From 302cf51c68edec1417a63a2491eb3d8ddf15ae8d Mon Sep 17 00:00:00 2001 From: David Spaeth Date: Fri, 21 Sep 2018 09:37:33 +0200 Subject: [PATCH 1/3] Add the ability to update sns application if it already exist --- README.md | 4 ++ fastlane/Fastfile | 4 +- .../plugin/aws_sns/actions/aws_sns_action.rb | 58 ++++++++++++++++--- 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3a4d9ce..6b7d001 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ aws_sns( # Optional private key password # platform_apns_private_key_password: 'joshissupercool' + # Optional: updating certificate if platform_name already exists + # udpate_if_exist: true ) ``` @@ -40,6 +42,8 @@ aws_sns( platform: 'GCM', platform_name: 'your_awesome_android_app', platform_gcm_api_key: 'your_gcm_api_key' + # Optional: updating key if platform_name already exists + # udpate_if_exist: true ) ``` diff --git a/fastlane/Fastfile b/fastlane/Fastfile index b81afbc..5e27d3a 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -3,7 +3,9 @@ platform :ios do arn = aws_sns( platform: 'APNS', platform_name: 'test_app_ios_2', - platform_apns_private_key_path: 'assets/test_push_cert.p12' + platform_apns_private_key_path: 'assets/test_push_cert.p12', + + update_if_exists: UI.confirm?("Update if exists?") ) puts "test_app_ios ARN: #{arn}" end diff --git a/lib/fastlane/plugin/aws_sns/actions/aws_sns_action.rb b/lib/fastlane/plugin/aws_sns/actions/aws_sns_action.rb index 531f825..0caf000 100644 --- a/lib/fastlane/plugin/aws_sns/actions/aws_sns_action.rb +++ b/lib/fastlane/plugin/aws_sns/actions/aws_sns_action.rb @@ -15,7 +15,7 @@ def self.run(params) platform = params[:platform] platform_name = params[:platform_name] - + update_attributes = params[:update_if_exist] platform_apns_private_key_path = params[:platform_apns_private_key_path] platform_apns_private_key_password = params[:platform_apns_private_key_password] @@ -63,12 +63,50 @@ def self.run(params) # UI.crash!("Unable to create any attributes to create platform application") unless attributes begin - resp = client.create_platform_application({ - name: platform_name, - platform: platform, - attributes: attributes, - }) - arn = resp.platform_application_arn + + arn = nil + + # + # Try to find the arn for platform_name + # + if update_attributes + + # Loop as long as list platform applications returns next_page or return the desired name + next_token = nil + loop do + + resp = client.list_platform_applications({ + next_token: next_token, + }) + + next_token = resp.next_token + # TODO: Must find a best search method ! + platform_application = resp.platform_applications.find { |platform_application| platform_application.platform_application_arn.end_with? platform_name } + + unless platform_application.nil? + arn = platform_application.platform_application_arn + break + end + break if next_token.nil? + end + + end + + # Not arn? OK, we create it ! + if arn.nil? + resp = client.create_platform_application({ + name: platform_name, + platform: platform, + attributes: attributes, + }) + arn = resp.platform_application_arn + else + # else, updating + client.set_platform_application_attributes({ + platform_application_arn: arn, + attributes: attributes, + }) + end Actions.lane_context[SharedValues::AWS_SNS_PLATFORM_APPLICATION_ARN] = arn ENV[SharedValues::AWS_SNS_PLATFORM_APPLICATION_ARN.to_s] = arn @@ -140,6 +178,12 @@ def self.available_options env_name: "AWS_SNS_PLATFORM_GCM_API_KEY", description: "AWS Platform GCM API KEY", deprecated: "Use :platform_fcm_server_key instead", + optional: true), + FastlaneCore::ConfigItem.new(key: :update_if_exist, + env_name: "AWS_SNS_UDPATE_IF_EXIST", + description: "updating certificate/key if platform_name already exists", + default_value: false, + is_string: false, optional: true) ] end From a2798d8a626a41c4e95929733245da4164dc8e65 Mon Sep 17 00:00:00 2001 From: Josh Holtz Date: Thu, 25 Mar 2021 07:24:06 -0500 Subject: [PATCH 2/3] Rebase and minor updates --- assets/test_push_cert_2.p12 | Bin 0 -> 3238 bytes fastlane/Fastfile | 4 ++-- .../plugin/aws_sns/actions/aws_sns_action.rb | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 assets/test_push_cert_2.p12 diff --git a/assets/test_push_cert_2.p12 b/assets/test_push_cert_2.p12 new file mode 100644 index 0000000000000000000000000000000000000000..84b8dd3cb14274f34fa808b0ac4b00eb0f6db43f GIT binary patch literal 3238 zcmY+FcQhLe+r}e_7)^}UC>k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*!NDErO>J`uY@U?JYWKU+c^0}e;boZ@k#4Ob&mXM$OlP*US=QTYRo zUM!Y?qK%WF=?{OnRklXJ{3vaYXFJ&+n=|aF^Uz>ZXLa!4SA%pwDQg{{Qz45ho#=zH z=X^np!c=}ycUT>$$zNKyn*9@a*ej@T5;0v2Q9f0i7)(3&f%e~$&13`LdBEbllr+t( zoxC8XM4R{a;$$U)sdD@Sl`4Mfa`Y0jQL^a?EOW0C=T{q? z;PE>##r|M&!X4Np+L1iH(U>_sp;_LUCb9FqGvq=CcdF66iy<&AQoj(Rf5&4T}!_{Pij35~SLgSc8Mzs_@8L zfm^v2qaq^Yv&)nA6I%fnNOF0@z*+6l9TMc&0=1I#gXQ!S8{ip?wrT$O9JssXrtCE)%lyjocSIj_|H&XABdy;|wub{%R+d!d%5v9N zKkw&Hy6BKtrbVtsE&qz^H0UMkR^&XMyeG2)qWl_ zr;d6htyX=p|S{Kwf$PnB&k- Date: Thu, 25 Mar 2021 07:28:08 -0500 Subject: [PATCH 3/3] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6b7d001..f3a91c1 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ aws_sns( # Optional private key password # platform_apns_private_key_password: 'joshissupercool' # Optional: updating certificate if platform_name already exists - # udpate_if_exist: true + # update_if_exist: true ) ``` @@ -43,7 +43,7 @@ aws_sns( platform_name: 'your_awesome_android_app', platform_gcm_api_key: 'your_gcm_api_key' # Optional: updating key if platform_name already exists - # udpate_if_exist: true + # update_if_exist: true ) ```