Class: Rebi::ConfigEnvironment

Inherits:
Object
  • Object
show all
Defined in:
lib/rebi/config_environment.rb

Constant Summary collapse

NAMESPACE =
{
  app_env: "aws:elasticbeanstalk:application:environment",
  eb_env: "aws:elasticbeanstalk:environment",
  autoscaling_launch: "aws:autoscaling:launchconfiguration",
  autoscaling_asg: "aws:autoscaling:asg",
  elb_policies: "aws:elb:policies",
  elb_health: "aws:elb:healthcheck",
  elb_loadbalancer: "aws:elb:loadbalancer",
  healthreporting: "aws:elasticbeanstalk:healthreporting:system",
  eb_command: "aws:elasticbeanstalk:command",
}
UPDATEABLE_NS =
{
  autoscaling_asg: [:MaxSize, :MinSize],
  autoscaling_launch: [:InstanceType, :EC2KeyName],
  eb_env: [:ServiceRole],
}
DEFAULT_IAM_INSTANCE_PROFILE =
"aws-elasticbeanstalk-ec2-role"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stage, env_name, env_conf = {}) ⇒ ConfigEnvironment

Returns a new instance of ConfigEnvironment.



45
46
47
48
49
# File 'lib/rebi/config_environment.rb', line 45

def initialize stage, env_name, env_conf={}
  @raw_conf = env_conf.with_indifferent_access
  @stage = stage.to_sym
  @env_name = env_name.to_sym
end

Instance Attribute Details

#cfg_fileObject (readonly)

Returns the value of attribute cfg_file.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def cfg_file
  @cfg_file
end

#cname_prefixObject (readonly)

Returns the value of attribute cname_prefix.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def cname_prefix
  @cname_prefix
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def description
  @description
end

#ebextensionsObject (readonly)

Returns the value of attribute ebextensions.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def ebextensions
  @ebextensions
end

#env_fileObject (readonly)

Returns the value of attribute env_file.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def env_file
  @env_file
end

#env_nameObject (readonly)

Returns the value of attribute env_name.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def env_name
  @env_name
end

#environment_variablesObject (readonly)

Returns the value of attribute environment_variables.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def environment_variables
  @environment_variables
end

#instance_numObject (readonly)

Returns the value of attribute instance_num.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def instance_num
  @instance_num
end

#instance_profileObject (readonly)

Returns the value of attribute instance_profile.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def instance_profile
  @instance_profile
end

#instance_typeObject (readonly)

Returns the value of attribute instance_type.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def instance_type
  @instance_type
end

#key_nameObject (readonly)

Returns the value of attribute key_name.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def key_name
  @key_name
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def name
  @name
end

#option_settingsObject (readonly)

Returns the value of attribute option_settings.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def option_settings
  @option_settings
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def options
  @options
end

#raw_confObject (readonly)

Returns the value of attribute raw_conf.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def raw_conf
  @raw_conf
end

#solution_stack_nameObject (readonly)

Returns the value of attribute solution_stack_name.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def solution_stack_name
  @solution_stack_name
end

#stageObject (readonly)

Returns the value of attribute stage.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def stage
  @stage
end

#tierObject (readonly)

Returns the value of attribute tier.



6
7
8
# File 'lib/rebi/config_environment.rb', line 6

def tier
  @tier
end

Instance Method Details

#app_nameObject



55
56
57
# File 'lib/rebi/config_environment.rb', line 55

def app_name
  Rebi.config.app_name
end

#cfgObject



138
139
140
141
142
143
144
145
# File 'lib/rebi/config_environment.rb', line 138

def cfg
  begin
    return nil if cfg_file.blank?
    return (@cfg ||= YAML.load(ERB.new(IO.read(cfg_file)).result).with_indifferent_access)
  rescue Errno::ENOENT
    raise Rebi::Error::ConfigInvalid.new("cfg_file: #{cfg_file}")
  end
end

#default_instance_profile?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/rebi/config_environment.rb', line 117

def default_instance_profile?
  self.instance_profile == DEFAULT_IAM_INSTANCE_PROFILE
end

#dotenvObject



169
170
171
# File 'lib/rebi/config_environment.rb', line 169

def dotenv
  env_file.present? ? Dotenv.load(env_file).with_indifferent_access : {}
end

#get_opt(namespace, opt_name = nil) ⇒ Object



177
178
179
# File 'lib/rebi/config_environment.rb', line 177

def get_opt namespace, opt_name=nil
  has_value_by_keys(option_settings, namespace, opt_name)
end

#get_raw_opt(namespace, opt_name = nil) ⇒ Object



181
182
183
# File 'lib/rebi/config_environment.rb', line 181

def get_raw_opt namespace, opt_name=nil
  has_value_by_keys(raw_conf[:option_settings], namespace, opt_name)
end

#ns(key = nil) ⇒ Object



221
222
223
# File 'lib/rebi/config_environment.rb', line 221

def ns key=nil
  key.present? ? NAMESPACE[key.to_sym] : NAMESPACE
end

#opts_array(opts = option_settings) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/rebi/config_environment.rb', line 185

def opts_array opts=option_settings
  res = []
  opts.each do |namespace, v|
    namespace, resource_name = namespace.split(".").reverse
    v.each do |option_name, value|
      res << {
        resource_name: resource_name,
        namespace: namespace,
        option_name: option_name,
        value: value.to_s,
      }.with_indifferent_access
    end
  end
  return res
end

#platform_arnObject



151
152
153
# File 'lib/rebi/config_environment.rb', line 151

def platform_arn
  cfg && cfg[:Platform] && cfg[:Platform][:PlatformArn]
end

#raw_environment_variablesObject



165
166
167
# File 'lib/rebi/config_environment.rb', line 165

def raw_environment_variables
  raw_conf[:environment_variables] || {}
end

#worker?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/rebi/config_environment.rb', line 94

def worker?
  tier[:name] == "Worker" ? true : false
end