From 4f0ac3aea36e4a0711a9ee60d19bf6d3c426e63e Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Tue, 16 Jan 2018 19:45:23 -0200 Subject: [PATCH 01/11] Add android certifica, apple store id and prefix --- .../firebase_add_android_certificate.rb | 110 ++++++++++++++++++ .../actions/firebase_add_apple_store_id.rb | 104 +++++++++++++++++ .../firebase/actions/firebase_add_team.rb | 105 +++++++++++++++++ lib/fastlane/plugin/firebase/lib/api.rb | 32 +++++ 4 files changed, 351 insertions(+) create mode 100644 lib/fastlane/plugin/firebase/actions/firebase_add_android_certificate.rb create mode 100644 lib/fastlane/plugin/firebase/actions/firebase_add_apple_store_id.rb create mode 100644 lib/fastlane/plugin/firebase/actions/firebase_add_team.rb diff --git a/lib/fastlane/plugin/firebase/actions/firebase_add_android_certificate.rb b/lib/fastlane/plugin/firebase/actions/firebase_add_android_certificate.rb new file mode 100644 index 0000000..3f316dc --- /dev/null +++ b/lib/fastlane/plugin/firebase/actions/firebase_add_android_certificate.rb @@ -0,0 +1,110 @@ +module Fastlane + module Actions + class FirebaseAddAndroidCertificateAction < Action + + def self.run(params) + manager = Firebase::Manager.new + #Login + api = manager.login(params[:username]) + + #Select project + project = manager.select_project(params[:project_number]) + + # Client input + type = params[:type].to_sym + + bundle_id = params[:bundle_id] + name = params[:name] + appstore_id = params[:appstore_id] + sha256 = params[:sha256] + + begin + client = api.add_android_certificate(project["projectNumber"], bundle_id, sha256) + rescue Firebase::Api::BadRequestError => e + if e.message != 'Requested entity already exists' then + raise + end + end + + UI.success "Successfuly added android certificate of app #{bundle_id}" + end + + def self.description + "An unofficial tool to access Firebase" + end + + def self.authors + ["Tomas Kohout"] + end + + def self.return_value + # If your method provides a return value, you can describe here what it does + end + + def self.details + # Optional: + "Firebase helps you list your projects, create applications, download configuration files and more..." + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :username, + env_name: "FIREBASE_USERNAME", + description: "Username for your google account", + optional: false), + FastlaneCore::ConfigItem.new(key: :project_number, + env_name: "FIREBASE_PROJECT_NUMBER", + description: "Project number", + optional: true), + FastlaneCore::ConfigItem.new(key: :download_config, + env_name: "FIREBASE_DOWNLOAD_CONFIG", + description: "Should download config for created client", + optional: false, + is_string: false, + default_value: true), + FastlaneCore::ConfigItem.new(key: :type, + env_name: "FIREBASE_TYPE", + description: "Type of client (ios, android)", + verify_block: proc do |value| + types = [:ios, :android] + UI.user_error!("Type must be in #{types}") unless types.include?(value.to_sym) + end + ), + FastlaneCore::ConfigItem.new(key: :bundle_id, + env_name: "FIREBASE_BUNDLE_ID", + description: "Bundle ID (package name)", + optional: false), + FastlaneCore::ConfigItem.new(key: :name, + env_name: "FIREBASE_BUNDLE_ID", + description: "Display name", + optional: true), + FastlaneCore::ConfigItem.new(key: :appstore_id, + env_name: "FIREBASE_APPSTORE_ID", + description: "AppStore ID", + optional: true), + FastlaneCore::ConfigItem.new(key: :output_path, + env_name: "FIREBASE_OUTPUT_PATH", + description: "Path for the downloaded config", + optional: false, + default_value: "./"), + FastlaneCore::ConfigItem.new(key: :output_name, + env_name: "FIREBASE_OUTPUT_NAME", + description: "Name of the downloaded file", + optional: true), + FastlaneCore::ConfigItem.new(key: :sha256, + env_name: "FIREBASE_SHA_256", + description: "SHA256 for android", + optional: true) + ] + end + + def self.is_supported?(platform) + # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) + # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md + # + # [:ios, :mac, :android].include?(platform) + true + end + end + end +end diff --git a/lib/fastlane/plugin/firebase/actions/firebase_add_apple_store_id.rb b/lib/fastlane/plugin/firebase/actions/firebase_add_apple_store_id.rb new file mode 100644 index 0000000..05effda --- /dev/null +++ b/lib/fastlane/plugin/firebase/actions/firebase_add_apple_store_id.rb @@ -0,0 +1,104 @@ +module Fastlane + module Actions + class FirebaseAddAppleStoreIdAction < Action + + def self.run(params) + manager = Firebase::Manager.new + #Login + api = manager.login(params[:username]) + + #Select project + project = manager.select_project(params[:project_number]) + + # Client input + type = params[:type].to_sym + + bundle_id = params[:bundle_id] + name = params[:name] + appstore_id = params[:appstore_id] + store_id = params[:store_id] + + client = api.add_apple_store_id(project["projectNumber"], bundle_id, store_id) + + UI.success "Successfuly added apple store id of app #{bundle_id}" + end + + def self.description + "An unofficial tool to access Firebase" + end + + def self.authors + ["Tomas Kohout"] + end + + def self.return_value + # If your method provides a return value, you can describe here what it does + end + + def self.details + # Optional: + "Firebase helps you list your projects, create applications, download configuration files and more..." + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :username, + env_name: "FIREBASE_USERNAME", + description: "Username for your google account", + optional: false), + FastlaneCore::ConfigItem.new(key: :project_number, + env_name: "FIREBASE_PROJECT_NUMBER", + description: "Project number", + optional: true), + FastlaneCore::ConfigItem.new(key: :download_config, + env_name: "FIREBASE_DOWNLOAD_CONFIG", + description: "Should download config for created client", + optional: false, + is_string: false, + default_value: true), + FastlaneCore::ConfigItem.new(key: :type, + env_name: "FIREBASE_TYPE", + description: "Type of client (ios, android)", + verify_block: proc do |value| + types = [:ios, :android] + UI.user_error!("Type must be in #{types}") unless types.include?(value.to_sym) + end + ), + FastlaneCore::ConfigItem.new(key: :bundle_id, + env_name: "FIREBASE_BUNDLE_ID", + description: "Bundle ID (package name)", + optional: false), + FastlaneCore::ConfigItem.new(key: :name, + env_name: "FIREBASE_BUNDLE_ID", + description: "Display name", + optional: true), + FastlaneCore::ConfigItem.new(key: :appstore_id, + env_name: "FIREBASE_APPSTORE_ID", + description: "AppStore ID", + optional: true), + FastlaneCore::ConfigItem.new(key: :output_path, + env_name: "FIREBASE_OUTPUT_PATH", + description: "Path for the downloaded config", + optional: false, + default_value: "./"), + FastlaneCore::ConfigItem.new(key: :output_name, + env_name: "FIREBASE_OUTPUT_NAME", + description: "Name of the downloaded file", + optional: true), + FastlaneCore::ConfigItem.new(key: :store_id, + env_name: "APPLE_STORE_ID", + description: "App Apple ID", + optional: true) + ] + end + + def self.is_supported?(platform) + # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) + # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md + # + # [:ios, :mac, :android].include?(platform) + true + end + end + end +end diff --git a/lib/fastlane/plugin/firebase/actions/firebase_add_team.rb b/lib/fastlane/plugin/firebase/actions/firebase_add_team.rb new file mode 100644 index 0000000..e086897 --- /dev/null +++ b/lib/fastlane/plugin/firebase/actions/firebase_add_team.rb @@ -0,0 +1,105 @@ +module Fastlane + module Actions + class FirebaseAddTeamAction < Action + + def self.run(params) + manager = Firebase::Manager.new + #Login + api = manager.login(params[:username]) + + #Select project + project = manager.select_project(params[:project_number]) + + # Client input + type = params[:type].to_sym + + bundle_id = params[:bundle_id] + name = params[:name] + appstore_id = params[:appstore_id] + team_id = params[:team_id] + + # Add team + client = api.add_team(project["projectNumber"], bundle_id, team_id) + + UI.success "Successfuly added team_id of app #{bundle_id}" + end + + def self.description + "An unofficial tool to access Firebase" + end + + def self.authors + ["Tomas Kohout"] + end + + def self.return_value + # If your method provides a return value, you can describe here what it does + end + + def self.details + # Optional: + "Firebase helps you list your projects, create applications, download configuration files and more..." + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :username, + env_name: "FIREBASE_USERNAME", + description: "Username for your google account", + optional: false), + FastlaneCore::ConfigItem.new(key: :project_number, + env_name: "FIREBASE_PROJECT_NUMBER", + description: "Project number", + optional: true), + FastlaneCore::ConfigItem.new(key: :download_config, + env_name: "FIREBASE_DOWNLOAD_CONFIG", + description: "Should download config for created client", + optional: false, + is_string: false, + default_value: true), + FastlaneCore::ConfigItem.new(key: :type, + env_name: "FIREBASE_TYPE", + description: "Type of client (ios, android)", + verify_block: proc do |value| + types = [:ios, :android] + UI.user_error!("Type must be in #{types}") unless types.include?(value.to_sym) + end + ), + FastlaneCore::ConfigItem.new(key: :bundle_id, + env_name: "FIREBASE_BUNDLE_ID", + description: "Bundle ID (package name)", + optional: false), + FastlaneCore::ConfigItem.new(key: :name, + env_name: "FIREBASE_BUNDLE_ID", + description: "Display name", + optional: true), + FastlaneCore::ConfigItem.new(key: :appstore_id, + env_name: "FIREBASE_APPSTORE_ID", + description: "AppStore ID", + optional: true), + FastlaneCore::ConfigItem.new(key: :output_path, + env_name: "FIREBASE_OUTPUT_PATH", + description: "Path for the downloaded config", + optional: false, + default_value: "./"), + FastlaneCore::ConfigItem.new(key: :output_name, + env_name: "FIREBASE_OUTPUT_NAME", + description: "Name of the downloaded file", + optional: true), + FastlaneCore::ConfigItem.new(key: :team_id, + env_name: "FIREBASE_TEAM_ID", + description: "ID of the Apple Team", + optional: true) + ] + end + + def self.is_supported?(platform) + # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) + # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md + # + # [:ios, :mac, :android].include?(platform) + true + end + end + end +end diff --git a/lib/fastlane/plugin/firebase/lib/api.rb b/lib/fastlane/plugin/firebase/lib/api.rb index cfbeec9..0d59833 100644 --- a/lib/fastlane/plugin/firebase/lib/api.rb +++ b/lib/fastlane/plugin/firebase/lib/api.rb @@ -273,6 +273,38 @@ def download_config_file(project_number, client_id) UI.crash! e.page.body end end + + def add_team(project_number, bundle_id, team_id) + parameters = { + "iosTeamId" => team_id + } + + json = request_json("v1/projects/#{project_number}/clients/ios:#{bundle_id}:setTeamId", :post, parameters) + end + + def add_android_certificate(project_number, bundle_id, sha256) + parameters = { + "requestHeader" => { "clientVersion" => "FIREBASE" }, + "projectNumber" => project_number, + "clientId" => "android:#{bundle_id}", + "androidCertificate" => { + "androidSha256Hash" => sha256 + } + } + + json = request_json("v1/projects/#{project_number}/clients/android:#{bundle_id}:addAndroidCertificate", :post, parameters) + end + + def add_apple_store_id(project_number, bundle_id, store_id) + parameters = { + "requestHeader" => { "clientVersion" => "FIREBASE" }, + "projectNumber" => project_number, + "clientId" => "android:#{bundle_id}", + iosAppStoreId: store_id + } + + json = request_json("v1/projects/#{project_number}/clients/ios:#{bundle_id}:setAppStoreId", :post, parameters) + end end end end \ No newline at end of file From 565a5d6a2dc02f32770402680e9a90d9db421fe8 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Tue, 30 Jan 2018 14:36:35 -0200 Subject: [PATCH 02/11] Fix some actions and add env of password --- .../firebase_add_android_certificate.rb | 15 +++++++------ .../actions/firebase_add_apple_store_id.rb | 22 ++++++++----------- .../actions/firebase_add_client_action.rb | 7 +++++- .../firebase/actions/firebase_add_team.rb | 15 +++++++------ .../actions/firebase_delete_client_action.rb | 7 +++++- .../firebase_download_config_action.rb | 7 +++++- .../firebase/actions/firebase_list_action.rb | 7 +++++- .../firebase_upload_certificate_action.rb | 7 +++++- lib/fastlane/plugin/firebase/lib/manager.rb | 4 ++-- 9 files changed, 57 insertions(+), 34 deletions(-) diff --git a/lib/fastlane/plugin/firebase/actions/firebase_add_android_certificate.rb b/lib/fastlane/plugin/firebase/actions/firebase_add_android_certificate.rb index 3f316dc..d3f9e35 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_add_android_certificate.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_add_android_certificate.rb @@ -5,7 +5,7 @@ class FirebaseAddAndroidCertificateAction < Action def self.run(params) manager = Firebase::Manager.new #Login - api = manager.login(params[:username]) + api = manager.login(params[:username], params[:password]) #Select project project = manager.select_project(params[:project_number]) @@ -52,6 +52,11 @@ def self.available_options env_name: "FIREBASE_USERNAME", description: "Username for your google account", optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), FastlaneCore::ConfigItem.new(key: :project_number, env_name: "FIREBASE_PROJECT_NUMBER", description: "Project number", @@ -65,11 +70,7 @@ def self.available_options FastlaneCore::ConfigItem.new(key: :type, env_name: "FIREBASE_TYPE", description: "Type of client (ios, android)", - verify_block: proc do |value| - types = [:ios, :android] - UI.user_error!("Type must be in #{types}") unless types.include?(value.to_sym) - end - ), + optional: true), FastlaneCore::ConfigItem.new(key: :bundle_id, env_name: "FIREBASE_BUNDLE_ID", description: "Bundle ID (package name)", @@ -94,7 +95,7 @@ def self.available_options FastlaneCore::ConfigItem.new(key: :sha256, env_name: "FIREBASE_SHA_256", description: "SHA256 for android", - optional: true) + optional: false) ] end diff --git a/lib/fastlane/plugin/firebase/actions/firebase_add_apple_store_id.rb b/lib/fastlane/plugin/firebase/actions/firebase_add_apple_store_id.rb index 05effda..68be65f 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_add_apple_store_id.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_add_apple_store_id.rb @@ -5,7 +5,7 @@ class FirebaseAddAppleStoreIdAction < Action def self.run(params) manager = Firebase::Manager.new #Login - api = manager.login(params[:username]) + api = manager.login(params[:username], params[:password]) #Select project project = manager.select_project(params[:project_number]) @@ -16,9 +16,8 @@ def self.run(params) bundle_id = params[:bundle_id] name = params[:name] appstore_id = params[:appstore_id] - store_id = params[:store_id] - client = api.add_apple_store_id(project["projectNumber"], bundle_id, store_id) + client = api.add_apple_store_id(project["projectNumber"], bundle_id, appstore_id) UI.success "Successfuly added apple store id of app #{bundle_id}" end @@ -46,6 +45,11 @@ def self.available_options env_name: "FIREBASE_USERNAME", description: "Username for your google account", optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), FastlaneCore::ConfigItem.new(key: :project_number, env_name: "FIREBASE_PROJECT_NUMBER", description: "Project number", @@ -59,11 +63,7 @@ def self.available_options FastlaneCore::ConfigItem.new(key: :type, env_name: "FIREBASE_TYPE", description: "Type of client (ios, android)", - verify_block: proc do |value| - types = [:ios, :android] - UI.user_error!("Type must be in #{types}") unless types.include?(value.to_sym) - end - ), + optional: true), FastlaneCore::ConfigItem.new(key: :bundle_id, env_name: "FIREBASE_BUNDLE_ID", description: "Bundle ID (package name)", @@ -75,7 +75,7 @@ def self.available_options FastlaneCore::ConfigItem.new(key: :appstore_id, env_name: "FIREBASE_APPSTORE_ID", description: "AppStore ID", - optional: true), + optional: false), FastlaneCore::ConfigItem.new(key: :output_path, env_name: "FIREBASE_OUTPUT_PATH", description: "Path for the downloaded config", @@ -84,10 +84,6 @@ def self.available_options FastlaneCore::ConfigItem.new(key: :output_name, env_name: "FIREBASE_OUTPUT_NAME", description: "Name of the downloaded file", - optional: true), - FastlaneCore::ConfigItem.new(key: :store_id, - env_name: "APPLE_STORE_ID", - description: "App Apple ID", optional: true) ] end diff --git a/lib/fastlane/plugin/firebase/actions/firebase_add_client_action.rb b/lib/fastlane/plugin/firebase/actions/firebase_add_client_action.rb index 6fd4e0c..ced15dd 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_add_client_action.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_add_client_action.rb @@ -5,7 +5,7 @@ class FirebaseAddClientAction < Action def self.run(params) manager = Firebase::Manager.new #Login - api = manager.login(params[:username]) + api = manager.login(params[:username], params[:password]) #Select project project = manager.select_project(params[:project_number]) @@ -68,6 +68,11 @@ def self.available_options env_name: "FIREBASE_USERNAME", description: "Username for your google account", optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), FastlaneCore::ConfigItem.new(key: :project_number, env_name: "FIREBASE_PROJECT_NUMBER", description: "Project number", diff --git a/lib/fastlane/plugin/firebase/actions/firebase_add_team.rb b/lib/fastlane/plugin/firebase/actions/firebase_add_team.rb index e086897..97c5639 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_add_team.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_add_team.rb @@ -5,7 +5,7 @@ class FirebaseAddTeamAction < Action def self.run(params) manager = Firebase::Manager.new #Login - api = manager.login(params[:username]) + api = manager.login(params[:username], params[:password]) #Select project project = manager.select_project(params[:project_number]) @@ -47,6 +47,11 @@ def self.available_options env_name: "FIREBASE_USERNAME", description: "Username for your google account", optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), FastlaneCore::ConfigItem.new(key: :project_number, env_name: "FIREBASE_PROJECT_NUMBER", description: "Project number", @@ -60,11 +65,7 @@ def self.available_options FastlaneCore::ConfigItem.new(key: :type, env_name: "FIREBASE_TYPE", description: "Type of client (ios, android)", - verify_block: proc do |value| - types = [:ios, :android] - UI.user_error!("Type must be in #{types}") unless types.include?(value.to_sym) - end - ), + optional: true), FastlaneCore::ConfigItem.new(key: :bundle_id, env_name: "FIREBASE_BUNDLE_ID", description: "Bundle ID (package name)", @@ -89,7 +90,7 @@ def self.available_options FastlaneCore::ConfigItem.new(key: :team_id, env_name: "FIREBASE_TEAM_ID", description: "ID of the Apple Team", - optional: true) + optional: false) ] end diff --git a/lib/fastlane/plugin/firebase/actions/firebase_delete_client_action.rb b/lib/fastlane/plugin/firebase/actions/firebase_delete_client_action.rb index b333416..2a54685 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_delete_client_action.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_delete_client_action.rb @@ -5,7 +5,7 @@ class FirebaseDeleteClientAction < Action def self.run(params) manager = Firebase::Manager.new #Login - api = manager.login(params[:username]) + api = manager.login(params[:username], params[:password]) #Select project project = manager.select_project(params[:project_number]) @@ -48,6 +48,11 @@ def self.available_options env_name: "FIREBASE_USERNAME", description: "Username for your google account", optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), FastlaneCore::ConfigItem.new(key: :project_number, env_name: "FIREBASE_PROJECT_NUMBER", description: "Project number", diff --git a/lib/fastlane/plugin/firebase/actions/firebase_download_config_action.rb b/lib/fastlane/plugin/firebase/actions/firebase_download_config_action.rb index 69e23c9..e125169 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_download_config_action.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_download_config_action.rb @@ -6,7 +6,7 @@ def self.run(params) manager = Firebase::Manager.new # Login - api = manager.login(params[:username]) + api = manager.login(params[:username], params[:password]) #Select project project = manager.select_project(params[:project_number]) @@ -47,6 +47,11 @@ def self.available_options env_name: "FIREBASE_USERNAME", description: "Username for your google account", optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), FastlaneCore::ConfigItem.new(key: :project_number, env_name: "FIREBASE_PROJECT_NUMBER", description: "Project number", diff --git a/lib/fastlane/plugin/firebase/actions/firebase_list_action.rb b/lib/fastlane/plugin/firebase/actions/firebase_list_action.rb index aa7e8b3..a52e946 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_list_action.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_list_action.rb @@ -6,7 +6,7 @@ class FirebaseListAction < Action def self.run(params) manager = Firebase::Manager.new # Login - api = manager.login(params[:username]) + api = manager.login(params[:username], params[:password]) # List projects projects = api.project_list() @@ -43,6 +43,11 @@ def self.available_options env_name: "FIREBASE_USERNAME", description: "Username for your google account", optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), FastlaneCore::ConfigItem.new(key: :project_number, env_name: "FIREBASE_PROJECT_NUMBER", description: "Project number", diff --git a/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb b/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb index e213d24..2be8bdc 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb @@ -11,7 +11,7 @@ def self.run(params) manager = Firebase::Manager.new # Login - api = manager.login(params[:username]) + api = manager.login(params[:username], params[:password]) p12_path = params[:p12_path] @@ -73,6 +73,11 @@ def self.available_options env_name: "FIREBASE_USERNAME", description: "Username for your google account", optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), FastlaneCore::ConfigItem.new(key: :p12_path, env_name: "FIREBASE_P12PATH", description: "Path to certificate", diff --git a/lib/fastlane/plugin/firebase/lib/manager.rb b/lib/fastlane/plugin/firebase/lib/manager.rb index 9db95a1..01e59ee 100644 --- a/lib/fastlane/plugin/firebase/lib/manager.rb +++ b/lib/fastlane/plugin/firebase/lib/manager.rb @@ -7,11 +7,11 @@ def server_name "firebase.google.com" end - def login(username) + def login(username, password = nil) item = Security::InternetPassword.find(server: server_name(), account: username) keychain_password = item.password if item - password = keychain_password + password = password || keychain_password begin password = UI.password("Password for #{username}") unless password From 1a3faa02c3ce6ce73180b0e05533ac27450f732d Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Thu, 1 Feb 2018 17:12:05 -0200 Subject: [PATCH 03/11] Fix p12 password same env problem --- .../firebase/actions/firebase_upload_certificate_action.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb b/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb index 2be8bdc..f0996d3 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb @@ -86,7 +86,7 @@ def self.available_options UI.user_error! "Inserted value is not file - #{value}" unless File.exists? value end), FastlaneCore::ConfigItem.new(key: :p12_password, - env_name: "FIREBASE_PASSWORD", + env_name: "FIREBASE_P12_PASSWORD", description: "Password to the certicate", optional: true), FastlaneCore::ConfigItem.new(key: :project_number, From 371dd1524d8948d6d2425c6d9cbd4957d88ad9d1 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Thu, 16 Aug 2018 18:48:57 -0300 Subject: [PATCH 04/11] Support cookies --- lib/fastlane/plugin/firebase/lib/api.rb | 35 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/fastlane/plugin/firebase/lib/api.rb b/lib/fastlane/plugin/firebase/lib/api.rb index 0d59833..600eb40 100644 --- a/lib/fastlane/plugin/firebase/lib/api.rb +++ b/lib/fastlane/plugin/firebase/lib/api.rb @@ -28,23 +28,31 @@ def initialize(email, password) def login(email, password) UI.message "Logging in to Google account #{email}" + begin + @agent.cookie_jar.load '.cookies.yml' + UI.message "Cookies found!" - page = @agent.get("#{@login_url}?passive=1209600&osid=1&continue=#{@base_url}/&followup=#{@base_url}/") - - #First step - email - google_form = page.form() - google_form.Email = email + page = @agent.get(@base_url) + rescue + UI.message "Cookies not found, try to login" - #Send - page = @agent.submit(google_form, google_form.buttons.first) + page = @agent.get("#{@login_url}?passive=1209600&osid=1&continue=#{@base_url}/&followup=#{@base_url}/") - #Second step - password - google_form = page.form() - google_form.Passwd = password + #First step - email + google_form = page.form() + google_form.Email = email + + #Send + page = @agent.submit(google_form, google_form.buttons.first) + + #Second step - password + google_form = page.form() + google_form.Passwd = password + + #Send + page = @agent.submit(google_form, google_form.buttons.first) + end - #Send - page = @agent.submit(google_form, google_form.buttons.first) - while page do if extract_api_key(page) then UI.success "Successfuly logged in" @@ -159,6 +167,7 @@ def generate_sapisid_hash(time, sapisid, origin) end def create_authorization_headers + @agent.cookie_jar.save_as '.cookies.yml', :session => true, :format => :yaml cookie = @agent.cookie_jar.jar["google.com"]["/"]["SAPISID"] sapisid = cookie.value origin = @base_url From 8e5c6d3beff051bcf719fed189fa9d019bef2271 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Thu, 16 Aug 2018 18:50:46 -0300 Subject: [PATCH 05/11] Bump version --- lib/fastlane/plugin/firebase/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/firebase/version.rb b/lib/fastlane/plugin/firebase/version.rb index b74b277..1f9bfca 100644 --- a/lib/fastlane/plugin/firebase/version.rb +++ b/lib/fastlane/plugin/firebase/version.rb @@ -1,5 +1,5 @@ module Fastlane module Firebase - VERSION = "0.2.1" + VERSION = "0.2.2" end end From bcd2dc6a64e981a3213fcbf3703430df423172e3 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Fri, 17 Aug 2018 11:01:05 -0300 Subject: [PATCH 06/11] Use cookies from env --- Gemfile | 1 + lib/fastlane/plugin/firebase/lib/api.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 2aa2e3e..7e39f86 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' gemspec +gem 'two_captcha' plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval(File.read(plugins_path), binding) if File.exist?(plugins_path) diff --git a/lib/fastlane/plugin/firebase/lib/api.rb b/lib/fastlane/plugin/firebase/lib/api.rb index 600eb40..a7dc081 100644 --- a/lib/fastlane/plugin/firebase/lib/api.rb +++ b/lib/fastlane/plugin/firebase/lib/api.rb @@ -28,13 +28,20 @@ def initialize(email, password) def login(email, password) UI.message "Logging in to Google account #{email}" + + # Load cookie from ENV into file if is set + if !ENV["FIREBASE_COOKIE"].nil? then + File.open('.cookies.yml', 'w') { |file| file.write(ENV["FIREBASE_COOKIE"]) } + end + + # Try to load cookie from file begin @agent.cookie_jar.load '.cookies.yml' UI.message "Cookies found!" page = @agent.get(@base_url) rescue - UI.message "Cookies not found, try to login" + UI.message "Cookies not found, trying to login" page = @agent.get("#{@login_url}?passive=1209600&osid=1&continue=#{@base_url}/&followup=#{@base_url}/") From e4d947bbae5c334067ba90ef7b9a367fda59c116 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Sun, 23 Sep 2018 11:43:52 -0300 Subject: [PATCH 07/11] Support .p8 file --- .../firebase_upload_certificate_action.rb | 29 +++++++++++++++++-- lib/fastlane/plugin/firebase/lib/api.rb | 10 +++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb b/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb index f0996d3..eb90216 100644 --- a/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb +++ b/lib/fastlane/plugin/firebase/actions/firebase_upload_certificate_action.rb @@ -29,11 +29,26 @@ def self.run(params) #Base64 certificate certificate_value = Base64.encode64(File.open(p12_path, "rb").read).delete!("\n") + # Check if we are dealing with .p12 file or .p8 + isP8 = p12_path.end_with? ".p8" + + # Perform extra action if is .p8 + if isP8 then + team_id = params[:team_id] + api.add_team(project_number, client_id.gsub('ios:', ''), team_id) + end + UI.message "Uploading certificate ..." cert_password = params[:p12_password] - begin - api.upload_certificate(project_number, client_id, type, certificate_value, cert_password) + begin + if isP8 then + key_code = params[:key_code] + api.upload_p8_certificate(project_number, client_id, type, certificate_value, key_code) + else + api.upload_certificate(project_number, client_id, type, certificate_value, cert_password) + end + rescue Firebase::Api::BadRequestError => e if e.message.start_with? "3000" then UI.error e.message @@ -99,7 +114,15 @@ def self.available_options optional: true), FastlaneCore::ConfigItem.new(key: :type, env_name: "FIREBASE_TYPE", - description: "Type of certificate (development, production)") + description: "Type of certificate (development, production)"), + FastlaneCore::ConfigItem.new(key: :team_id, + env_name: "FIREBASE_TEAM_ID", + description: "ID of the Apple Team", + optional: true), + FastlaneCore::ConfigItem.new(key: :key_code, + env_name: "FIREBASE_P8_KEY_CODE", + description: "P8 certicate key code", + optional: true) ] end diff --git a/lib/fastlane/plugin/firebase/lib/api.rb b/lib/fastlane/plugin/firebase/lib/api.rb index a7dc081..5f74e49 100644 --- a/lib/fastlane/plugin/firebase/lib/api.rb +++ b/lib/fastlane/plugin/firebase/lib/api.rb @@ -275,6 +275,16 @@ def upload_certificate(project_number, client_id, type, certificate_value, certi json = request_json("v1/projects/#{project_number}/clients/#{client_id}:setApnsCertificate", :post, parameters) end + def upload_p8_certificate(project_number, client_id, type, certificate_value, key_code) + + parameters = { + "keyId" => key_code, + "privateKey" => certificate_value + } + + json = request_json("v1/projects/#{project_number}/clients/#{client_id}:setApnsAuthKey", :post, parameters) + end + def download_config_file(project_number, client_id) request = "[\"getArtifactRequest\",null,\"#{client_id}\",\"1\",\"#{project_number}\"]" From eaec30431d0e6a624168dbcc2ea540517fe04f86 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Wed, 21 Nov 2018 17:36:12 -0200 Subject: [PATCH 08/11] Bump mechanize --- fastlane-plugin-firebase.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlane-plugin-firebase.gemspec b/fastlane-plugin-firebase.gemspec index 1562677..8c30a6a 100644 --- a/fastlane-plugin-firebase.gemspec +++ b/fastlane-plugin-firebase.gemspec @@ -29,6 +29,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake' spec.add_development_dependency 'rubocop' spec.add_development_dependency 'fastlane', '>= 2.5.0' - spec.add_dependency 'mechanize' + spec.add_dependency 'mechanize', '2.7.6' end From 29968e2c922b33c816cd96ff39d4e261aa0252d1 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Wed, 21 Nov 2018 17:38:47 -0200 Subject: [PATCH 09/11] Bump version --- lib/fastlane/plugin/firebase/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/firebase/version.rb b/lib/fastlane/plugin/firebase/version.rb index 1f9bfca..57438f9 100644 --- a/lib/fastlane/plugin/firebase/version.rb +++ b/lib/fastlane/plugin/firebase/version.rb @@ -1,5 +1,5 @@ module Fastlane module Firebase - VERSION = "0.2.2" + VERSION = "0.2.3" end end From 8741a12b9bfd531db5507cb4234cec967d007320 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Wed, 9 Jan 2019 14:49:33 -0200 Subject: [PATCH 10/11] Fix android request --- lib/fastlane/plugin/firebase/lib/api.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/fastlane/plugin/firebase/lib/api.rb b/lib/fastlane/plugin/firebase/lib/api.rb index 5f74e49..91f5089 100644 --- a/lib/fastlane/plugin/firebase/lib/api.rb +++ b/lib/fastlane/plugin/firebase/lib/api.rb @@ -232,7 +232,7 @@ def project_list def add_client(project_number, type, bundle_id, app_name, ios_appstore_id ) parameters = { - "requestHeader" => { "clientVersion" => "FIREBASE" }, + "requestHeader" => { }, "displayName" => app_name || "" } @@ -244,7 +244,8 @@ def add_client(project_number, type, bundle_id, app_name, ios_appstore_id ) } when :android parameters["androidData"] = { - "packageName" => bundle_id + "packageName" => bundle_id, + "androidCertificateHash" => [] } end From baae1dc31e01a0437ea38c03d27eebca4ae71ade Mon Sep 17 00:00:00 2001 From: jl-gogovapps <44532602+jl-gogovapps@users.noreply.github.com> Date: Mon, 4 May 2020 14:20:01 -0400 Subject: [PATCH 11/11] Support project name or ID (#1) * Add support for project_number being a project displayName * Add support for listing and updating android and ios restrictions on an API key * Add ability to get the server key from the Firebase API --- fastlane/README.md | 54 +++++++--- .../actions/firebase_get_server_key.rb | 98 +++++++++++++++++++ .../google_api_key_add_allowed_bundle_ids.rb | 78 +++++++++++++++ .../google_api_key_list_allowed_bundle_ids.rb | 70 +++++++++++++ lib/fastlane/plugin/firebase/lib/api.rb | 50 +++++++++- lib/fastlane/plugin/firebase/lib/manager.rb | 2 + lib/fastlane/plugin/firebase/version.rb | 2 +- 7 files changed, 337 insertions(+), 17 deletions(-) create mode 100644 lib/fastlane/plugin/firebase/actions/firebase_get_server_key.rb create mode 100644 lib/fastlane/plugin/firebase/actions/google_api_key_add_allowed_bundle_ids.rb create mode 100644 lib/fastlane/plugin/firebase/actions/google_api_key_list_allowed_bundle_ids.rb diff --git a/fastlane/README.md b/fastlane/README.md index 75ffef4..0147191 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -28,33 +28,57 @@ xcode-select --install -# Available Actions -### test_list +### google_api_key_list_allowed_bundle_ids ``` -fastlane test_list + google_api_key_list_allowed_bundle_ids( + project_number: "some:project-id", + api_key_id: "fd1d4e87-0ba5-4e2e-bacd-54d96b70befd", + type: 'ios', + username: ENV['GOOGLE_USERNAME'], + password: ENV['GOOGLE_PASSWORD'], + ) ``` - -### test_add_client ``` -fastlane test_add_client + google_api_key_list_allowed_bundle_ids( + project_number: "some:project-id", + api_key_id: "fd1d4e87-0ba5-4e2e-bacd-54d96b70befd", + type: 'android', + username: ENV['GOOGLE_USERNAME'], + password: ENV['GOOGLE_PASSWORD'], + ) ``` -### test_delete_client +### google_api_key_add_allowed_bundle_ids ``` -fastlane test_delete_client + google_api_key_add_allowed_bundle_ids( + project_number: "some:project-id", + api_key_id: "fd1d4e87-0ba5-4e2e-bacd-54d96b70befd", + type: 'ios', + bundle_id: 'com.example.test', + username: ENV['GOOGLE_USERNAME'], + password: ENV['GOOGLE_PASSWORD'], + ) + google_api_key_add_allowed_bundle_ids( + project_number: "some:project-id", + api_key_id: "fd1d4e87-0ba5-4e2e-bacd-54d96b70befd", + type: 'android', + bundle_id: 'com.example.test', + fingerprint: '2a:ae:6c:35:c9:4f:cf:b4:15:db:e9:5f:40:8b:9c:e9:1e:e8:46:ed', + username: ENV['GOOGLE_USERNAME'], + password: ENV['GOOGLE_PASSWORD'], + ) ``` -### test_upload_certificate -``` -fastlane test_upload_certificate -``` +### firebase_get_server_key -### test_download_config ``` -fastlane test_download_config + firebase_get_server_key( + project_number: "project-name-or-number", + username: ENV['GOOGLE_USERNAME'], + password: ENV['GOOGLE_PASSWORD'], + ) ``` - ---- This README.md is auto-generated and will be re-generated every time [fastlane](https://fastlane.tools) is run. diff --git a/lib/fastlane/plugin/firebase/actions/firebase_get_server_key.rb b/lib/fastlane/plugin/firebase/actions/firebase_get_server_key.rb new file mode 100644 index 0000000..51baa01 --- /dev/null +++ b/lib/fastlane/plugin/firebase/actions/firebase_get_server_key.rb @@ -0,0 +1,98 @@ +module Fastlane + module Actions + class FirebaseGetServerKeyAction < Action + + def self.run(params) + manager = Firebase::Manager.new + #Login + api = manager.login(params[:username], params[:password]) + + #Select project + project = manager.select_project(params[:project_number]) + + # Add team + server_key = api.get_server_key(project["projectNumber"]) + + UI.success "Successfuly found of server key #{server_key['token'][0]['token']}" + end + + def self.description + "An unofficial tool to access Firebase" + end + + def self.authors + ["Jonathan Lewis"] + end + + def self.return_value + # If your method provides a return value, you can describe here what it does + end + + def self.details + # Optional: + "Firebase helps you list your projects, create applications, download configuration files and more..." + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :username, + env_name: "FIREBASE_USERNAME", + description: "Username for your google account", + optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), + FastlaneCore::ConfigItem.new(key: :project_number, + env_name: "FIREBASE_PROJECT_NUMBER", + description: "Project number", + optional: true), + FastlaneCore::ConfigItem.new(key: :download_config, + env_name: "FIREBASE_DOWNLOAD_CONFIG", + description: "Should download config for created client", + optional: false, + is_string: false, + default_value: true), + FastlaneCore::ConfigItem.new(key: :type, + env_name: "FIREBASE_TYPE", + description: "Type of client (ios, android)", + optional: true), + FastlaneCore::ConfigItem.new(key: :bundle_id, + env_name: "FIREBASE_BUNDLE_ID", + description: "Bundle ID (package name)", + optional: false), + FastlaneCore::ConfigItem.new(key: :name, + env_name: "FIREBASE_BUNDLE_ID", + description: "Display name", + optional: true), + FastlaneCore::ConfigItem.new(key: :appstore_id, + env_name: "FIREBASE_APPSTORE_ID", + description: "AppStore ID", + optional: true), + FastlaneCore::ConfigItem.new(key: :output_path, + env_name: "FIREBASE_OUTPUT_PATH", + description: "Path for the downloaded config", + optional: false, + default_value: "./"), + FastlaneCore::ConfigItem.new(key: :output_name, + env_name: "FIREBASE_OUTPUT_NAME", + description: "Name of the downloaded file", + optional: true), + FastlaneCore::ConfigItem.new(key: :team_id, + env_name: "FIREBASE_TEAM_ID", + description: "ID of the Apple Team", + optional: false) + ] + end + + def self.is_supported?(platform) + # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) + # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md + # + # [:ios, :mac, :android].include?(platform) + true + end + end + end +end diff --git a/lib/fastlane/plugin/firebase/actions/google_api_key_add_allowed_bundle_ids.rb b/lib/fastlane/plugin/firebase/actions/google_api_key_add_allowed_bundle_ids.rb new file mode 100644 index 0000000..2f1f6c7 --- /dev/null +++ b/lib/fastlane/plugin/firebase/actions/google_api_key_add_allowed_bundle_ids.rb @@ -0,0 +1,78 @@ +require 'base64' + +module Fastlane + module Actions + class GoogleApiKeyAddAllowedBundleIdsAction < Action + def self.run(params) + manager = Firebase::Manager.new + # Login + api = manager.login(params[:username], params[:password]) + + key_info = api.get_apikey(params[:project_number], params[:api_key_id]) + case params[:type] + when 'ios' + key_info['iosKeyDetails']['allowedBundleIds'] << params[:bundle_id] + api.update_apikey(params[:project_number], params[:api_key_id], 'apiTargetKeyDetails,iosKeyDetails', key_info) + when 'android' + key_info['androidKeyDetails']['allowedApplications'] << { + packageName: params[:bundle_id], + sha1Fingerprint: Base64.strict_encode64([params[:fingerprint].gsub(':','')].pack('H*')) + } + api.update_apikey(params[:project_number], params[:api_key_id], 'apiTargetKeyDetails,androidKeyDetails', key_info) + end + end + + def self.description + "An unofficial tool to access Firebase" + end + + def self.authors + ["Jonathan Lewis"] + end + + def self.return_value + # If your method provides a return value, you can describe here what it does + end + + def self.details + # Optional: + "Get iOS Bundle IDs allowed to access an API Key" + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :username, + env_name: "FIREBASE_USERNAME", + description: "Username for your google account", + optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), + FastlaneCore::ConfigItem.new(key: :project_number, + env_name: "GOOGLE_PROJECT_NUMBER", + description: "Project number", + optional: false), + FastlaneCore::ConfigItem.new(key: :api_key_id, + env_name: "GOOGLE_API_KEY_ID", + description: "API Key ID to retrieve details for", + optional: false), + FastlaneCore::ConfigItem.new(key: :type, + description: "ios or android", + optional: false), + FastlaneCore::ConfigItem.new(key: :bundle_id, + description: "ios bundle id", + optional: false), + FastlaneCore::ConfigItem.new(key: :fingerprint, + description: "Android SHA-1 fingerprint", + optional: true) + ] + end + + def self.is_supported?(platform) + true + end + end + end +end diff --git a/lib/fastlane/plugin/firebase/actions/google_api_key_list_allowed_bundle_ids.rb b/lib/fastlane/plugin/firebase/actions/google_api_key_list_allowed_bundle_ids.rb new file mode 100644 index 0000000..4318b58 --- /dev/null +++ b/lib/fastlane/plugin/firebase/actions/google_api_key_list_allowed_bundle_ids.rb @@ -0,0 +1,70 @@ +module Fastlane + module Actions + class GoogleApiKeyListAllowedBundleIdsAction < Action + def self.run(params) + manager = Firebase::Manager.new + # Login + api = manager.login(params[:username], params[:password]) + + key_info = api.get_apikey(params[:project_number], params[:api_key_id]) + case params[:type] + when 'ios' + key_info['iosKeyDetails']['allowedBundleIds'].each do |bundle| + UI.message bundle + end + when 'android' + key_info['androidKeyDetails']['allowedApplications'].each do |app| + UI.message app['packageName'] + end + end + end + + def self.description + "An unofficial tool to access Firebase" + end + + def self.authors + ["Jonathan Lewis"] + end + + def self.return_value + # If your method provides a return value, you can describe here what it does + end + + def self.details + # Optional: + "Get iOS Bundle IDs allowed to access an API Key" + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :username, + env_name: "FIREBASE_USERNAME", + description: "Username for your google account", + optional: false), + FastlaneCore::ConfigItem.new(key: :password, + env_name: "FIREBASE_PASSWORD", + sensitive: true, + description: "Password to your firebase account", + optional: true), + FastlaneCore::ConfigItem.new(key: :project_number, + env_name: "GOOGLE_PROJECT_NUMBER", + description: "Project number", + optional: false), + FastlaneCore::ConfigItem.new(key: :api_key_id, + env_name: "GOOGLE_API_KEY_ID", + description: "API Key ID to retrieve details for", + optional: false), + FastlaneCore::ConfigItem.new(key: :type, + description: "ios or android", + optional: false) + + ] + end + + def self.is_supported?(platform) + true + end + end + end +end diff --git a/lib/fastlane/plugin/firebase/lib/api.rb b/lib/fastlane/plugin/firebase/lib/api.rb index 91f5089..87a3941 100644 --- a/lib/fastlane/plugin/firebase/lib/api.rb +++ b/lib/fastlane/plugin/firebase/lib/api.rb @@ -22,6 +22,7 @@ def initialize(email, password) @base_url = "https://console.firebase.google.com" @sdk_url = "https://mobilesdk-pa.clients6.google.com/" @login_url = "https://accounts.google.com/ServiceLogin" + @apikey_url = "https://apikeys.clients6.google.com/" login(email, password) end @@ -197,6 +198,38 @@ def create_authorization_headers json_headers end + def apikey_request_json(path, method = :get, parameters = Hash.new, headers = Hash.new, query = '') + begin + if method == :get then + parameters["key"] = @api_key + page = @agent.get("#{@apikey_url}#{path}", parameters, nil, headers.merge(@authorization_headers)) + elsif method == :post then + headers['Content-Type'] = 'application/json' + puts "#{@apikey_url}#{path}?key=#{@api_key}" + puts parameters.to_json + page = @agent.post("#{@apikey_url}#{path}?key=#{@api_key}", parameters.to_json, headers.merge(@authorization_headers)) + elsif method == :patch then + headers['Content-Type'] = 'application/json' + page = @agent.request_with_entity( + 'patch', "#{@apikey_url}#{path}?key=#{@api_key}&#{query}", parameters.to_json, headers.merge(@authorization_headers) + ) + elsif method == :delete then + page = @agent.delete("#{@apikey_url}#{path}?key=#{@api_key}", parameters, headers.merge(@authorization_headers)) + end + + JSON.parse(page.body) + + rescue Mechanize::ResponseCodeError => e + code = e.response_code.to_i + if code >= 400 && code < 500 then + if body = JSON.parse(e.page.body) then + raise BadRequestError.new(body["error"]["message"], code) + end + end + UI.crash! e.page.body + end + end + def request_json(path, method = :get, parameters = Hash.new, headers = Hash.new) begin if method == :get then @@ -332,6 +365,21 @@ def add_apple_store_id(project_number, bundle_id, store_id) json = request_json("v1/projects/#{project_number}/clients/ios:#{bundle_id}:setAppStoreId", :post, parameters) end + + def get_apikey(project_number, api_key) + json = apikey_request_json("v1/projects/#{project_number}/apiKeys/#{api_key}", :get) + end + + def update_apikey(project_number, api_key, update_mask, payload) + json = apikey_request_json( + "v1/projects/#{project_number}/apiKeys/#{api_key}", :patch, payload, Hash.new, "updateMask=#{update_mask}" + ) + end + + def get_server_key(project_number) + parameters = {} + json = request_json("v1/projects/#{project_number}:getIidTokens", :post, parameters) + end end end -end \ No newline at end of file +end diff --git a/lib/fastlane/plugin/firebase/lib/manager.rb b/lib/fastlane/plugin/firebase/lib/manager.rb index 01e59ee..4f8ea5b 100644 --- a/lib/fastlane/plugin/firebase/lib/manager.rb +++ b/lib/fastlane/plugin/firebase/lib/manager.rb @@ -46,6 +46,8 @@ def select_project(project_number) if project = projects.select {|p| p["projectNumber"] == project_number }.first then project + elsif project = projects.select {|p| p["displayName"] == project_number }.first then + project else options = projects.map { |p| p["displayName"] } index = select_index("Select project:", options) diff --git a/lib/fastlane/plugin/firebase/version.rb b/lib/fastlane/plugin/firebase/version.rb index 57438f9..eece009 100644 --- a/lib/fastlane/plugin/firebase/version.rb +++ b/lib/fastlane/plugin/firebase/version.rb @@ -1,5 +1,5 @@ module Fastlane module Firebase - VERSION = "0.2.3" + VERSION = "0.2.6" end end