Class: Rebi::ConfigEnvironment
- Inherits:
-
Object
- Object
- Rebi::ConfigEnvironment
- 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
-
#cfg_file ⇒ Object
readonly
Returns the value of attribute cfg_file.
-
#cname_prefix ⇒ Object
readonly
Returns the value of attribute cname_prefix.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#ebextensions ⇒ Object
readonly
Returns the value of attribute ebextensions.
-
#env_file ⇒ Object
readonly
Returns the value of attribute env_file.
-
#env_name ⇒ Object
readonly
Returns the value of attribute env_name.
-
#environment_variables ⇒ Object
readonly
Returns the value of attribute environment_variables.
-
#instance_num ⇒ Object
readonly
Returns the value of attribute instance_num.
-
#instance_profile ⇒ Object
readonly
Returns the value of attribute instance_profile.
-
#instance_type ⇒ Object
readonly
Returns the value of attribute instance_type.
-
#key_name ⇒ Object
readonly
Returns the value of attribute key_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#option_settings ⇒ Object
readonly
Returns the value of attribute option_settings.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#raw_conf ⇒ Object
readonly
Returns the value of attribute raw_conf.
-
#solution_stack_name ⇒ Object
readonly
Returns the value of attribute solution_stack_name.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
-
#tier ⇒ Object
readonly
Returns the value of attribute tier.
Instance Method Summary collapse
- #app_name ⇒ Object
- #cfg ⇒ Object
- #default_instance_profile? ⇒ Boolean
- #dockerrun ⇒ Object
- #dotenv ⇒ Object
- #get_opt(namespace, opt_name = nil) ⇒ Object
- #get_raw_opt(namespace, opt_name = nil) ⇒ Object
- #hooks ⇒ Object
-
#initialize(stage, env_name, env_conf = {}) ⇒ ConfigEnvironment
constructor
A new instance of ConfigEnvironment.
- #ns(key = nil) ⇒ Object
- #opts_array(opts = option_settings) ⇒ Object
- #platform_arn ⇒ Object
- #post_hooks ⇒ Object
- #pre_hooks ⇒ Object
- #raw_environment_variables ⇒ Object
- #web? ⇒ Boolean
- #worker? ⇒ Boolean
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_file ⇒ Object (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_prefix ⇒ Object (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 |
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/rebi/config_environment.rb', line 6 def description @description end |
#ebextensions ⇒ Object (readonly)
Returns the value of attribute ebextensions.
6 7 8 |
# File 'lib/rebi/config_environment.rb', line 6 def ebextensions @ebextensions end |
#env_file ⇒ Object (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_name ⇒ Object (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_variables ⇒ Object (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_num ⇒ Object (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_profile ⇒ Object (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_type ⇒ Object (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_name ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rebi/config_environment.rb', line 6 def name @name end |
#option_settings ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/rebi/config_environment.rb', line 6 def @options end |
#raw_conf ⇒ Object (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_name ⇒ Object (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 |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
6 7 8 |
# File 'lib/rebi/config_environment.rb', line 6 def stage @stage end |
#tier ⇒ Object (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_name ⇒ Object
55 56 57 |
# File 'lib/rebi/config_environment.rb', line 55 def app_name Rebi.config.app_name end |
#cfg ⇒ Object
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
121 122 123 |
# File 'lib/rebi/config_environment.rb', line 121 def default_instance_profile? self.instance_profile == DEFAULT_IAM_INSTANCE_PROFILE end |
#dockerrun ⇒ Object
142 143 144 |
# File 'lib/rebi/config_environment.rb', line 142 def dockerrun raw_conf[:dockerrun] end |
#dotenv ⇒ Object
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 |
#hooks ⇒ Object
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_arn ⇒ Object
159 160 161 |
# File 'lib/rebi/config_environment.rb', line 159 def platform_arn cfg && cfg[:Platform] && cfg[:Platform][:PlatformArn] end |
#post_hooks ⇒ Object
253 254 255 |
# File 'lib/rebi/config_environment.rb', line 253 def post_hooks hooks[:post] end |
#pre_hooks ⇒ Object
249 250 251 |
# File 'lib/rebi/config_environment.rb', line 249 def pre_hooks hooks[:pre] end |
#raw_environment_variables ⇒ Object
173 174 175 |
# File 'lib/rebi/config_environment.rb', line 173 def raw_environment_variables raw_conf[:environment_variables] || {} end |
#web? ⇒ Boolean
98 99 100 |
# File 'lib/rebi/config_environment.rb', line 98 def web? !worker? end |
#worker? ⇒ Boolean
94 95 96 |
# File 'lib/rebi/config_environment.rb', line 94 def worker? tier[:name] == "Worker" ? true : false end |