From 903ec0f521dbdd9d6845e115f35c4750ae3fedfc Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Sun, 29 Oct 2017 21:40:30 -0200 Subject: [PATCH] Add env FASTLANE_PASSWORD and reindent --- lib/fastlane/plugin/firebase/lib/manager.rb | 66 +++++++++++---------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/lib/fastlane/plugin/firebase/lib/manager.rb b/lib/fastlane/plugin/firebase/lib/manager.rb index 9db95a1..9189072 100644 --- a/lib/fastlane/plugin/firebase/lib/manager.rb +++ b/lib/fastlane/plugin/firebase/lib/manager.rb @@ -1,20 +1,24 @@ module Fastlane module Firebase - + - class Manager - def server_name + class Manager + def server_name "firebase.google.com" end - def login(username) - item = Security::InternetPassword.find(server: server_name(), account: username) - keychain_password = item.password if item + def login(username) + password = ENV["FIREBASE_PASSWORD"] - password = keychain_password - begin + unless password + item = Security::InternetPassword.find(server: server_name(), account: username) + keychain_password = item.password if item + password = keychain_password + end + + begin password = UI.password("Password for #{username}") unless password - + #Api instance @api = Firebase::Api.new(username, password) @@ -26,7 +30,7 @@ def login(username) UI.error e.message if UI.confirm "Do you want to re-enter your password?" then - password = nil + password = nil if keychain_password then puts "Removing Keychain entry for user '#{username}'...".yellow Security::InternetPassword.delete(server: server_name(), account: username) @@ -35,21 +39,21 @@ def login(username) retry end end - end + end - def select_project(project_number) - projects = @api.project_list() + def select_project(project_number) + projects = @api.project_list() if projects.count == 0 then UI.user_error! "No projects exist under the account" return end - if project = projects.select {|p| p["projectNumber"] == project_number }.first then - project - else - options = projects.map { |p| p["displayName"] } - index = select_index("Select project:", options) - projects[index] + if project = projects.select {|p| p["projectNumber"] == project_number }.first then + project + else + options = projects.map { |p| p["displayName"] } + index = select_index("Select project:", options) + projects[index] end end @@ -61,19 +65,19 @@ def select_client(project, client_id) clients = (project["clientSummary"] || []).sort {|left, right| left["clientId"] <=> right["clientId"] } - if client = clients.select {|c| c["clientId"] == client_id }.first then - client - else - options = clients.map { |p| "#{p["clientId"]} (#{p["displayName"]})" } - index = select_index("Select client:", options) - clients[index] - end + if client = clients.select {|c| c["clientId"] == client_id }.first then + client + else + options = clients.map { |p| "#{p["clientId"]} (#{p["displayName"]})" } + index = select_index("Select client:", options) + clients[index] + end end def select_index(text, options) - selected = UI.select(text, options) - return options.index(selected) - end - end - end + selected = UI.select(text, options) + return options.index(selected) + end + end + end end