Class: Fastlane::Actions::CreateKeychainAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/create_keychain.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, details, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



105
106
107
# File 'fastlane/lib/fastlane/actions/create_keychain.rb', line 105

def self.authors
  ["gin0606"]
end

.available_optionsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'fastlane/lib/fastlane/actions/create_keychain.rb', line 59

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :name,
                                 env_name: "KEYCHAIN_NAME",
                                 description: "Keychain name",
                                 conflicting_options: [:path],
                                 is_string: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :path,
                                 env_name: "KEYCHAIN_PATH",
                                 description: "Path to keychain",
                                 is_string: true,
                                 conflicting_options: [:name],
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :password,
                                 env_name: "KEYCHAIN_PASSWORD",
                                 description: "Password for the keychain",
                                 sensitive: true,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :default_keychain,
                                 description: 'Should the newly created Keychain be the new system default keychain',
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :unlock,
                                 description: 'Unlock keychain after create',
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :timeout,
                                 description: 'timeout interval in seconds. Set `false` if you want to specify "no time-out"',
                                 is_string: false,
                                 default_value: 300),
    FastlaneCore::ConfigItem.new(key: :lock_when_sleeps,
                                 description: 'Lock keychain when the system sleeps',
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :lock_after_timeout,
                                 description: 'Lock keychain after timeout interval',
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :add_to_search_list,
                                 description: 'Add keychain to search list',
                                 is_string: false,
                                 default_value: true)
  ]
end

.categoryObject



125
126
127
# File 'fastlane/lib/fastlane/actions/create_keychain.rb', line 125

def self.category
  :misc
end

.descriptionObject



55
56
57
# File 'fastlane/lib/fastlane/actions/create_keychain.rb', line 55

def self.description
  "Create a new Keychain"
end

.example_codeObject



113
114
115
116
117
118
119
120
121
122
123
# File 'fastlane/lib/fastlane/actions/create_keychain.rb', line 113

def self.example_code
  [
    'create_keychain(
      name: "KeychainName",
      default_keychain: true,
      unlock: true,
      timeout: 3600,
      lock_when_sleeps: true
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



109
110
111
# File 'fastlane/lib/fastlane/actions/create_keychain.rb', line 109

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'fastlane/lib/fastlane/actions/create_keychain.rb', line 10

def self.run(params)
  escaped_password = params[:password].shellescape

  if params[:name]
    escaped_name = params[:name].shellescape
    keychain_path = "~/Library/Keychains/#{escaped_name}"
  else
    keychain_path = params[:path].shellescape
  end

  if keychain_path.nil?
    UI.user_error!("You either have to set :name or :path")
  end

  commands = []
  commands << Fastlane::Actions.sh("security create-keychain -p #{escaped_password} #{keychain_path}", log: false)

  if params[:default_keychain]
    # if there is no default keychain - setting the original will fail - silent this error
    begin
      Actions.lane_context[Actions::SharedValues::ORIGINAL_DEFAULT_KEYCHAIN] = Fastlane::Actions.sh("security default-keychain", log: false).strip
    rescue
    end
    commands << Fastlane::Actions.sh("security default-keychain -s #{keychain_path}", log: false)
  end

  commands << Fastlane::Actions.sh("security unlock-keychain -p #{escaped_password} #{keychain_path}", log: false) if params[:unlock]

  command = "security set-keychain-settings"
  command << " -t #{params[:timeout]}" if params[:timeout]
  command << " -l" if params[:lock_when_sleeps]
  command << " -u" if params[:lock_after_timeout]
  command << " #{keychain_path}"

  commands << Fastlane::Actions.sh(command, log: false)

  if params[:add_to_search_list]
    keychains = Action.sh("security list-keychains -d user").shellsplit
    keychains << File.expand_path(keychain_path)
    commands << Fastlane::Actions.sh("security list-keychains -s #{keychains.shelljoin}", log: false)
  end

  commands
end