From 4f0ac3aea36e4a0711a9ee60d19bf6d3c426e63e Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Tue, 16 Jan 2018 19:45:23 -0200 Subject: [PATCH] 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