Skip to content

Commit

Permalink
Add env FASTLANE_PASSWORD and reindent
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Santos committed Oct 29, 2017
1 parent 2463015 commit 903ec0f
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions lib/fastlane/plugin/firebase/lib/manager.rb
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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

0 comments on commit 903ec0f

Please sign in to comment.