Class: EC2::Host::Config
- Inherits:
-
Object
- Object
- EC2::Host::Config
- Defined in:
- lib/ec2/host/config.rb
Class Attribute Summary collapse
- .aws_access_key_id ⇒ Object
- .aws_credential_file ⇒ Object
- .aws_profile ⇒ Object
- .aws_region ⇒ Object
- .aws_secret_access_key ⇒ Object
- .config_file ⇒ Object
- .hostname_tag ⇒ Object
- .log_level ⇒ Object
- .optional_array_tags ⇒ Object
- .optional_string_tags ⇒ Object
- .roles_tag ⇒ Object
Class Method Summary collapse
- .array_tag_delimiter ⇒ Object
- .aws_config ⇒ Object
- .aws_config_file ⇒ Object
- .config ⇒ Object
- .configure(params) ⇒ Object
-
.optional_array_options ⇒ Object
private.
- .optional_options ⇒ Object
- .optional_string_options ⇒ Object
- .role_max_depth ⇒ Object
- .role_tag_delimiter ⇒ Object
Class Attribute Details
.aws_access_key_id ⇒ Object
45 46 47 48 |
# File 'lib/ec2/host/config.rb', line 45 def self.aws_access_key_id # ref. aws cli and terraform @aws_access_key_id ||= ENV['AWS_ACCESS_KEY_ID'] || config.fetch('AWS_ACCESS_KEY_ID', nil) end |
.aws_credential_file ⇒ Object
55 56 57 58 59 60 |
# File 'lib/ec2/host/config.rb', line 55 def self.aws_credential_file @aws_credential_file ||= ENV['AWS_CREDENTIALS_FILE'] || config.fetch('AWS_CREDENTIALS_FILE', nil) || ENV['AWS_CREDENTIAL_FILE'] || config.fetch('AWS_CREDENTIAL_FILE', nil) || # ref. aws cli (supported lately) File.('~/.aws/credentials') end |
.aws_profile ⇒ Object
39 40 41 42 43 |
# File 'lib/ec2/host/config.rb', line 39 def self.aws_profile @aws_profile ||= ENV['AWS_PROFILE'] || config.fetch('AWS_PROFILE', nil) || # ref. old aws cli ENV['AWS_DEFAULT_PROFILE'] || config.fetch('AWS_DEFAULT_PROFILE', 'default') # ref. aws cli and terraform end |
.aws_region ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ec2/host/config.rb', line 32 def self.aws_region @aws_region ||= ENV['AWS_REGION'] || config.fetch('AWS_REGION', nil) || # ref. old aws cli ENV['AWS_DEFAULT_REGION'] || config.fetch('AWS_DEFAULT_REGION', nil) || # ref. aws cli and terraform aws_config['region'] || raise('AWS_REGION nor AWS_DEFAULT_REGION is not set') end |
.aws_secret_access_key ⇒ Object
50 51 52 53 |
# File 'lib/ec2/host/config.rb', line 50 def self.aws_secret_access_key # ref. aws cli and terraform @aws_secret_access_key ||= ENV['AWS_SECRET_ACCESS_KEY'] || config.fetch('AWS_SECRET_ACCESS_KEY', nil) end |
.config_file ⇒ Object
28 29 30 |
# File 'lib/ec2/host/config.rb', line 28 def self.config_file @config_file ||= ENV.fetch('EC2_HOST_CONFIG_FILE', File.exist?('/etc/sysconfig/ec2-host') ? '/etc/sysconfig/ec2-host' : '/etc/default/ec2-host') end |
.hostname_tag ⇒ Object
83 84 85 |
# File 'lib/ec2/host/config.rb', line 83 def self.hostname_tag @hostname_tag ||= ENV['HOSTNAME_TAG'] || config.fetch('HOSTNAME_TAG', 'Name') end |
.log_level ⇒ Object
79 80 81 |
# File 'lib/ec2/host/config.rb', line 79 def self.log_level @log_level ||= ENV['LOG_LEVEL'] || config.fetch('LOG_LEVEL', 'info') end |
.optional_array_tags ⇒ Object
91 92 93 |
# File 'lib/ec2/host/config.rb', line 91 def self. @optional_array_tags ||= (ENV['OPTIONAL_ARRAY_TAGS'] || config.fetch('OPTIONAL_ARRAY_TAGS', '')).split(',') end |
.optional_string_tags ⇒ Object
95 96 97 |
# File 'lib/ec2/host/config.rb', line 95 def self. @optional_string_tags ||= (ENV['OPTIONAL_STRING_TAGS'] || config.fetch('OPTIONAL_STRING_TAGS', '')).split(',') end |
.roles_tag ⇒ Object
87 88 89 |
# File 'lib/ec2/host/config.rb', line 87 def self.roles_tag @roles_tag ||= ENV['ROLES_TAG'] || config.fetch('ROLES_TAG', 'Roles') end |
Class Method Details
.array_tag_delimiter ⇒ Object
103 104 105 |
# File 'lib/ec2/host/config.rb', line 103 def self.array_tag_delimiter @array_tag_delimiter ||= ENV['ARRAY_TAG_DELIMITER'] || config.fetch('ARRAY_TAG_DELIMITER', ',') end |
.aws_config ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ec2/host/config.rb', line 66 def self.aws_config return @aws_config if @aws_config if File.readable?(aws_config_file) ini = IniFile.load(aws_config_file).to_h if aws_profile == 'default' @aws_config = ini['default'] else @aws_config = ini["profile #{aws_profile}"] end end @aws_config ||= {} end |
.aws_config_file ⇒ Object
62 63 64 |
# File 'lib/ec2/host/config.rb', line 62 def self.aws_config_file @aws_config_file ||= ENV['AWS_CONFIG_FILE'] || config.fetch('AWS_CONFIG_FILE', nil) || File.('~/.aws/config') end |
.config ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ec2/host/config.rb', line 129 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 |
.configure(params) ⇒ Object
22 23 24 25 26 |
# File 'lib/ec2/host/config.rb', line 22 def self.configure(params) params.each do |key, val| send("#{key}=", val) end end |
.optional_array_options ⇒ Object
private
113 114 115 116 117 |
# File 'lib/ec2/host/config.rb', line 113 def self. @optional_array_options ||= Hash[.map {|tag| [StringUtil.singularize(StringUtil.underscore(tag)), tag] }] end |
.optional_options ⇒ Object
125 126 127 |
# File 'lib/ec2/host/config.rb', line 125 def self. @optional_options ||= .merge() end |
.optional_string_options ⇒ Object
119 120 121 122 123 |
# File 'lib/ec2/host/config.rb', line 119 def self. @optional_string_options ||= Hash[.map {|tag| [StringUtil.underscore(tag), tag] }] end |
.role_max_depth ⇒ Object
107 108 109 |
# File 'lib/ec2/host/config.rb', line 107 def self.role_max_depth @role_max_depth ||= Integer(ENV['ROLE_MAX_DEPTH'] || config.fetch('ROLE_MAX_DEPTH', 3)) end |
.role_tag_delimiter ⇒ Object
99 100 101 |
# File 'lib/ec2/host/config.rb', line 99 def self.role_tag_delimiter @role_tag_delimiter ||= ENV['ROLE_TAG_DELIMITER'] || config.fetch('ROLE_TAG_DELIMITER', ':') end |