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
@@ -1,122 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Humidifier
4
- # The payload sent to the shim methods, representing the stack and the options
5
- class SdkPayload
6
- # The maximum size a template body can be before it has to be put somewhere
7
- # and referenced through a URL
8
- MAX_TEMPLATE_BODY_SIZE = 51_200
9
-
10
- # The maximum size a template body can be inside of an S3 bucket
11
- MAX_TEMPLATE_URL_SIZE = 460_800
12
-
13
- # The maximum amount of time that Humidifier should wait for a stack to
14
- # complete a CRUD operation
15
- MAX_WAIT = 600
16
-
17
- # Thrown when a template is too large to use the template_url option
18
- class TemplateTooLargeError < StandardError
19
- def initialize(bytesize)
20
- message =
21
- "Cannot use a template > #{MAX_TEMPLATE_URL_SIZE} bytes " \
22
- "(currently #{bytesize} bytes), consider using nested stacks " \
23
- '(http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide' \
24
- '/aws-properties-stack.html)'
25
- super(message)
26
- end
27
- end
28
-
29
- # The stack on which operations are going to be performed.
30
- attr_reader :stack
31
-
32
- # Options that should be passed through to CloudFormation when the desired
33
- # operation is being performed. Particularly useful for the `capabilities`
34
- # option for acknowledging IAM resource changes.
35
- attr_reader :options
36
-
37
- # The maximum amount of time that `humidifier` should wait for the stack to
38
- # resolve to the desired state. If your stacks are particularly large, you
39
- # may need to set this to wait longer than the default `MAX_WAIT`.
40
- attr_accessor :max_wait
41
-
42
- # Force the stack to upload to S3 regardless of the size of the stack.
43
- attr_accessor :force_upload
44
-
45
- extend Forwardable
46
- def_delegators :stack, :id=, :identifier, :name
47
-
48
- def initialize(stack, options)
49
- @stack = stack
50
- @options = options
51
- @max_wait = options.delete(:max_wait) || MAX_WAIT
52
- @force_upload = options.delete(:force_upload)
53
- end
54
-
55
- # True if the stack and options are the same as the other (used for testing)
56
- def ==(other)
57
- stack == other.stack && options == other.options
58
- end
59
-
60
- # Merge in options
61
- def merge(new_options)
62
- @options = new_options.merge(options)
63
- end
64
-
65
- # The body of the template
66
- def template_body
67
- @template_body ||= stack.to_cf
68
- end
69
-
70
- ###
71
- # Param sets
72
- ###
73
-
74
- # Param set for the #create_change_set SDK method
75
- def create_change_set_params
76
- { stack_name: stack.identifier }.merge(template_param).merge(options)
77
- end
78
-
79
- # Param set for the #create_stack SDK method
80
- def create_params
81
- { stack_name: stack.name }.merge(template_param).merge(options)
82
- end
83
-
84
- # Param set for the #delete_stack SDK method
85
- def delete_params
86
- { stack_name: stack.identifier }.merge(options)
87
- end
88
-
89
- # Param set for the #update_stack SDK method
90
- def update_params
91
- { stack_name: stack.identifier }.merge(template_param).merge(options)
92
- end
93
-
94
- # Param set for the #validate_template SDK method
95
- def validate_params
96
- template_param.merge(options)
97
- end
98
-
99
- private
100
-
101
- def bytesize
102
- template_body.bytesize.tap do |size|
103
- raise TemplateTooLargeError, size if size > MAX_TEMPLATE_URL_SIZE
104
- end
105
- end
106
-
107
- def should_upload?
108
- return force_upload unless force_upload.nil?
109
-
110
- Humidifier.config.force_upload || bytesize > MAX_TEMPLATE_BODY_SIZE
111
- end
112
-
113
- def template_param
114
- @template_param ||=
115
- if should_upload?
116
- { template_url: AwsShim.upload(self) }
117
- else
118
- { template_body: template_body }
119
- end
120
- end
121
- end
122
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Humidifier
4
- # Manages waiting for stack events for v1 of the SDK
5
- class Sleeper
6
- attr_reader :attempts
7
-
8
- # Store attempts and wait for the block to return true
9
- def initialize(attempts, &block)
10
- @attempts = attempts
11
- hibernate_until(&block)
12
- end
13
-
14
- private
15
-
16
- def hibernate_until(&block)
17
- raise 'Waited too long, giving up' if attempts.zero?
18
- return if yield
19
-
20
- @attempts -= 1
21
- sleep 1
22
- hibernate_until(&block)
23
- end
24
- end
25
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Humidifier
4
- # Dumps an object to CFN syntax
5
- module Utils
6
- # convert from UpperCamelCase to lower_snake_case
7
- def self.underscore(name)
8
- return nil unless name
9
-
10
- name.gsub(/([A-Z]+)([0-9]|[A-Z]|\z)/) { "#{$1.capitalize}#{$2}" }
11
- .gsub(/(.)([A-Z])/, '\1_\2').downcase
12
- end
13
-
14
- # a frozen hash of the given names mapped to their underscored version
15
- def self.underscored(names)
16
- names.map { |name| [name, underscore(name).to_sym] }.to_h.freeze
17
- end
18
- end
19
- end