Class: Fastlane::Actions::GetVoipPushCertificateAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



66
67
68
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 66

def self.authors
  ["Rafael Ferreira"]
end

.available_optionsObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 90

def self.available_options
  user = CredentialsManager::AppfileConfig.try_fetch_value(:apple_dev_portal_id)
  user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)

  [
    FastlaneCore::ConfigItem.new(key: :app_identifier,
                                 short_option: "-a",
                                 env_name: "VOIP_PUSH_CERTIFICATE_APP_IDENTIFIER",
                                 description: "The bundle identifier of your app",
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier),
                                 default_value_dynamic: true),
    FastlaneCore::ConfigItem.new(key: :username,
                                 short_option: "-u",
                                 env_name: "VOIP_PUSH_CERTIFICATE_USERNAME",
                                 description: "Your Apple ID username",
                                 default_value: user,
                                 default_value_dynamic: true),
    FastlaneCore::ConfigItem.new(key: :team_id,
                                 short_option: "-b",
                                 env_name: "VOIP_PUSH_CERTIFICATE_TEAM_ID",
                                 description: "The ID of your Developer Portal team if you're in multiple teams",
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_id),
                                 default_value_dynamic: true,
                                 optional: true,
                                 verify_block: proc do |value|
                                   ENV["FASTLANE_TEAM_ID"] = value.to_s
                                 end),
    FastlaneCore::ConfigItem.new(key: :team_name,
                                 short_option: "-l",
                                 env_name: "VOIP_PUSH_CERTIFICATE_TEAM_NAME",
                                 description: "The name of your Developer Portal team if you're in multiple teams",
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_name),
                                 default_value_dynamic: true,
                                 optional: true,
                                 verify_block: proc do |value|
                                   ENV["FASTLANE_TEAM_NAME"] = value.to_s
                                 end),
    FastlaneCore::ConfigItem.new(key: :active_days_limit,
                                 env_name: "VOIP_PUSH_CERTIFICATE_ACTIVE_DAYS_LIMIT",
                                 description: "If the current certificate is active for less than this number of days, generate a new one",
                                 default_value: 30,
                                 type: Integer,
                                 verify_block: proc do |value|
                                   UI.user_error!("Value of active_days_limit must be a positive integer") unless value.kind_of?(Integer) && value > 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :force,
                                 env_name: "VOIP_PUSH_CERTIFICATE_FORCE",
                                 description: "Create a new certificate, even if the current one is active for more than `active_days_limit` days",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :revoke_existing,
                                 env_name: "VOIP_PUSH_CERTIFICATE_REVOKE_EXISTING",
                                 description: "Revoke the matching existing certificate before creating a new one. This immediately breaks any push provider still using it",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :generate_p12,
                                 env_name: "VOIP_PUSH_CERTIFICATE_GENERATE_P12_FILE",
                                 description: "Generate a p12 file additionally to the PEM file",
                                 type: Boolean,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :p12_password,
                                 short_option: "-p",
                                 env_name: "VOIP_PUSH_CERTIFICATE_P12_PASSWORD",
                                 sensitive: true,
                                 description: "The password that is used for your p12 file",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :save_private_key,
                                 short_option: "-s",
                                 env_name: "VOIP_PUSH_CERTIFICATE_SAVE_PRIVATE_KEY",
                                 description: "Set to save the private RSA key as a separate .pkey file",
                                 type: Boolean,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :save_cer,
                                 env_name: "VOIP_PUSH_CERTIFICATE_SAVE_CER",
                                 description: "Additionally save the raw DER certificate as a .cer file",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :bag_attributes,
                                 env_name: "VOIP_PUSH_CERTIFICATE_BAG_ATTRIBUTES",
                                 description: "Write the .pem with OpenSSL bag attributes (friendlyName / localKeyID), mimicking the output of `openssl pkcs12 -nodes`. Some push providers require this format",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :pem_name,
                                 short_option: "-o",
                                 env_name: "VOIP_PUSH_CERTIFICATE_PEM_NAME",
                                 description: "The base file name of the generated files. Defaults to `voip_<app_identifier>`",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :output_path,
                                 short_option: "-e",
                                 env_name: "VOIP_PUSH_CERTIFICATE_OUTPUT_PATH",
                                 description: "The path to a directory in which all certificates and private keys should be stored",
                                 default_value: ".")
  ]
end

.categoryObject



86
87
88
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 86

def self.category
  :push
end

.descriptionObject



28
29
30
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 28

def self.description
  "Create and renew Apple VoIP Services push certificates"
end

.detailsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 32

def self.details
  [
    "Generates an Apple *VoIP Services* push certificate (the certificate type used by PushKit)",
    "and writes it to disk as `.pem`, `.p12` and, optionally, `.cer`.",
    "",
    "fastlane's built-in `get_push_certificate` covers development, production and website push",
    "certificates, but not VoIP ones. This plugin fills that gap using the same Spaceship APIs.",
    "",
    "Apple issues a single VoIP Services certificate that works for both the sandbox and the",
    "production APNs environments, so there is no `development` option here.",
    "",
    "By default an existing certificate is never revoked: if the app already has two active VoIP",
    "certificates the action fails with an explanation. Set `revoke_existing` to true only if you",
    "are sure no push provider still depends on the old certificate.",
    "",
    "Authentication goes through Spaceship's Apple Developer Portal API, which requires an Apple ID",
    "and password (`FASTLANE_USER` / `FASTLANE_PASSWORD`) plus 2FA. App Store Connect API keys are",
    "not supported for push certificates by Apple's portal API."
  ].join("\n")
end

.example_codeObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 70

def self.example_code
  [
    'get_voip_push_certificate',
    'get_voip_push_certificate(
      app_identifier: "com.example.app",
      output_path: "./certs"
    )',
    '# Renew even if the current certificate is still valid for a long time
    get_voip_push_certificate(
      app_identifier: "com.example.app",
      force: true,
      revoke_existing: true
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 188

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

.outputObject



57
58
59
60
61
62
63
64
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 57

def self.output
  [
    ['VOIP_PUSH_CERTIFICATE_PEM_PATH', 'The path to the generated .pem file'],
    ['VOIP_PUSH_CERTIFICATE_P12_PATH', 'The path to the generated .p12 file'],
    ['VOIP_PUSH_CERTIFICATE_PKEY_PATH', 'The path to the generated private key'],
    ['VOIP_PUSH_CERTIFICATE_CER_PATH', 'The path to the generated .cer file']
  ]
end

.return_valueObject



53
54
55
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 53

def self.return_value
  "The path to the generated .pem file, or nil when the existing certificate was still valid and was kept"
end

.run(params) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fastlane/plugin/voip_push_certificate/actions/get_voip_push_certificate_action.rb', line 16

def self.run(params)
  paths = Helper::VoipPushCertificateHelper.new(params).run
  return nil if paths.nil?

  Actions.lane_context[SharedValues::VOIP_PUSH_CERTIFICATE_PEM_PATH] = paths[:pem]
  Actions.lane_context[SharedValues::VOIP_PUSH_CERTIFICATE_P12_PATH] = paths[:p12]
  Actions.lane_context[SharedValues::VOIP_PUSH_CERTIFICATE_PKEY_PATH] = paths[:pkey]
  Actions.lane_context[SharedValues::VOIP_PUSH_CERTIFICATE_CER_PATH] = paths[:cer]

  paths[:pem]
end