Skip to content

Commit aa34e84

Browse files
committed
Support for AWS SSO + custom attributes to configure SNS platform app
This commit adds the possibility to pass an AWS SNS client, which can be initialized with AWS SSO credentials. It also makes the code unit testable by providing a client with stub_responses (I'll make a separate PR for that). We also needed to configure the SNS platform app with various attributes like EventEndpointCreated, so I added a parameter for that. The full list of SNS platform application attributes can be found here: https://docs.aws.amazon.com/sns/latest/api/API_SetPlatformApplicationAttributes.html .
1 parent 06df801 commit aa34e84

File tree

1 file changed

+67
-27
lines changed

1 file changed

+67
-27
lines changed

lib/fastlane/plugin/aws_sns/actions/aws_sns_action.rb

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,30 @@ def self.run(params)
1212
access_key = params[:access_key]
1313
secret_access_key = params[:secret_access_key]
1414
region = params[:region]
15+
client = params[:aws_sns_client]
1516

1617
platform = params[:platform]
1718
platform_name = params[:platform_name]
1819
update_attributes = params[:update_if_exists]
20+
attributes_override = params[:attributes_override]
1921
platform_apns_private_key_path = params[:platform_apns_private_key_path]
2022
platform_apns_private_key_password = params[:platform_apns_private_key_password]
2123

2224
platform_fcm_server_key = params[:platform_fcm_server_key]
2325
platform_fcm_server_key ||= params[:platform_gcm_api_key]
2426

25-
UI.user_error!("No S3 access key given, pass using `access_key: 'key'`") unless access_key.to_s.length > 0
26-
UI.user_error!("No S3 secret access key given, pass using `secret_access_key: 'secret key'`") unless secret_access_key.to_s.length > 0
27-
UI.user_error!("No S3 region given, pass using `region: 'region'`") unless region.to_s.length > 0
28-
UI.user_error!("No S3 region given, pass using `platform: 'platform'`") unless platform.to_s.length > 0
29-
UI.user_error!("No S3 region given, pass using `platform_name: 'platform_name'`") unless platform_name.to_s.length > 0
27+
if client.nil?
28+
UI.user_error!("No AWS access key given, pass using `access_key: 'key'`") unless access_key.to_s.length > 0
29+
UI.user_error!("No AWS secret access key given, pass using `secret_access_key: 'secret key'`") unless secret_access_key.to_s.length > 0
30+
UI.user_error!("No AWS region given, pass using `region: 'region'`") unless region.to_s.length > 0
31+
end
32+
UI.user_error!("No notification platform given, pass using `platform: 'platform'`") unless platform.to_s.length > 0
33+
UI.user_error!("No SNS platform application name given, pass using `platform_name: 'platform_name'`") unless platform_name.to_s.length > 0
3034

3135
#
3236
# Initialize AWS client
3337
#
34-
client = Aws::SNS::Client.new(
38+
client ||= Aws::SNS::Client.new(
3539
access_key_id: access_key,
3640
secret_access_key: secret_access_key,
3741
region: region
@@ -58,6 +62,13 @@ def self.run(params)
5862
}
5963
end
6064

65+
# Set additional AWS platform attributes
66+
if attributes.nil?
67+
attributes = attributes_override
68+
else
69+
attributes = attributes.merge(attributes_override)
70+
end
71+
6172
#
6273
#
6374
#
@@ -104,9 +115,9 @@ def self.run(params)
104115
else
105116
# else, updating
106117
client.set_platform_application_attributes({
107-
platform_application_arn: arn,
108-
attributes: attributes,
109-
})
118+
platform_application_arn: arn,
119+
attributes: attributes,
120+
})
110121
UI.important("Updated #{arn}")
111122
end
112123

@@ -138,27 +149,47 @@ def self.details
138149
def self.available_options
139150
[
140151
FastlaneCore::ConfigItem.new(key: :access_key,
141-
env_name: "AWS_SNS_ACCESS_KEY",
142-
description: "AWS Access Key ID",
143-
optional: false,
144-
default_value: ENV['AWS_ACCESS_KEY_ID']),
152+
env_name: "AWS_SNS_ACCESS_KEY",
153+
description: "AWS Access Key ID",
154+
optional: true,
155+
sensitive: true,
156+
conflicting_options: [:aws_sns_client],
157+
conflict_block: proc do |value|
158+
UI.user_error!("You can't use option '#{value.key}' along with 'access_key'")
159+
end),
145160
FastlaneCore::ConfigItem.new(key: :secret_access_key,
146-
env_name: "AWS_SNS_SECRET_ACCESS_KEY",
147-
description: "AWS Secret Access Key",
148-
optional: false,
149-
default_value: ENV['AWS_SECRET_ACCESS_KEY']),
161+
env_name: "AWS_SNS_SECRET_ACCESS_KEY",
162+
description: "AWS Secret Access Key",
163+
optional: true,
164+
sensitive: true,
165+
conflicting_options: [:aws_sns_client],
166+
conflict_block: proc do |value|
167+
UI.user_error!("You can't use option '#{value.key}' along with 'secret_access_key'")
168+
end),
150169
FastlaneCore::ConfigItem.new(key: :region,
151170
env_name: "AWS_SNS_REGION",
152171
description: "AWS Region",
153-
optional: false,
154-
default_value: ENV['AWS_REGION']),
172+
optional: true,
173+
sensitive: true,
174+
conflicting_options: [:aws_sns_client],
175+
conflict_block: proc do |value|
176+
UI.user_error!("You can't use option '#{value.key}' along with 'region'")
177+
end),
178+
FastlaneCore::ConfigItem.new(key: :aws_sns_client,
179+
description: "AWS SNS Client, useful in case of special credentials or custom logging",
180+
type: Aws::SNS::Client,
181+
optional: true,
182+
conflicting_options: [:access_key, :secret_access_key, :region],
183+
conflict_block: proc do |value|
184+
UI.user_error!("You can't use option '#{value.key}' along with 'aws_sns_client'")
185+
end),
155186
FastlaneCore::ConfigItem.new(key: :platform,
156-
env_name: "AWS_SNS_PLATFORM",
157-
description: "AWS Platform",
158-
optional: false,
159-
verify_block: proc do |value|
160-
UI.user_error!("Invalid platform #{value}") unless ['APNS', 'APNS_SANDBOX', 'GCM', 'FCM'].include?(value)
161-
end),
187+
env_name: "AWS_SNS_PLATFORM",
188+
description: "AWS Platform",
189+
optional: false,
190+
verify_block: proc do |value|
191+
UI.user_error!("Invalid platform #{value}") unless ['APNS', 'APNS_SANDBOX', 'GCM', 'FCM'].include?(value)
192+
end),
162193
FastlaneCore::ConfigItem.new(key: :platform_name,
163194
env_name: "AWS_SNS_PLATFORM_NAME",
164195
description: "AWS Platform Name",
@@ -171,21 +202,30 @@ def self.available_options
171202
env_name: "AWS_SNS_PLATFORM_APNS_PRIVATE_KEY_PASSWORD",
172203
description: "AWS Platform APNS Private Key Password",
173204
optional: true,
205+
sensitive: true,
174206
default_value: ""),
175207
FastlaneCore::ConfigItem.new(key: :platform_fcm_server_key,
176208
env_name: "AWS_SNS_PLATFORM_FCM_SERVER_KEY",
177209
description: "AWS Platform FCM SERVER KEY",
178-
optional: true),
210+
optional: true,
211+
sensitive: true),
179212
FastlaneCore::ConfigItem.new(key: :platform_gcm_api_key,
180213
env_name: "AWS_SNS_PLATFORM_GCM_API_KEY",
181214
description: "AWS Platform GCM API KEY",
182215
deprecated: "Use :platform_fcm_server_key instead",
183-
optional: true),
216+
optional: true,
217+
sensitive: true),
184218
FastlaneCore::ConfigItem.new(key: :update_if_exists,
185219
env_name: "AWS_SNS_UDPATE_IF_EXISTS",
186220
description: "updating certificate/key if platform_name already exists",
187221
default_value: false,
188222
is_string: false,
223+
optional: true),
224+
FastlaneCore::ConfigItem.new(key: :attributes_override,
225+
env_name: "AWS_SNS_PLATFORM_ATTRIBUTES_OVERRIDE",
226+
description: "additional AWS platform attributes such as EventEndpointCreated or SuccessFeedbackRoleArn",
227+
default_value: {},
228+
is_string: false,
189229
optional: true)
190230
]
191231
end

0 commit comments

Comments
 (0)