humidifier 2.15.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CloudFormationResourceSpecification.json +24305 -18109
  3. data/LICENSE +1 -1
  4. data/README.md +55 -33
  5. data/lib/humidifier/condition.rb +0 -2
  6. data/lib/humidifier/config.rb +46 -0
  7. data/lib/humidifier/fn.rb +7 -8
  8. data/lib/humidifier/loader.rb +37 -45
  9. data/lib/humidifier/mapping.rb +0 -2
  10. data/lib/humidifier/output.rb +4 -6
  11. data/lib/humidifier/parameter.rb +9 -10
  12. data/lib/humidifier/props.rb +177 -2
  13. data/lib/humidifier/resource.rb +13 -14
  14. data/lib/humidifier/stack.rb +166 -21
  15. data/lib/humidifier/version.rb +1 -1
  16. data/lib/humidifier.rb +31 -24
  17. metadata +67 -31
  18. data/lib/humidifier/aws_adapters/base.rb +0 -67
  19. data/lib/humidifier/aws_adapters/noop.rb +0 -25
  20. data/lib/humidifier/aws_adapters/sdkv1.rb +0 -75
  21. data/lib/humidifier/aws_adapters/sdkv2.rb +0 -61
  22. data/lib/humidifier/aws_adapters/sdkv3.rb +0 -31
  23. data/lib/humidifier/aws_shim.rb +0 -83
  24. data/lib/humidifier/configuration.rb +0 -69
  25. data/lib/humidifier/props/base.rb +0 -47
  26. data/lib/humidifier/props/boolean_prop.rb +0 -25
  27. data/lib/humidifier/props/double_prop.rb +0 -23
  28. data/lib/humidifier/props/integer_prop.rb +0 -23
  29. data/lib/humidifier/props/json_prop.rb +0 -31
  30. data/lib/humidifier/props/list_prop.rb +0 -42
  31. data/lib/humidifier/props/map_prop.rb +0 -46
  32. data/lib/humidifier/props/string_prop.rb +0 -23
  33. data/lib/humidifier/props/structure_prop.rb +0 -71
  34. data/lib/humidifier/props/timestamp_prop.rb +0 -23
  35. data/lib/humidifier/sdk_payload.rb +0 -122
  36. data/lib/humidifier/sleeper.rb +0 -25
  37. data/lib/humidifier/utils.rb +0 -19
@@ -5,14 +5,16 @@ module Humidifier
5
5
  class Resource
6
6
  # Attributes that are available to every stack
7
7
  COMMON_ATTRIBUTES =
8
- Utils.underscored(%w[Condition CreationPolicy DeletionPolicy DependsOn
9
- Metadata UpdatePolicy])
8
+ Humidifier.underscore(
9
+ %w[Condition CreationPolicy DeletionPolicy DependsOn Metadata
10
+ UpdatePolicy]
11
+ )
10
12
 
11
13
  attr_accessor :properties, *COMMON_ATTRIBUTES.values
12
14
 
13
- def initialize(properties = {}, raw = false)
15
+ def initialize(properties = {})
14
16
  self.properties = {}
15
- update(properties, raw)
17
+ update(properties)
16
18
  end
17
19
 
18
20
  # Patches method_missing to include property accessors
@@ -49,9 +51,9 @@ module Humidifier
49
51
  end
50
52
 
51
53
  # Update a set of properties defined by the given properties hash
52
- def update(properties, raw = false)
54
+ def update(properties)
53
55
  properties.each do |property, value|
54
- update_property(property, value, raw)
56
+ update_property(property, value)
55
57
  end
56
58
  end
57
59
 
@@ -67,10 +69,10 @@ module Humidifier
67
69
  end
68
70
 
69
71
  # Update an individual property on this resource
70
- def update_property(property, value, raw = false)
72
+ def update_property(property, value)
71
73
  property = property.to_s
72
- property = validate_property(property, raw)
73
- value = validate_value(property, value, raw)
74
+ property = validate_property(property)
75
+ value = validate_value(property, value)
74
76
  properties[property] = value
75
77
  end
76
78
 
@@ -110,9 +112,7 @@ module Humidifier
110
112
  (self.class.props.keys & [method.to_s, method.to_s[0..-2]]).any?
111
113
  end
112
114
 
113
- def validate_property(property, raw)
114
- property = Utils.underscore(property) if raw
115
-
115
+ def validate_property(property)
116
116
  unless self.class.prop?(property)
117
117
  raise ArgumentError, 'Attempting to set invalid property for ' \
118
118
  "#{self.class.name}: #{property}"
@@ -121,9 +121,8 @@ module Humidifier
121
121
  property
122
122
  end
123
123
 
124
- def validate_value(property, value, raw)
124
+ def validate_value(property, value)
125
125
  prop = self.class.props[property]
126
- value = prop.convert(value) if raw
127
126
 
128
127
  unless prop.valid?(value)
129
128
  raise ArgumentError, "Invalid value for #{property}: #{value.inspect}"
@@ -3,16 +3,45 @@
3
3
  module Humidifier
4
4
  # Represents a CFN stack
5
5
  class Stack
6
- # Single settings on the stack
7
- STATIC_RESOURCES =
8
- Utils.underscored(%w[AWSTemplateFormatVersion Description Metadata])
6
+ class TemplateTooLargeError < StandardError
7
+ def initialize(bytesize)
8
+ super(
9
+ "Cannot use a template > #{MAX_TEMPLATE_URL_SIZE} bytes " \
10
+ "(currently #{bytesize} bytes), consider using nested stacks " \
11
+ '(http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide' \
12
+ '/aws-properties-stack.html)'
13
+ )
14
+ end
15
+ end
16
+
17
+ # The AWS region, can be set through the environment, defaults to us-east-1
18
+ AWS_REGION = ENV['AWS_REGION'] || 'us-east-1'
9
19
 
10
20
  # Lists of objects linked to the stack
11
21
  ENUMERABLE_RESOURCES =
12
- Utils.underscored(%w[Conditions Mappings Outputs Parameters Resources])
22
+ Humidifier.underscore(
23
+ %w[Conditions Mappings Outputs Parameters Resources]
24
+ )
25
+
26
+ # The maximum size a template body can be before it has to be put somewhere
27
+ # and referenced through a URL
28
+ MAX_TEMPLATE_BODY_SIZE = 51_200
29
+
30
+ # The maximum size a template body can be inside of an S3 bucket
31
+ MAX_TEMPLATE_URL_SIZE = 460_800
32
+
33
+ # The maximum amount of time that Humidifier should wait for a stack to
34
+ # complete a CRUD operation
35
+ MAX_WAIT = 600
36
+
37
+ # Single settings on the stack
38
+ STATIC_RESOURCES =
39
+ Humidifier.underscore(%w[AWSTemplateFormatVersion Description Metadata])
13
40
 
14
41
  attr_accessor :id
15
- attr_reader(:name, *ENUMERABLE_RESOURCES.values, *STATIC_RESOURCES.values)
42
+ attr_writer :client
43
+
44
+ attr_reader :name, *ENUMERABLE_RESOURCES.values, *STATIC_RESOURCES.values
16
45
 
17
46
  def initialize(opts = {})
18
47
  @name = opts[:name]
@@ -28,22 +57,38 @@ module Humidifier
28
57
  end
29
58
  end
30
59
 
31
- # Add a resource to the stack and optionally set its attributes
32
60
  def add(name, resource, attributes = {})
33
61
  resources[name] = resource
34
62
  resource.update_attributes(attributes) if attributes.any?
35
63
  resource
36
64
  end
37
65
 
38
- # The identifier used by the shim to find the stack in CFN, prefers id to
39
- # name
66
+ def add_condition(name, opts = {})
67
+ conditions[name] = Condition.new(opts)
68
+ end
69
+
70
+ def add_mapping(name, opts = {})
71
+ mappings[name] = Mapping.new(opts)
72
+ end
73
+
74
+ def add_output(name, opts = {})
75
+ outputs[name] = Output.new(opts)
76
+ end
77
+
78
+ def add_parameter(name, opts = {})
79
+ parameters[name] = Parameter.new(opts)
80
+ end
81
+
82
+ def client
83
+ @client ||= Aws::CloudFormation::Client.new(region: AWS_REGION)
84
+ end
85
+
40
86
  def identifier
41
87
  id || name || default_identifier
42
88
  end
43
89
 
44
- # A string representation of the stack that's valid for CFN
45
90
  def to_cf(serializer = :json)
46
- resources = static_resources.merge(enumerable_resources)
91
+ resources = static_resources.merge!(enumerable_resources)
47
92
 
48
93
  case serializer
49
94
  when :json then JSON.pretty_generate(resources)
@@ -51,20 +96,75 @@ module Humidifier
51
96
  end
52
97
  end
53
98
 
54
- %i[condition mapping output parameter].each do |resource_type|
55
- define_method(:"add_#{resource_type}") do |name, opts = {}|
56
- send(:"#{resource_type}s")[name] =
57
- Humidifier.const_get(resource_type.capitalize).new(opts)
99
+ def create(opts = {})
100
+ params = { stack_name: name }.merge!(template_for(opts)).merge!(opts)
101
+
102
+ try_valid do
103
+ client.create_stack(params).tap { |response| @id = response.stack_id }
58
104
  end
59
105
  end
60
106
 
61
- AwsShim::STACK_METHODS.each do |method|
62
- define_method(method) do |opts = {}|
63
- AwsShim.send(method, SdkPayload.new(self, opts))
64
- end
107
+ def create_and_wait(opts = {})
108
+ perform_and_wait(:create, opts)
109
+ end
110
+
111
+ def create_change_set(opts = {})
112
+ params = {
113
+ stack_name: identifier,
114
+ change_set_name: "changeset-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
115
+ }
116
+ params.merge!(template_for(opts)).merge!(opts)
117
+
118
+ try_valid { client.create_change_set(params) }
119
+ end
120
+
121
+ def delete(opts = {})
122
+ client.delete_stack({ stack_name: identifier }.merge!(opts))
123
+ true
124
+ end
125
+
126
+ def delete_and_wait(opts = {})
127
+ perform_and_wait(:delete, opts)
128
+ end
129
+
130
+ def deploy(opts = {})
131
+ exists? ? update(opts) : create(opts)
132
+ end
133
+
134
+ def deploy_and_wait(opts = {})
135
+ perform_and_wait(exists? ? :update : :create, opts)
136
+ end
137
+
138
+ def deploy_change_set(opts = {})
139
+ exists? ? create_change_set(opts) : create(opts)
140
+ end
141
+
142
+ def exists?
143
+ Aws::CloudFormation::Stack.new(name: identifier).exists?
144
+ end
145
+
146
+ def update(opts = {})
147
+ params =
148
+ { stack_name: identifier }.merge!(template_for(opts)).merge!(opts)
149
+
150
+ try_valid { client.update_stack(params) }
151
+ end
152
+
153
+ def update_and_wait(opts = {})
154
+ perform_and_wait(:update, opts)
155
+ end
156
+
157
+ def upload
158
+ Humidifier.config.ensure_upload_configured!(identifier)
159
+ upload_object("#{Humidifier.config.s3_prefix}#{identifier}.json")
160
+ end
161
+
162
+ def valid?(opts = {})
163
+ params = template_for(opts).merge!(opts)
164
+
165
+ try_valid { client.validate_template(params) }
65
166
  end
66
167
 
67
- # Increment the default identifier
68
168
  def self.next_default_identifier
69
169
  @count ||= 0
70
170
  @count += 1
@@ -75,9 +175,36 @@ module Humidifier
75
175
 
76
176
  attr_reader :default_identifier
77
177
 
178
+ def perform_and_wait(method, opts)
179
+ public_send(method, opts).tap do
180
+ signal = :"stack_#{method}_complete"
181
+
182
+ client.wait_until(signal, stack_name: identifier) do |waiter|
183
+ waiter.max_attempts = (opts.delete(:max_wait) || MAX_WAIT) / 5
184
+ waiter.delay = 5
185
+ end
186
+ end
187
+ end
188
+
189
+ def try_valid
190
+ yield || true
191
+ rescue Aws::CloudFormation::Errors::ValidationError => error
192
+ warn(error.message)
193
+ warn(error.backtrace)
194
+ false
195
+ end
196
+
197
+ def upload_object(key)
198
+ Aws.config.update(region: AWS_REGION)
199
+ bucket = Humidifier.config.s3_bucket
200
+
201
+ Aws::S3::Client.new.put_object(body: to_cf, bucket: bucket, key: key)
202
+ Aws::S3::Object.new(bucket, key).presigned_url(:get)
203
+ end
204
+
78
205
  def enumerable_resources
79
206
  ENUMERABLE_RESOURCES.each_with_object({}) do |(name, prop), list|
80
- resources = send(prop)
207
+ resources = public_send(prop)
81
208
  next if resources.empty?
82
209
 
83
210
  list[name] =
@@ -89,9 +216,27 @@ module Humidifier
89
216
 
90
217
  def static_resources
91
218
  STATIC_RESOURCES.each_with_object({}) do |(name, prop), list|
92
- resource = send(prop)
219
+ resource = public_send(prop)
93
220
  list[name] = resource if resource
94
221
  end
95
222
  end
223
+
224
+ def bytesize
225
+ to_cf.bytesize.tap do |size|
226
+ raise TemplateTooLargeError, size if size > MAX_TEMPLATE_URL_SIZE
227
+ end
228
+ end
229
+
230
+ def template_for(opts)
231
+ @template ||=
232
+ if opts.delete(:force_upload) ||
233
+ Humidifier.config.force_upload ||
234
+ bytesize > MAX_TEMPLATE_BODY_SIZE
235
+
236
+ { template_url: upload }
237
+ else
238
+ { template_body: to_cf }
239
+ end
240
+ end
96
241
  end
97
242
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Humidifier
4
4
  # Gem version
5
- VERSION = '2.15.0'
5
+ VERSION = '3.0.0'
6
6
  end
data/lib/humidifier.rb CHANGED
@@ -1,41 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'date'
4
- require 'forwardable'
5
4
  require 'json'
6
5
  require 'pathname'
7
6
  require 'yaml'
8
7
 
9
- require 'humidifier/utils'
10
- require 'humidifier/fn'
11
- require 'humidifier/ref'
12
- require 'humidifier/props'
13
-
14
- require 'humidifier/props/base'
8
+ require 'aws-sdk-cloudformation'
9
+ require 'aws-sdk-s3'
10
+ require 'fast_underscore'
15
11
 
16
- prop_types = %w[boolean double integer json list map string structure timestamp]
17
- prop_types.each { |type| require "humidifier/props/#{type}_prop" }
18
-
19
- require 'humidifier/aws_shim'
20
- require 'humidifier/condition'
21
- require 'humidifier/configuration'
22
- require 'humidifier/loader'
23
- require 'humidifier/mapping'
24
- require 'humidifier/output'
25
- require 'humidifier/parameter'
26
- require 'humidifier/resource'
27
- require 'humidifier/sdk_payload'
28
- require 'humidifier/serializer'
29
- require 'humidifier/sleeper'
30
- require 'humidifier/stack'
31
- require 'humidifier/version'
12
+ # Hook into the string extension and ensure it works for certain AWS acronyms
13
+ String.prepend(
14
+ Module.new do
15
+ def underscore
16
+ FastUnderscore.underscore(gsub(/(ARNs|AZs|VPCs)/) { $1.capitalize })
17
+ end
18
+ end
19
+ )
32
20
 
33
21
  # container module for all gem classes
34
22
  module Humidifier
35
23
  class << self
36
24
  # the configuration instance
37
25
  def config
38
- @config ||= Configuration.new
26
+ @config ||= Config.new
39
27
  end
40
28
 
41
29
  # yield the config object to the block for setting user params
@@ -62,7 +50,26 @@ module Humidifier
62
50
  def [](aws_name)
63
51
  registry[aws_name]
64
52
  end
53
+
54
+ # a frozen hash of the given names mapped to their underscored version
55
+ def underscore(names)
56
+ names.map { |name| [name, name.underscore.to_sym] }.to_h.freeze
57
+ end
65
58
  end
66
59
  end
67
60
 
61
+ require 'humidifier/condition'
62
+ require 'humidifier/config'
63
+ require 'humidifier/fn'
64
+ require 'humidifier/loader'
65
+ require 'humidifier/mapping'
66
+ require 'humidifier/output'
67
+ require 'humidifier/parameter'
68
+ require 'humidifier/ref'
69
+ require 'humidifier/resource'
70
+ require 'humidifier/serializer'
71
+ require 'humidifier/stack'
72
+ require 'humidifier/version'
73
+ require 'humidifier/props'
74
+
68
75
  Humidifier::Loader.load
metadata CHANGED
@@ -1,29 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humidifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Localytics
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2019-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-cloudformation
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.19'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-s3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.36'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.36'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fast_underscore
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: bundler
15
57
  requirement: !ruby/object:Gem::Requirement
16
58
  requirements:
17
59
  - - "~>"
18
60
  - !ruby/object:Gem::Version
19
- version: '1.16'
61
+ version: '2.0'
20
62
  type: :development
21
63
  prerelease: false
22
64
  version_requirements: !ruby/object:Gem::Requirement
23
65
  requirements:
24
66
  - - "~>"
25
67
  - !ruby/object:Gem::Version
26
- version: '1.16'
68
+ version: '2.0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: minitest
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +86,14 @@ dependencies:
44
86
  requirements:
45
87
  - - "~>"
46
88
  - !ruby/object:Gem::Version
47
- version: '1.8'
89
+ version: '1.10'
48
90
  type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
- version: '1.8'
96
+ version: '1.10'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: rake
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +114,28 @@ dependencies:
72
114
  requirements:
73
115
  - - "~>"
74
116
  - !ruby/object:Gem::Version
75
- version: '0.60'
117
+ version: '0.68'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.68'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-performance
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.2'
76
132
  type: :development
77
133
  prerelease: false
78
134
  version_requirements: !ruby/object:Gem::Requirement
79
135
  requirements:
80
136
  - - "~>"
81
137
  - !ruby/object:Gem::Version
82
- version: '0.60'
138
+ version: '1.2'
83
139
  - !ruby/object:Gem::Dependency
84
140
  name: simplecov
85
141
  requirement: !ruby/object:Gem::Requirement
@@ -120,37 +176,18 @@ files:
120
176
  - LICENSE
121
177
  - README.md
122
178
  - lib/humidifier.rb
123
- - lib/humidifier/aws_adapters/base.rb
124
- - lib/humidifier/aws_adapters/noop.rb
125
- - lib/humidifier/aws_adapters/sdkv1.rb
126
- - lib/humidifier/aws_adapters/sdkv2.rb
127
- - lib/humidifier/aws_adapters/sdkv3.rb
128
- - lib/humidifier/aws_shim.rb
129
179
  - lib/humidifier/condition.rb
130
- - lib/humidifier/configuration.rb
180
+ - lib/humidifier/config.rb
131
181
  - lib/humidifier/fn.rb
132
182
  - lib/humidifier/loader.rb
133
183
  - lib/humidifier/mapping.rb
134
184
  - lib/humidifier/output.rb
135
185
  - lib/humidifier/parameter.rb
136
186
  - lib/humidifier/props.rb
137
- - lib/humidifier/props/base.rb
138
- - lib/humidifier/props/boolean_prop.rb
139
- - lib/humidifier/props/double_prop.rb
140
- - lib/humidifier/props/integer_prop.rb
141
- - lib/humidifier/props/json_prop.rb
142
- - lib/humidifier/props/list_prop.rb
143
- - lib/humidifier/props/map_prop.rb
144
- - lib/humidifier/props/string_prop.rb
145
- - lib/humidifier/props/structure_prop.rb
146
- - lib/humidifier/props/timestamp_prop.rb
147
187
  - lib/humidifier/ref.rb
148
188
  - lib/humidifier/resource.rb
149
- - lib/humidifier/sdk_payload.rb
150
189
  - lib/humidifier/serializer.rb
151
- - lib/humidifier/sleeper.rb
152
190
  - lib/humidifier/stack.rb
153
- - lib/humidifier/utils.rb
154
191
  - lib/humidifier/version.rb
155
192
  homepage: https://github.com/localytics/humidifier
156
193
  licenses:
@@ -164,15 +201,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
201
  requirements:
165
202
  - - ">="
166
203
  - !ruby/object:Gem::Version
167
- version: '2.1'
204
+ version: '2.4'
168
205
  required_rubygems_version: !ruby/object:Gem::Requirement
169
206
  requirements:
170
207
  - - ">="
171
208
  - !ruby/object:Gem::Version
172
209
  version: '0'
173
210
  requirements: []
174
- rubyforge_project:
175
- rubygems_version: 2.7.6
211
+ rubygems_version: 3.0.3
176
212
  signing_key:
177
213
  specification_version: 4
178
214
  summary: CloudFormation made easy
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Humidifier
4
- # A container module for all adapters for the SDK
5
- module AwsAdapters
6
- # The parent class for the adapters for both versions of the SDK
7
- class Base
8
- # Create a CFN stack
9
- def create(payload)
10
- try_valid do
11
- response = client.create_stack(payload.create_params)
12
- payload.id = response.stack_id
13
- response
14
- end
15
- end
16
-
17
- # Delete a CFN stack
18
- def delete(payload)
19
- client.delete_stack(payload.delete_params)
20
- true
21
- end
22
-
23
- # Update a CFN stack if it exists, otherwise create it
24
- def deploy(payload)
25
- exists?(payload) ? update(payload) : create(payload)
26
- end
27
-
28
- # Update a CFN stack
29
- def update(payload)
30
- try_valid { client.update_stack(payload.update_params) }
31
- end
32
-
33
- # Upload a CFN stack to S3 so that it can be referenced via template_url
34
- def upload(payload)
35
- Humidifier.config.ensure_upload_configured!(payload)
36
- filename = "#{Humidifier.config.s3_prefix}#{payload.identifier}.json"
37
- upload_object(payload, filename)
38
- end
39
-
40
- # Validate a template in CFN
41
- def valid?(payload)
42
- try_valid { client.validate_template(payload.validate_params) }
43
- end
44
-
45
- %i[create delete deploy update].each do |method|
46
- define_method(:"#{method}_and_wait") do |payload|
47
- perform_and_wait(method, payload)
48
- end
49
- end
50
-
51
- private
52
-
53
- def client
54
- @client ||=
55
- base_module::CloudFormation::Client.new(region: AwsShim::REGION)
56
- end
57
-
58
- def try_valid
59
- yield || true
60
- rescue base_module::CloudFormation::Errors::ValidationError => error
61
- warn(error.message)
62
- warn(error.backtrace)
63
- false
64
- end
65
- end
66
- end
67
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Humidifier
4
- module AwsAdapters
5
- # An adapter used when neither SDK is loaded
6
- class Noop
7
- # Capture all STACK_METHODS method calls and warn that they will not be
8
- # run
9
- def method_missing(method, *)
10
- if AwsShim::STACK_METHODS.include?(method)
11
- puts "WARNING: Cannot run #{method} because aws-sdk not loaded."
12
- false
13
- else
14
- super
15
- end
16
- end
17
-
18
- # We capture stack methods and warn about them but don't actually respond
19
- # to them
20
- def respond_to_missing?(method, *)
21
- AwsShim::STACK_METHODS.include?(method) ? false : super
22
- end
23
- end
24
- end
25
- end