class GCE::Host::Config
Public Class Methods
application_default_credentials_file()
click to toggle source
# File lib/gce/host/config.rb, line 30 def self.application_default_credentials_file @application_default_credentials_file ||= File.expand_path("~/.config/gcloud/application_default_credentials.json") end
array_value_delimiter()
click to toggle source
# File lib/gce/host/config.rb, line 104 def self.array_value_delimiter @array_value_delimiter ||= ENV['ARRAY_VALUE_DELIMITER'] || config.fetch('ARRAY_VALUE_DELIMITER', ',') end
auth_method()
click to toggle source
# File lib/gce/host/config.rb, line 20 def self.auth_method @auth_method ||= ENV['AUTH_METHOD'] || config.fetch('AUTH_METHOD', nil) || credentials['type'] || 'compute_engine' end
config()
click to toggle source
# File lib/gce/host/config.rb, line 136 def self.config return @config if @config @config = {} if File.exist?(config_file) File.readlines(config_file).each do |line| next if line.start_with?('#') key, val = line.chomp.split('=', 2) @config[key] = val end end @config end
config_default()
click to toggle source
# File lib/gce/host/config.rb, line 46 def self.config_default # {'core'=>{'account'=>'xxx','project'=>'xxx'},'compute'=>{'zone'=>'xxx}} @config_default ||= File.readable?(config_default_file) ? IniFile.load(config_default_file).to_h : {} end
config_default_file()
click to toggle source
# File lib/gce/host/config.rb, line 42 def self.config_default_file File.expand_path('~/.config/gcloud/configurations/config_default') end
config_file()
click to toggle source
# File lib/gce/host/config.rb, line 16 def self.config_file @config_file ||= File.expand_path(ENV.fetch('GCE_HOST_CONFIG_FILE', File.exist?('/etc/sysconfig/gce-host') ? '/etc/sysconfig/gce-host' : '/etc/default/gce-host')) end
configure(params)
click to toggle source
# File lib/gce/host/config.rb, line 10 def self.configure(params) params.each do |key, val| send("#{key}=", val) end end
credentials()
click to toggle source
# File lib/gce/host/config.rb, line 38 def self.credentials File.readable?(credentials_file) ? JSON.parse(File.read(credentials_file)) : {} end
credentials_file()
click to toggle source
# File lib/gce/host/config.rb, line 24 def self.credentials_file # ref. https://developers.google.com/identity/protocols/application-default-credentials @credentials_file ||= File.expand_path(ENV['GOOGLE_APPLICATION_CREDENTIALS'] || config.fetch('GOOGLE_APPLICATION_CREDENTIALS', nil) || (File.exist?(global_application_default_credentials_file) ? global_application_default_credentials_file : application_default_credentials_file)) end
global_application_default_credentials_file()
click to toggle source
# File lib/gce/host/config.rb, line 34 def self.global_application_default_credentials_file @global_application_default_credentials_file ||= '/etc/google/auth/application_default_credentials.json' end
log_level()
click to toggle source
# File lib/gce/host/config.rb, line 61 def self.log_level @log_level ||= ENV['LOG_LEVEL'] || config.fetch('LOG_LEVEL', 'info') end
open_timeout_sec()
click to toggle source
# File lib/gce/host/config.rb, line 69 def self.open_timeout_sec @open_timeout_sec ||= ENV['OPEN_TIMEOUT_SEC'] || config.fetch('OPEN_TIMEOUT_SEC', 300) end
optional_array_keys()
click to toggle source
# File lib/gce/host/config.rb, line 92 def self.optional_array_keys @optional_array_keys ||= (ENV['OPTIONAL_ARRAY_KEYS'] || config.fetch('OPTIONAL_ARRAY_KEYS', '')).split(',') end
optional_array_options()
click to toggle source
private
# File lib/gce/host/config.rb, line 120 def self.optional_array_options @optional_array_options ||= Hash[optional_array_keys.map {|key| [StringUtil.singularize(StringUtil.underscore(key)), key] }] end
optional_options()
click to toggle source
# File lib/gce/host/config.rb, line 132 def self.optional_options @optional_options ||= optional_array_options.merge(optional_string_options) end
optional_string_keys()
click to toggle source
# File lib/gce/host/config.rb, line 96 def self.optional_string_keys @optional_string_keys ||= (ENV['OPTIONAL_STRING_KEYS'] || config.fetch('OPTIONAL_STRING_KEYS', '')).split(',') end
optional_string_options()
click to toggle source
# File lib/gce/host/config.rb, line 126 def self.optional_string_options @optional_string_options ||= Hash[optional_string_keys.map {|key| [StringUtil.underscore(key), key] }] end
project()
click to toggle source
# File lib/gce/host/config.rb, line 55 def self.project @project ||= ENV['GOOGLE_PROJECT'] || config.fetch('GOOGLE_PROJECT', nil) || credentials['project_id'] @project ||= credentials['client_email'].chomp('.iam.gserviceaccount.com').split('@').last if credentials['client_email'] @project ||= project_default || raise('project is not given, configure GOOGLE_PROJECT or run $ gcloud config set project PROJECT_NAME') end
project_default()
click to toggle source
# File lib/gce/host/config.rb, line 51 def self.project_default (config_default['core'] || {})['project'] end
read_timeout_sec()
click to toggle source
google-api-ruby-client >= v0.11.0
# File lib/gce/host/config.rb, line 84 def self.read_timeout_sec @read_timeout_sec ||= ENV['READ_TIMEOUT_SEC'] || config.fetch('READ_TIMEOUT_SEC', timeout_sec) end
retries()
click to toggle source
# File lib/gce/host/config.rb, line 65 def self.retries @retries ||= ENV['RETRIES'] || config.fetch('RETRIES', 5) end
role_max_depth()
click to toggle source
# File lib/gce/host/config.rb, line 114 def self.role_max_depth @role_max_depth ||= Integer(ENV['ROLE_MAX_DEPTH'] || config.fetch('ROLE_MAX_DEPTH', 3)) end
role_value_delimiter()
click to toggle source
# File lib/gce/host/config.rb, line 100 def self.role_value_delimiter @role_value_delimiter ||= ENV['ROLE_VALUE_DELIMITER'] || config.fetch('ROLE_VALUE_DELIMITER', ':') end
roles_key()
click to toggle source
# File lib/gce/host/config.rb, line 88 def self.roles_key @roles_key ||= ENV['ROLES_KEY'] || config.fetch('ROLES_KEY', 'roles') end
send_timeout_sec()
click to toggle source
google-api-ruby-client >= v0.11.0
# File lib/gce/host/config.rb, line 79 def self.send_timeout_sec @send_timeout_sec ||= ENV['SEND_TIMEOUT_SEC'] || config.fetch('SEND_TIMEOUT_SEC', 300) end
status()
click to toggle source
this makes configurable to change status to state to make compatible with AWS usually, users do not need to care of this
# File lib/gce/host/config.rb, line 110 def self.status @status ||= ENV['STATUS'] || config.fetch('STATUS', 'status') end
timeout_sec()
click to toggle source
google-api-ruby-client < v0.11.0
# File lib/gce/host/config.rb, line 74 def self.timeout_sec @timeout_sec ||= ENV['TIMEOUT_SEC'] || config.fetch('TIMEOUT_SEC', 300) end