module GcpData

Constants

VERSION

Public Instance Methods

check_gcloud_installed!() click to toggle source
# File lib/gcp_data.rb, line 39
def check_gcloud_installed!
  installed = system("type gcloud > /dev/null 2>&1")
  return if installed
  raise Error.new("ERROR: gcloud is not installed. Please install the gcloud command.")
end
credentials() click to toggle source
# File lib/gcp_data.rb, line 27
def credentials
  path = ENV['GOOGLE_APPLICATION_CREDENTIALS']
  JSON.load(IO.read(path)) if path && File.exist?(path)
end
creds(name) click to toggle source
# File lib/gcp_data.rb, line 23
def creds(name)
  credentials[name] if credentials
end
gcloud_config(key) click to toggle source
# File lib/gcp_data.rb, line 33
def gcloud_config(key)
  check_gcloud_installed!
  val = `gcloud config get-value #{key}`.strip
  val unless val == ''
end
project() click to toggle source
# File lib/gcp_data.rb, line 8
def project
  ENV['GOOGLE_PROJECT'] || creds("project_id") || gcloud_config("core/project") || raise("Unable to look up google project_id")
end
region() click to toggle source
# File lib/gcp_data.rb, line 13
def region
  ENV['GOOGLE_REGION'] || gcloud_config("compute/region") || 'us-central1'
end
zone() click to toggle source
# File lib/gcp_data.rb, line 18
def zone
  ENV['GOOGLE_ZONE'] || gcloud_config("compute/zone") || 'us-central1a'
end