class EC2::Host::Config
Attributes
aws_access_key_id[W]
aws_credentials_file[W]
aws_profile[W]
aws_region[W]
aws_secret_access_key[W]
config_file[W]
hostname_tag[W]
log_level[W]
roles_tag[W]
Public Class Methods
array_tag_delimiter()
click to toggle source
# File lib/ec2/host/config.rb, line 107 def self.array_tag_delimiter @array_tag_delimiter ||= ENV['ARRAY_TAG_DELIMITER'] || config.fetch('ARRAY_TAG_DELIMITER', ',') end
aws_access_key_id()
click to toggle source
# 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_config()
click to toggle source
# File lib/ec2/host/config.rb, line 70 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()
click to toggle source
# File lib/ec2/host/config.rb, line 66 def self.aws_config_file @aws_config_file ||= ENV['AWS_CONFIG_FILE'] || config.fetch('AWS_CONFIG_FILE', nil) || File.expand_path('~/.aws/config') end
aws_credentials_file()
click to toggle source
# File lib/ec2/host/config.rb, line 55 def self.aws_credentials_file @aws_credentials_file ||= ENV['AWS_CREDENTIALS_FILE'] || config.fetch('AWS_CREDENTIALS_FILE', nil) || # old ENV['AWS_CREDENTIAL_FILE'] || config.fetch('AWS_CREDENTIAL_FILE', nil) || # old ENV['AWS_SHARED_CREDENTIALS_FILE'] || config.fetch('AWS_SHARED_CREDENTIALS_FILE', nil) || # ref. https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-configure-envvars.html File.expand_path('~/.aws/credentials') end
Also aliased as: aws_credential_file
aws_profile()
click to toggle source
# 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()
click to toggle source
# 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 nor region in ~/.aws/config is not set') end
aws_secret_access_key()
click to toggle source
# 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()
click to toggle source
# File lib/ec2/host/config.rb, line 133 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()
click to toggle source
# 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
configure(params)
click to toggle source
# File lib/ec2/host/config.rb, line 22 def self.configure(params) params.each do |key, val| send("#{key}=", val) end end
hostname_tag()
click to toggle source
# File lib/ec2/host/config.rb, line 87 def self.hostname_tag @hostname_tag ||= ENV['HOSTNAME_TAG'] || config.fetch('HOSTNAME_TAG', 'Name') end
log_level()
click to toggle source
# File lib/ec2/host/config.rb, line 83 def self.log_level @log_level ||= ENV['LOG_LEVEL'] || config.fetch('LOG_LEVEL', 'info') end
optional_array_options()
click to toggle source
private
# File lib/ec2/host/config.rb, line 117 def self.optional_array_options @optional_array_options ||= Hash[optional_array_tags.map {|tag| [StringUtil.singularize(StringUtil.underscore(tag)), tag] }] end
optional_options()
click to toggle source
# File lib/ec2/host/config.rb, line 129 def self.optional_options @optional_options ||= optional_array_options.merge(optional_string_options) end
optional_string_options()
click to toggle source
# File lib/ec2/host/config.rb, line 123 def self.optional_string_options @optional_string_options ||= Hash[optional_string_tags.map {|tag| [StringUtil.underscore(tag), tag] }] end
role_max_depth()
click to toggle source
# File lib/ec2/host/config.rb, line 111 def self.role_max_depth @role_max_depth ||= Integer(ENV['ROLE_MAX_DEPTH'] || config.fetch('ROLE_MAX_DEPTH', 3)) end
role_tag_delimiter()
click to toggle source
# File lib/ec2/host/config.rb, line 103 def self.role_tag_delimiter @role_tag_delimiter ||= ENV['ROLE_TAG_DELIMITER'] || config.fetch('ROLE_TAG_DELIMITER', ':') end
roles_tag()
click to toggle source
# File lib/ec2/host/config.rb, line 91 def self.roles_tag @roles_tag ||= ENV['ROLES_TAG'] || config.fetch('ROLES_TAG', 'Roles') end