Class: Fastlane::Actions::DecryptAndroidKeystoreAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



121
122
123
124
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 121

def self.authors
  # So no one will ever forget your contribution to fastlane :) You are awesome btw!
  ["cball", "isaiahgrey93", "cmejet"]
end

.available_optionsObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 83

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :encrypt_in_repo,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_ENCRYPT_IN_REPO",
                                 description: "If the new keystore should be encrypted and saved",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :password,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_PASSWORD",
                                 description: "Password for the Keystore",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :alias,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_ALIAS",
                                 description: "ALIAS for the Keystore",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :destination,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_DESTINATION",
                                 description: "Where to put decrypted keystore",
                                 default_value: "../android/app/android.keystore"),
    FastlaneCore::ConfigItem.new(key: :fullname,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_FULLNAME",
                                 description: "Fullname of keystore owner",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :city,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_CITY",
                                 description: "City of keystore owner",
                                 type: String),
  ]
end

.create_keystore_with_params(params) ⇒ Object

Creates a new android keystore based on the provided params. Wraps Cryptex.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 43

def self.create_keystore_with_params(params)
  begin
    other_action.cryptex_generate_keystore(
      destination: params[:destination],
      password: params[:password],
      fullname: params[:fullname],
      city: params[:city],
      alias: params[:alias]
    )
  rescue => ex
    UI.abort_with_message!("Could not create keystore. Do you already have one with this alias?")
  end

  params[:destination]
end

.descriptionObject



74
75
76
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 74

def self.description
  "Decrypts app env vars and sets the values in the root .env file"
end

.detailsObject



78
79
80
81
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 78

def self.details
  # Optional:
  # this is your chance to provide a more detailed description of this action
end

.encrypt_keystore(keystore_path) ⇒ Object

Saves a keystore to the repo. Note this will overwrite it!



60
61
62
63
64
65
66
67
68
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 60

def self.encrypt_keystore(keystore_path)
  key = Helper::ReactNativeReleaseHelper::ANDROID_KEYSTORE_CRYPTEX_KEY

  other_action.cryptex(
    type: "import",
    in: keystore_path,
    key: key
  )
end

.export_and_decrypt_keystore(file, key) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 30

def self.export_and_decrypt_keystore(file,key)
  other_action.cryptex(
    type: "export",
    out: file,
    key: key,
    verbose: true
  )
   # There is currently a bug where the keystore needs to be in multiple paths
   # Optimized for the CI process to be running from the lane in android directory
   sh("cp ./app/android.keystore ./")
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 126

def self.is_supported?(platform)
  [:ios, :android].include?(platform)
end

.return_valueObject



113
114
115
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 113

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_android_keystore.rb', line 7

def self.run(params)
  key = Helper::ReactNativeReleaseHelper::ANDROID_KEYSTORE_CRYPTEX_KEY
  file = Helper::ReactNativeReleaseHelper::ANDROID_KEYSTORE_PATH

  begin
    env_file_exists = File.exists?(file)

    if (env_file_exists && UI.confirm("This will overwrite your existing .env file. Proceed?"))
      self.export_and_decrypt_keystore(file,key)
      
    elsif(env_file_exists)
      UI.abort_with_message!("Stepping away...")
    else
      self.export_and_decrypt_keystore(file,key)
    end
  # If we don't have a keystore, cryptex will throw an exception.
  rescue => ex
    UI.abort_with_message!('Error decrypting keystore. Does it exist in the repo?')
  end

  UI.success("Decrypted #{key} to keystore.")
end