Commit 2a8d0b59 authored by Dylan Griffith's avatar Dylan Griffith

Auto DevOps QA: Prefer gcloud credentials from env

parent 00518d26
...@@ -58,6 +58,10 @@ module QA ...@@ -58,6 +58,10 @@ module QA
def gcloud_zone def gcloud_zone
ENV.fetch('GCLOUD_ZONE') ENV.fetch('GCLOUD_ZONE')
end end
def has_gcloud_credentials?
%w[GCLOUD_ACCOUNT_KEY GCLOUD_ACCOUNT_EMAIL].none? { |var| ENV[var].to_s.empty? }
end
end end
end end
end end
...@@ -50,13 +50,17 @@ module QA ...@@ -50,13 +50,17 @@ module QA
end end
def login_if_not_already_logged_in def login_if_not_already_logged_in
if Runtime::Env.has_gcloud_credentials?
attempt_login_with_env_vars
else
account = `gcloud auth list --filter=status:ACTIVE --format="value(account)"` account = `gcloud auth list --filter=status:ACTIVE --format="value(account)"`
if account.empty? if account.empty?
attempt_login_with_env_vars raise "Failed to login to gcloud. No credentials provided in environment and no credentials found locally."
else else
puts "gcloud account found. Using: #{account} for creating K8s cluster." puts "gcloud account found. Using: #{account} for creating K8s cluster."
end end
end end
end
def attempt_login_with_env_vars def attempt_login_with_env_vars
puts "No gcloud account. Attempting to login from env vars GCLOUD_ACCOUNT_EMAIL and GCLOUD_ACCOUNT_KEY." puts "No gcloud account. Attempting to login from env vars GCLOUD_ACCOUNT_EMAIL and GCLOUD_ACCOUNT_KEY."
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment