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_credentials_file ⇒ Object
this is not an official aws sdk environment variable.
- .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_credentials ⇒ Object
private.
- .config ⇒ Object
- .configure(params) ⇒ Object
- .optional_array_options ⇒ Object
- .optional_options ⇒ Object
- .optional_string_options ⇒ Object
- .role_tag_delimiter ⇒ Object
Class Attribute Details
.aws_access_key_id ⇒ Object
39 40 41 |
# File 'lib/ec2/host/config.rb', line 39 def self.aws_access_key_id @aws_access_key_id ||= ENV['AWS_ACCESS_KEY_ID'] || config.fetch('AWS_ACCESS_KEY_ID', nil) end |
.aws_credentials_file ⇒ Object
this is not an official aws sdk environment variable
48 49 50 |
# File 'lib/ec2/host/config.rb', line 48 def self.aws_credentials_file @aws_credentials_file ||= ENV['AWS_CREDENTIALS_FILE'] || config.fetch('AWS_CREDENTIALS_FILE', nil) end |
.aws_profile ⇒ Object
35 36 37 |
# File 'lib/ec2/host/config.rb', line 35 def self.aws_profile @aws_profile ||= ENV['AWS_PROFILE'] || config.fetch('AWS_PROFILE', 'default') end |
.aws_region ⇒ Object
31 32 33 |
# File 'lib/ec2/host/config.rb', line 31 def self.aws_region @aws_region ||= ENV['AWS_REGION'] || config.fetch('AWS_REGION') end |
.aws_secret_access_key ⇒ Object
43 44 45 |
# File 'lib/ec2/host/config.rb', line 43 def self.aws_secret_access_key @aws_secret_access_key ||= ENV['AWS_SECRET_ACCESS_KEY'] || config.fetch('AWS_SECRET_ACCESS_KEY', nil) end |
.config_file ⇒ Object
27 28 29 |
# File 'lib/ec2/host/config.rb', line 27 def self.config_file @config_file ||= ENV.fetch('EC2_HOST_CONFIG_FILE', '/etc/sysconfig/ec2-host') end |
.hostname_tag ⇒ Object
56 57 58 |
# File 'lib/ec2/host/config.rb', line 56 def self.hostname_tag @hostname_tag ||= ENV['HOSTNAME_TAG'] || config.fetch('HOSTNAME_TAG', 'Name') end |
.log_level ⇒ Object
52 53 54 |
# File 'lib/ec2/host/config.rb', line 52 def self.log_level @log_level ||= ENV['LOG_LEVEL'] || config.fetch('LOG_LEVEL', 'info') end |
.optional_array_tags ⇒ Object
64 65 66 |
# File 'lib/ec2/host/config.rb', line 64 def self. @optional_array_tags ||= (ENV['OPTIONAL_ARRAY_TAGS'] || config.fetch('OPTIONAL_ARRAY_TAGS', '')).split(',') end |
.optional_string_tags ⇒ Object
68 69 70 |
# File 'lib/ec2/host/config.rb', line 68 def self. @optional_string_tags ||= (ENV['OPTIONAL_STRING_TAGS'] || config.fetch('OPTIONAL_STRING_TAGS', '')).split(',') end |
.roles_tag ⇒ Object
60 61 62 |
# File 'lib/ec2/host/config.rb', line 60 def self.roles_tag @roles_tag ||= ENV['ROLES_TAG'] || config.fetch('ROLES_TAG', 'Roles') end |
Class Method Details
.array_tag_delimiter ⇒ Object
76 77 78 |
# File 'lib/ec2/host/config.rb', line 76 def self.array_tag_delimiter @array_tag_delimiter ||= ENV['ARRAY_TAG_DELIMITER'] || config.fetch('ARRAY_TAG_DELIMITER', ',') end |
.aws_credentials ⇒ Object
private
82 83 84 85 86 87 88 89 |
# File 'lib/ec2/host/config.rb', line 82 def self.aws_credentials @aws_credentials ||= if aws_access_key_id and aws_secret_access_key Aws::Credentials.new(aws_access_key_id, aws_secret_access_key) else Aws::SharedCredentials.new(profile_name: aws_profile, path: aws_credentials_file) end end |
.config ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ec2/host/config.rb', line 107 def self.config return @config if @config @config = {} File.readlines(config_file).each do |line| next if line.start_with?('#') key, val = line.chomp.split('=', 2) @config[key] = val end @config end |
.configure(params) ⇒ Object
21 22 23 24 25 |
# File 'lib/ec2/host/config.rb', line 21 def self.configure(params) params.each do |key, val| send("#{key}=", val) end end |
.optional_array_options ⇒ Object
91 92 93 94 95 |
# File 'lib/ec2/host/config.rb', line 91 def self. @optional_array_options ||= Hash[.map {|tag| [StringUtil.singularize(StringUtil.underscore(tag)), tag] }] end |
.optional_options ⇒ Object
103 104 105 |
# File 'lib/ec2/host/config.rb', line 103 def self. @optional_options ||= .merge() end |
.optional_string_options ⇒ Object
97 98 99 100 101 |
# File 'lib/ec2/host/config.rb', line 97 def self. @optional_string_options ||= Hash[.map {|tag| [StringUtil.underscore(tag), tag] }] end |
.role_tag_delimiter ⇒ Object
72 73 74 |
# File 'lib/ec2/host/config.rb', line 72 def self.role_tag_delimiter @role_tag_delimiter ||= ENV['ROLE_TAG_DELIMITER'] || config.fetch('ROLE_TAG_DELIMITER', ':') end |