Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for AWS SSO + custom attributes to configure SNS platform app #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 67 additions & 27 deletions lib/fastlane/plugin/aws_sns/actions/aws_sns_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,30 @@ def self.run(params)
access_key = params[:access_key]
secret_access_key = params[:secret_access_key]
region = params[:region]
client = params[:aws_sns_client]

platform = params[:platform]
platform_name = params[:platform_name]
update_attributes = params[:update_if_exists]
attributes_override = params[:attributes_override]
platform_apns_private_key_path = params[:platform_apns_private_key_path]
platform_apns_private_key_password = params[:platform_apns_private_key_password]

platform_fcm_server_key = params[:platform_fcm_server_key]
platform_fcm_server_key ||= params[:platform_gcm_api_key]

UI.user_error!("No S3 access key given, pass using `access_key: 'key'`") unless access_key.to_s.length > 0
UI.user_error!("No S3 secret access key given, pass using `secret_access_key: 'secret key'`") unless secret_access_key.to_s.length > 0
UI.user_error!("No S3 region given, pass using `region: 'region'`") unless region.to_s.length > 0
UI.user_error!("No S3 region given, pass using `platform: 'platform'`") unless platform.to_s.length > 0
UI.user_error!("No S3 region given, pass using `platform_name: 'platform_name'`") unless platform_name.to_s.length > 0
if client.nil?
UI.user_error!("No AWS access key given, pass using `access_key: 'key'`") unless access_key.to_s.length > 0
UI.user_error!("No AWS secret access key given, pass using `secret_access_key: 'secret key'`") unless secret_access_key.to_s.length > 0
UI.user_error!("No AWS region given, pass using `region: 'region'`") unless region.to_s.length > 0
end
UI.user_error!("No notification platform given, pass using `platform: 'platform'`") unless platform.to_s.length > 0
UI.user_error!("No SNS platform application name given, pass using `platform_name: 'platform_name'`") unless platform_name.to_s.length > 0

#
# Initialize AWS client
#
client = Aws::SNS::Client.new(
client ||= Aws::SNS::Client.new(
access_key_id: access_key,
secret_access_key: secret_access_key,
region: region
Expand All @@ -58,6 +62,13 @@ def self.run(params)
}
end

# Set additional AWS platform attributes
if attributes.nil?
attributes = attributes_override
else
attributes = attributes.merge(attributes_override)
end

#
#
#
Expand Down Expand Up @@ -104,9 +115,9 @@ def self.run(params)
else
# else, updating
client.set_platform_application_attributes({
platform_application_arn: arn,
attributes: attributes,
})
platform_application_arn: arn,
attributes: attributes,
})
UI.important("Updated #{arn}")
end

Expand Down Expand Up @@ -138,27 +149,47 @@ def self.details
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :access_key,
env_name: "AWS_SNS_ACCESS_KEY",
description: "AWS Access Key ID",
optional: false,
default_value: ENV['AWS_ACCESS_KEY_ID']),
env_name: "AWS_SNS_ACCESS_KEY",
description: "AWS Access Key ID",
optional: true,
sensitive: true,
conflicting_options: [:aws_sns_client],
conflict_block: proc do |value|
UI.user_error!("You can't use option '#{value.key}' along with 'access_key'")
end),
FastlaneCore::ConfigItem.new(key: :secret_access_key,
env_name: "AWS_SNS_SECRET_ACCESS_KEY",
description: "AWS Secret Access Key",
optional: false,
default_value: ENV['AWS_SECRET_ACCESS_KEY']),
env_name: "AWS_SNS_SECRET_ACCESS_KEY",
description: "AWS Secret Access Key",
optional: true,
sensitive: true,
conflicting_options: [:aws_sns_client],
conflict_block: proc do |value|
UI.user_error!("You can't use option '#{value.key}' along with 'secret_access_key'")
end),
FastlaneCore::ConfigItem.new(key: :region,
env_name: "AWS_SNS_REGION",
description: "AWS Region",
optional: false,
default_value: ENV['AWS_REGION']),
optional: true,
sensitive: true,
conflicting_options: [:aws_sns_client],
conflict_block: proc do |value|
UI.user_error!("You can't use option '#{value.key}' along with 'region'")
end),
FastlaneCore::ConfigItem.new(key: :aws_sns_client,
description: "AWS SNS Client, useful in case of special credentials or custom logging",
type: Aws::SNS::Client,
optional: true,
conflicting_options: [:access_key, :secret_access_key, :region],
conflict_block: proc do |value|
UI.user_error!("You can't use option '#{value.key}' along with 'aws_sns_client'")
end),
FastlaneCore::ConfigItem.new(key: :platform,
env_name: "AWS_SNS_PLATFORM",
description: "AWS Platform",
optional: false,
verify_block: proc do |value|
UI.user_error!("Invalid platform #{value}") unless ['APNS', 'APNS_SANDBOX', 'GCM', 'FCM'].include?(value)
end),
env_name: "AWS_SNS_PLATFORM",
description: "AWS Platform",
optional: false,
verify_block: proc do |value|
UI.user_error!("Invalid platform #{value}") unless ['APNS', 'APNS_SANDBOX', 'GCM', 'FCM'].include?(value)
end),
FastlaneCore::ConfigItem.new(key: :platform_name,
env_name: "AWS_SNS_PLATFORM_NAME",
description: "AWS Platform Name",
Expand All @@ -171,21 +202,30 @@ def self.available_options
env_name: "AWS_SNS_PLATFORM_APNS_PRIVATE_KEY_PASSWORD",
description: "AWS Platform APNS Private Key Password",
optional: true,
sensitive: true,
default_value: ""),
FastlaneCore::ConfigItem.new(key: :platform_fcm_server_key,
env_name: "AWS_SNS_PLATFORM_FCM_SERVER_KEY",
description: "AWS Platform FCM SERVER KEY",
optional: true),
optional: true,
sensitive: true),
FastlaneCore::ConfigItem.new(key: :platform_gcm_api_key,
env_name: "AWS_SNS_PLATFORM_GCM_API_KEY",
description: "AWS Platform GCM API KEY",
deprecated: "Use :platform_fcm_server_key instead",
optional: true),
optional: true,
sensitive: true),
FastlaneCore::ConfigItem.new(key: :update_if_exists,
env_name: "AWS_SNS_UDPATE_IF_EXISTS",
description: "updating certificate/key if platform_name already exists",
default_value: false,
is_string: false,
optional: true),
FastlaneCore::ConfigItem.new(key: :attributes_override,
env_name: "AWS_SNS_PLATFORM_ATTRIBUTES_OVERRIDE",
description: "additional AWS platform attributes such as EventEndpointCreated or SuccessFeedbackRoleArn",
default_value: {},
is_string: false,
optional: true)
]
end
Expand Down