Class: EC2::Host::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2/host/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.aws_access_key_idObject



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_fileObject

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_profileObject



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_regionObject



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_keyObject



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_fileObject



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_tagObject



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_levelObject



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_tagsObject



64
65
66
# File 'lib/ec2/host/config.rb', line 64

def self.optional_array_tags
  @optional_array_tags ||= (ENV['OPTIONAL_ARRAY_TAGS'] || config.fetch('OPTIONAL_ARRAY_TAGS', '')).split(',')
end

.optional_string_tagsObject



68
69
70
# File 'lib/ec2/host/config.rb', line 68

def self.optional_string_tags
  @optional_string_tags ||= (ENV['OPTIONAL_STRING_TAGS'] || config.fetch('OPTIONAL_STRING_TAGS', '')).split(',')
end

.roles_tagObject



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_delimiterObject



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_credentialsObject

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

.configObject



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_optionsObject



91
92
93
94
95
# File 'lib/ec2/host/config.rb', line 91

def self.optional_array_options
  @optional_array_options ||= Hash[optional_array_tags.map {|tag|
    [StringUtil.singularize(StringUtil.underscore(tag)), tag]
  }]
end

.optional_optionsObject



103
104
105
# File 'lib/ec2/host/config.rb', line 103

def self.optional_options
  @optional_options ||= optional_array_options.merge(optional_string_options)
end

.optional_string_optionsObject



97
98
99
100
101
# File 'lib/ec2/host/config.rb', line 97

def self.optional_string_options
  @optional_string_options ||= Hash[optional_string_tags.map {|tag|
    [StringUtil.underscore(tag), tag]
  }]
end

.role_tag_delimiterObject



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