Class: Fastlane::Actions::AppStoreConnectApiKeyAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/app_store_connect_api_key.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, authors, deprecated_notes, lane_context, method_missing, other_action, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



94
95
96
# File 'fastlane/lib/fastlane/actions/app_store_connect_api_key.rb', line 94

def self.author
  ["joshdholtz"]
end

.available_optionsObject



47
48
49
50
51
52
53
54
55
56
57
58
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
# File 'fastlane/lib/fastlane/actions/app_store_connect_api_key.rb', line 47

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :key_id,
                                 env_name: "APP_STORE_CONNECT_API_KEY_KEY_ID",
                                 description: "The key ID"),
    FastlaneCore::ConfigItem.new(key: :issuer_id,
                                 env_name: "APP_STORE_CONNECT_API_KEY_ISSUER_ID",
                                 description: "The issuer ID"),
    FastlaneCore::ConfigItem.new(key: :key_filepath,
                                 env_name: "APP_STORE_CONNECT_API_KEY_KEY_FILEPATH",
                                 description: "The path to the key p8 file",
                                 optional: true,
                                 conflicting_options: [:key_content],
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find key p8 file at path '#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :key_content,
                                 env_name: "APP_STORE_CONNECT_API_KEY_KEY",
                                 description: "The content of the key p8 file",
                                 sensitive: true,
                                 optional: true,
                                 conflicting_options: [:filepath]),
    FastlaneCore::ConfigItem.new(key: :is_key_content_base64,
                                 env_name: "APP_STORE_CONNECT_API_KEY_IS_KEY_CONTENT_BASE64",
                                 description: "Whether :key_content is Base64 encoded or not",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :duration,
                                 env_name: "APP_STORE_CONNECT_API_KEY_DURATION",
                                 description: "The token session duration",
                                 optional: true,
                                 default_value: Spaceship::ConnectAPI::Token::MAX_TOKEN_DURATION,
                                 type: Integer),
    FastlaneCore::ConfigItem.new(key: :in_house,
                                 env_name: "APP_STORE_CONNECT_API_KEY_IN_HOUSE",
                                 description: "Is App Store or Enterprise (in house) team? App Store Connect API cannot not determine this on its own (yet)",
                                 optional: true,
                                 type: Boolean)
  ]
end

.categoryObject



130
131
132
# File 'fastlane/lib/fastlane/actions/app_store_connect_api_key.rb', line 130

def self.category
  :app_store_connect
end

.descriptionObject



43
44
45
# File 'fastlane/lib/fastlane/actions/app_store_connect_api_key.rb', line 43

def self.description
  "Load the App Store Connect API token to use in other fastlane tools and actions"
end

.detailsObject



102
103
104
105
106
# File 'fastlane/lib/fastlane/actions/app_store_connect_api_key.rb', line 102

def self.details
  [
    "Load the App Store Connect API token to use in other fastlane tools and actions"
  ].join("\n")
end

.example_codeObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'fastlane/lib/fastlane/actions/app_store_connect_api_key.rb', line 108

def self.example_code
  [
    'app_store_connect_api_key(
      key_id: "D83848D23",
      issuer_id: "227b0bbf-ada8-458c-9d62-3d8022b7d07f",
      key_filepath: "D83848D23.p8"
    )',
    'app_store_connect_api_key(
      key_id: "D83848D23",
      issuer_id: "227b0bbf-ada8-458c-9d62-3d8022b7d07f",
      key_filepath: "D83848D23.p8",
      duration: 200,
      in_house: true
    )',
    'app_store_connect_api_key(
      key_id: "D83848D23",
      issuer_id: "227b0bbf-ada8-458c-9d62-3d8022b7d07f",
      key_content: "-----BEGIN EC PRIVATE KEY-----\nfewfawefawfe\n-----END EC PRIVATE KEY-----"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



98
99
100
# File 'fastlane/lib/fastlane/actions/app_store_connect_api_key.rb', line 98

def self.is_supported?(platform)
  true
end

.outputObject



88
89
90
91
92
# File 'fastlane/lib/fastlane/actions/app_store_connect_api_key.rb', line 88

def self.output
  [
    ['APP_STORE_CONNECT_API_KEY', 'The App Store Connect API key information used for authorization requests. This hash can be passed directly into the :api_key options on other tools or into Spaceship::ConnectAPI::Token.create method']
  ]
end

.run(options) ⇒ 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
# File 'fastlane/lib/fastlane/actions/app_store_connect_api_key.rb', line 10

def self.run(options)
  key_id = options[:key_id]
  issuer_id = options[:issuer_id]
  key_content = options[:key_content]
  is_key_content_base64 = options[:is_key_content_base64]
  key_filepath = options[:key_filepath]
  duration = options[:duration]
  in_house = options[:in_house]

  if key_content.nil? && key_filepath.nil?
    UI.user_error!(":key_content or :key_filepath is required")
  end

  # New lines don't get read properly when coming from an ENV
  # Replacing them literal version with a new line
  key_content = key_content.gsub('\n', "\n") if key_content

  # This hash matches the named arguments on
  # the Spaceship::ConnectAPI::Token.create method
  key = {
    key_id: key_id,
    issuer_id: issuer_id,
    key: key_content || File.binread(key_filepath),
    is_key_content_base64: is_key_content_base64,
    duration: duration,
    in_house: in_house
  }

  Actions.lane_context.set_sensitive(SharedValues::APP_STORE_CONNECT_API_KEY, key)

  return key
end