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



146
147
148
149
150
151
152
153
# File 'lib/rebi/config_environment.rb', line 146

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)


121
122
123
# File 'lib/rebi/config_environment.rb', line 121

def default_instance_profile?
  self.instance_profile == DEFAULT_IAM_INSTANCE_PROFILE
end

#dockerrunObject



142
143
144
# File 'lib/rebi/config_environment.rb', line 142

def dockerrun
  raw_conf[:dockerrun]
end

#dotenvObject



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

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

#get_opt(namespace, opt_name = nil) ⇒ Object



185
186
187
# File 'lib/rebi/config_environment.rb', line 185

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



189
190
191
# File 'lib/rebi/config_environment.rb', line 189

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

#hooksObject



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/rebi/config_environment.rb', line 233

def hooks
  return @hooks if @hooks

  @hooks = {
    pre: [],
    post: [],
  }.with_indifferent_access

  [:pre, :post].each do |type|
    next unless h = raw_conf[:hooks] && raw_conf[:hooks][type]
    @hooks[type] = h.is_a?(Array) ? h : [h]
  end

  return @hooks
end

#ns(key = nil) ⇒ Object



229
230
231
# File 'lib/rebi/config_environment.rb', line 229

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

#opts_array(opts = option_settings) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/rebi/config_environment.rb', line 193

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



159
160
161
# File 'lib/rebi/config_environment.rb', line 159

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

#post_hooksObject



253
254
255
# File 'lib/rebi/config_environment.rb', line 253

def post_hooks
  hooks[:post]
end

#pre_hooksObject



249
250
251
# File 'lib/rebi/config_environment.rb', line 249

def pre_hooks
  hooks[:pre]
end

#raw_environment_variablesObject



173
174
175
# File 'lib/rebi/config_environment.rb', line 173

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

#web?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/rebi/config_environment.rb', line 98

def web?
  !worker?
end

#worker?Boolean

Returns:

  • (Boolean)


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

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