Class: Fastlane::Actions::DecryptSecretsAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



40
41
42
# File 'lib/fastlane/plugin/secrets/actions/decrypt_secrets_action.rb', line 40

def self.authors
  ["Cyril Cermak, Jörg Nestele"]
end

.available_optionsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fastlane/plugin/secrets/actions/decrypt_secrets_action.rb', line 53

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :file_path,
                                 description: "Path to the encrypted secrets file",
                                 is_string: true),
    FastlaneCore::ConfigItem.new(key: :target_path,
                                 description: "Output path for the auto generated source file",
                                 is_string: true),
    FastlaneCore::ConfigItem.new(key: :password,
                                 description: "Password to open the GPG secrets file",
                                 is_string: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :private_key_path,
                                 description: "Path to a private key for GPG",
                                 is_string: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :empty,
                                 description: "Path to a private key for GPG",
                                 type: Boolean,
                                 optional: true,
                                 default_value: false)
  ]
end

.clean(file_path) ⇒ Object



49
50
51
# File 'lib/fastlane/plugin/secrets/actions/decrypt_secrets_action.rb', line 49

def self.clean file_path
  File.delete(file_path) if File.exist?(file_path)
end

.descriptionObject



36
37
38
# File 'lib/fastlane/plugin/secrets/actions/decrypt_secrets_action.rb', line 36

def self.description
  "Securely store secrets in source code"
end

.detailsObject



44
45
46
47
# File 'lib/fastlane/plugin/secrets/actions/decrypt_secrets_action.rb', line 44

def self.details
  # Optional:
  ""
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
# File 'lib/fastlane/plugin/secrets/actions/decrypt_secrets_action.rb', line 77

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  [:ios, :mac].include?(platform)
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
29
30
31
32
33
34
# File 'lib/fastlane/plugin/secrets/actions/decrypt_secrets_action.rb', line 7

def self.run(params)
  secrets_path = params[:file_path]
  password = params[:password]
  empty = params[:empty]
  private_key_path = params[:private_key_path]
  target_path = "#{Dir.pwd}/#{params[:target_path]}/secrets.swift"
  tmp_decrypted_secrets_file = "/tmp/secrets"
  secrets_handler = MobileSecrets::SecretsHandler.new

  return secrets_handler.inject_secrets [[]], target_path if empty

  clean tmp_decrypted_secrets_file
  if private_key_path && password
    sh("gpg", "-v", "--pinentry-mode", "loopback", "--passphrase", password, "--import", private_key_path)
    sh("gpg", "-a", "--pinentry-mode", "loopback", "--passphrase", password, "--output", tmp_decrypted_secrets_file, "--decrypt", secrets_path)
  elsif password then
    sh("gpg", "-a", "--pinentry-mode", "loopback", "--passphrase", password, "--output", tmp_decrypted_secrets_file, "--decrypt", secrets_path)
  else
    sh("gpg", "--output", tmp_decrypted_secrets_file, "--decrypt", secrets_path)
  end

  yml_config = File.read tmp_decrypted_secrets_file
  file_names_bytes, secrets_bytes = secrets_handler.process_yaml_config yml_config
  renderer = MobileSecrets::SourceRenderer.new "swift"
  renderer.render_template secrets_bytes, file_names_bytes, target_path

  clean tmp_decrypted_secrets_file
end