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

+ (Object) aws_access_key_id



43
44
45
46
# File 'lib/ec2/host/config.rb', line 43

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

+ (Object) aws_credential_file



53
54
55
56
57
# File 'lib/ec2/host/config.rb', line 53

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)
end

+ (Object) aws_profile



37
38
39
40
41
# File 'lib/ec2/host/config.rb', line 37

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

+ (Object) aws_region



31
32
33
34
35
# File 'lib/ec2/host/config.rb', line 31

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') # ref. aws cli and terraform
end

+ (Object) aws_secret_access_key



48
49
50
51
# File 'lib/ec2/host/config.rb', line 48

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

+ (Object) config_file



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

+ (Object) hostname_tag



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

def self.hostname_tag
  @hostname_tag ||= ENV['HOSTNAME_TAG'] || config.fetch('HOSTNAME_TAG', 'Name')
end

+ (Object) log_level



59
60
61
# File 'lib/ec2/host/config.rb', line 59

def self.log_level
  @log_level ||= ENV['LOG_LEVEL'] || config.fetch('LOG_LEVEL', 'info')
end

+ (Object) optional_array_tags



71
72
73
# File 'lib/ec2/host/config.rb', line 71

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

+ (Object) optional_string_tags



75
76
77
# File 'lib/ec2/host/config.rb', line 75

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

+ (Object) roles_tag



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

def self.roles_tag
  @roles_tag ||= ENV['ROLES_TAG'] || config.fetch('ROLES_TAG', 'Roles')
end

Class Method Details

+ (Object) array_tag_delimiter



83
84
85
# File 'lib/ec2/host/config.rb', line 83

def self.array_tag_delimiter
  @array_tag_delimiter ||= ENV['ARRAY_TAG_DELIMITER'] || config.fetch('ARRAY_TAG_DELIMITER', ',')
end

+ (Object) config



105
106
107
108
109
110
111
112
113
114
# File 'lib/ec2/host/config.rb', line 105

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

+ (Object) configure(params)



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

+ (Object) optional_array_options

private



89
90
91
92
93
# File 'lib/ec2/host/config.rb', line 89

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

+ (Object) optional_options



101
102
103
# File 'lib/ec2/host/config.rb', line 101

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

+ (Object) optional_string_options



95
96
97
98
99
# File 'lib/ec2/host/config.rb', line 95

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

+ (Object) role_tag_delimiter



79
80
81
# File 'lib/ec2/host/config.rb', line 79

def self.role_tag_delimiter
  @role_tag_delimiter ||= ENV['ROLE_TAG_DELIMITER'] || config.fetch('ROLE_TAG_DELIMITER', ':')
end