Class: GCE::Host::Config
- Inherits:
-
Object
- Object
- GCE::Host::Config
- Defined in:
- lib/gce/host/config.rb
Class Method Summary collapse
- .array_value_delimiter ⇒ Object
- .auth_method ⇒ Object
- .config ⇒ Object
- .config_file ⇒ Object
- .configure(params) ⇒ Object
- .credential_file ⇒ Object
- .log_level ⇒ Object
- .open_timeout_sec ⇒ Object
- .optional_array_keys ⇒ Object
-
.optional_array_options ⇒ Object
private.
- .optional_options ⇒ Object
- .optional_string_keys ⇒ Object
- .optional_string_options ⇒ Object
- .project ⇒ Object
- .retries ⇒ Object
- .role_value_delimiter ⇒ Object
- .roles_key ⇒ Object
-
.status ⇒ Object
this makes configurable to change status to state to make compatible with AWS usually, users do not need to care of this.
- .timeout_sec ⇒ Object
Class Method Details
.array_value_delimiter ⇒ Object
67 68 69 |
# File 'lib/gce/host/config.rb', line 67 def self.array_value_delimiter @array_value_delimiter ||= ENV['ARRAY_VALUE_DELIMITER'] || config.fetch('ARRAY_VALUE_DELIMITER', ',') end |
.auth_method ⇒ Object
17 18 19 |
# File 'lib/gce/host/config.rb', line 17 def self.auth_method @auth_method ||= ENV['AUTH_METHOD'] || config.fetch('AUTH_METHOD', 'application_default') end |
.config ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/gce/host/config.rb', line 95 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_file ⇒ Object
13 14 15 |
# File 'lib/gce/host/config.rb', line 13 def self.config_file @config_file ||= ENV.fetch('GCE_HOST_CONFIG_FILE', '/etc/sysconfig/gce-host') end |
.configure(params) ⇒ Object
7 8 9 10 11 |
# File 'lib/gce/host/config.rb', line 7 def self.configure(params) params.each do |key, val| send("#{key}=", val) end end |
.credential_file ⇒ Object
21 22 23 |
# File 'lib/gce/host/config.rb', line 21 def self.credential_file @credential_file ||= ENV['GOOGLE_CREDENTIAL_FILE'] || config.fetch('GOOGLE_CREDENTIAL_FILE', nil) end |
.log_level ⇒ Object
35 36 37 |
# File 'lib/gce/host/config.rb', line 35 def self.log_level @log_level ||= ENV['LOG_LEVEL'] || config.fetch('LOG_LEVEL', 'info') end |
.open_timeout_sec ⇒ Object
47 48 49 |
# File 'lib/gce/host/config.rb', line 47 def self.open_timeout_sec @open_timeout_sec ||= ENV['OPEN_TIMEOUT_SEC'] || config.fetch('OPEN_TIMEOUT_SEC', 300) end |
.optional_array_keys ⇒ Object
55 56 57 |
# File 'lib/gce/host/config.rb', line 55 def self.optional_array_keys @optional_array_keys ||= (ENV['OPTIONAL_ARRAY_KEYS'] || config.fetch('OPTIONAL_ARRAY_KEYS', '')).split(',') end |
.optional_array_options ⇒ Object
private
79 80 81 82 83 |
# File 'lib/gce/host/config.rb', line 79 def self. @optional_array_options ||= Hash[optional_array_keys.map {|key| [StringUtil.singularize(StringUtil.underscore(key)), key] }] end |
.optional_options ⇒ Object
91 92 93 |
# File 'lib/gce/host/config.rb', line 91 def self. @optional_options ||= .merge() end |
.optional_string_keys ⇒ Object
59 60 61 |
# File 'lib/gce/host/config.rb', line 59 def self.optional_string_keys @optional_string_keys ||= (ENV['OPTIONAL_STRING_KEYS'] || config.fetch('OPTIONAL_STRING_KEYS', '')).split(',') end |
.optional_string_options ⇒ Object
85 86 87 88 89 |
# File 'lib/gce/host/config.rb', line 85 def self. @optional_string_options ||= Hash[optional_string_keys.map {|key| [StringUtil.underscore(key), key] }] end |
.project ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/gce/host/config.rb', line 25 def self.project return @project if @project # ref. terraform https://www.terraform.io/docs/providers/google/ @project ||= ENV['GOOGLE_PROJECT'] || config.fetch('GOOGLE_PROJECT', nil) if @project.nil? and credential_file and File.readable?(credential_file) @project ||= (JSON.parse(File.read(credential_file)) || {})['project_id'] end @project end |
.retries ⇒ Object
39 40 41 |
# File 'lib/gce/host/config.rb', line 39 def self.retries @retries ||= ENV['RETRIES'] || config.fetch('RETRIES', 5) end |
.role_value_delimiter ⇒ Object
63 64 65 |
# File 'lib/gce/host/config.rb', line 63 def self.role_value_delimiter @role_value_delimiter ||= ENV['ROLE_VALUE_DELIMITER'] || config.fetch('ROLE_VALUE_DELIMITER', ':') end |
.roles_key ⇒ Object
51 52 53 |
# File 'lib/gce/host/config.rb', line 51 def self.roles_key @roles_key ||= ENV['ROLES_KEY'] || config.fetch('ROLES_KEY', 'roles') end |
.status ⇒ Object
this makes configurable to change status to state to make compatible with AWS usually, users do not need to care of this
73 74 75 |
# File 'lib/gce/host/config.rb', line 73 def self.status @status ||= ENV['STATUS'] || config.fetch('STATUS', 'status') end |
.timeout_sec ⇒ Object
43 44 45 |
# File 'lib/gce/host/config.rb', line 43 def self.timeout_sec @timeout_sec ||= ENV['TIMEOUT_SEC'] || config.fetch('TIMEOUT_SEC', 300) end |