Class: Automan::Beanstalk::Configuration
- Inherits:
-
Automan::Base
- Object
- Automan::Base
- Automan::Beanstalk::Configuration
- Includes:
- Mixins::Utils
- Defined in:
- lib/automan/beanstalk/configuration.rb
Constant Summary
Constants included from Mixins::AwsCaller
Instance Attribute Summary
Attributes inherited from Automan::Base
Attributes included from Mixins::AwsCaller
#as, #cfn, #eb, #ec, #ec2, #elb, #r53, #rds, #s3
Instance Method Summary collapse
- #config_template_exists? ⇒ Boolean
-
#configuration_options ⇒ Object
TODO: read options file (from local or s3) into array of hashes docs.aws.amazon.com/AWSRubySDK/latest/AWS/ElasticBeanstalk/Client/V20101201.html#create_configuration_template-instance_method.
- #create ⇒ Object
-
#create_config_template ⇒ Object
where are we getting configuration data?.
- #delete ⇒ Object
- #delete_config_template ⇒ Object
-
#fix_config_keys(config_array) ⇒ Object
config_option files are stored in json format compatible with elastic-beanstalk-create-configuration-template cli.
- #update ⇒ Object
Methods included from Mixins::Utils
Methods inherited from Automan::Base
add_option, #initialize, #log_options, #wait_until
Methods included from Mixins::AwsCaller
#account, #configure_aws, #looks_like_s3_path?, #parse_s3_path, #s3_object_exists?, #s3_read
Constructor Details
This class inherits a constructor from Automan::Base
Instance Method Details
#config_template_exists? ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/automan/beanstalk/configuration.rb', line 13 def config_template_exists? opts = { application_name: application, template_name: name } begin response = eb.describe_configuration_settings opts rescue AWS::ElasticBeanstalk::Errors::InvalidParameterValue => e if e..start_with? "No Configuration Template named" return false end end unless response.successful? raise RequestFailedError, "describe_configuration_settings failed: #{response.error}" end response.data[:configuration_settings].each do |settings| if settings[:application_name] == application && settings[:template_name] == name return true end end return false end |
#configuration_options ⇒ Object
TODO: read options file (from local or s3) into array of hashes docs.aws.amazon.com/AWSRubySDK/latest/AWS/ElasticBeanstalk/Client/V20101201.html#create_configuration_template-instance_method
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/automan/beanstalk/configuration.rb', line 72 def json_config = "" if looks_like_s3_path? template bucket, key = parse_s3_path template json_config = s3.buckets[bucket].objects[key].read else json_config = File.read template end config = JSON.parse json_config config = fix_config_keys config config end |
#create ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/automan/beanstalk/configuration.rb', line 104 def create if config_template_exists? logger.warn "Configuration template #{name} for #{application} already exists. Doing nothing." return end logger.info "Creating configuration template #{name} for #{application}." create_config_template end |
#create_config_template ⇒ Object
where are we getting configuration data?
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/automan/beanstalk/configuration.rb', line 89 def create_config_template opts = { application_name: application, template_name: name, solution_stack_name: platform, option_settings: } response = eb.create_configuration_template opts unless response.successful? raise RequestFailedError, "create_configuration_template failed: #{response.error}" end end |
#delete ⇒ Object
114 115 116 117 118 119 120 121 122 |
# File 'lib/automan/beanstalk/configuration.rb', line 114 def delete if !config_template_exists? logger.warn "Configuration #{name} for #{application} does not exist. Doing nothing." return end logger.info "Deleting configuration template #{name} for #{application}." delete_config_template end |
#delete_config_template ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/automan/beanstalk/configuration.rb', line 40 def delete_config_template opts = { application_name: application, template_name: name } response = eb.delete_configuration_template opts unless response.successful? raise RequestFailedError, "delete_configuration_template failed: #{response.error}" end end |
#fix_config_keys(config_array) ⇒ Object
config_option files are stored in json format compatible with elastic-beanstalk-create-configuration-template cli. The keys of each object are in json CamelCase. We need to convert them to ruby snake_case to work with aws-sdk
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/automan/beanstalk/configuration.rb', line 57 def fix_config_keys(config_array) result = [] config_array.each do |i| fixed_hash = {} i.each do |key, value| fixed_key = key.underscore fixed_hash[ fixed_key ] = value.to_s end result << fixed_hash end result end |
#update ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/automan/beanstalk/configuration.rb', line 124 def update if config_template_exists? logger.info "Configuration template #{name} for #{application} exists. Deleting it." delete_config_template end logger.info "Creating configuration template #{name} for #{application}" create_config_template end |