cfn-bridge 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +36 -0
  6. data/Rakefile +2 -0
  7. data/bin/cfn-bridge +5 -0
  8. data/cfn-bridge.gemspec +33 -0
  9. data/lib/cfn-bridge.rb +1 -0
  10. data/lib/cloud_formation/bridge/cli.rb +16 -0
  11. data/lib/cloud_formation/bridge/errors.rb +5 -0
  12. data/lib/cloud_formation/bridge/exception_notifier.rb +59 -0
  13. data/lib/cloud_formation/bridge/executor.rb +50 -0
  14. data/lib/cloud_formation/bridge/http_bridge.rb +30 -0
  15. data/lib/cloud_formation/bridge/names.rb +34 -0
  16. data/lib/cloud_formation/bridge/poller.rb +67 -0
  17. data/lib/cloud_formation/bridge/request.rb +94 -0
  18. data/lib/cloud_formation/bridge/resources/base.rb +31 -0
  19. data/lib/cloud_formation/bridge/resources/cloud_formation_outputs.rb +44 -0
  20. data/lib/cloud_formation/bridge/resources/subscribe_queue_to_topic.rb +66 -0
  21. data/lib/cloud_formation/bridge/version.rb +5 -0
  22. data/spec/files/outputs-formation.json +48 -0
  23. data/spec/files/sample-create-message.json +12 -0
  24. data/spec/files/sample-delete-message.json +12 -0
  25. data/spec/files/subscribe-to-sns-formation.json +79 -0
  26. data/spec/files/test-formation.json +75 -0
  27. data/spec/lib/cloud_formation/bridge/executor_spec.rb +66 -0
  28. data/spec/lib/cloud_formation/bridge/poller_spec.rb +88 -0
  29. data/spec/lib/cloud_formation/bridge/request_spec.rb +130 -0
  30. data/spec/lib/cloud_formation/bridge/resources/cloud_formation_outputs_spec.rb +36 -0
  31. data/spec/lib/cloud_formation/bridge/resources/subscribe_queue_to_topic_spec.rb +95 -0
  32. data/spec/spec_helper.rb +92 -0
  33. data/spec/support/cloud_formation_creator.rb +104 -0
  34. data/spec/support/file_support.rb +7 -0
  35. metadata +245 -0
@@ -0,0 +1,92 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+
18
+ ENV['CFN_ENVIRONMENT'] = 'test'
19
+
20
+ require 'pry'
21
+ require 'dotenv'
22
+
23
+ Dotenv.load
24
+
25
+ RSpec.configure do |config|
26
+ # The settings below are suggested to provide a good initial experience
27
+ # with RSpec, but feel free to customize to your heart's content.
28
+
29
+ # These two settings work together to allow you to limit a spec run
30
+ # to individual examples or groups you care about by tagging them with
31
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
32
+ # get run.
33
+ config.filter_run :focus
34
+ config.run_all_when_everything_filtered = true
35
+
36
+ # Many RSpec users commonly either run the entire suite or an individual
37
+ # file, and it's useful to allow more verbose output when running an
38
+ # individual spec file.
39
+ if config.files_to_run.one?
40
+ # Use the documentation formatter for detailed output,
41
+ # unless a formatter has already been configured
42
+ # (e.g. via a command-line flag).
43
+ config.default_formatter = 'doc'
44
+ end
45
+
46
+ # Print the 10 slowest examples and example groups at the
47
+ # end of the spec run, to help surface which specs are running
48
+ # particularly slow.
49
+ config.profile_examples = 10
50
+
51
+ # Run specs in random order to surface order dependencies. If you find an
52
+ # order dependency and want to debug it, you can fix the order by providing
53
+ # the seed, which is printed after each run.
54
+ # --seed 1234
55
+ config.order = :random
56
+
57
+ # Seed global randomization in this process using the `--seed` CLI option.
58
+ # Setting this allows you to use `--seed` to deterministically reproduce
59
+ # test failures related to randomization by passing the same `--seed` value
60
+ # as the one that triggered the failure.
61
+ Kernel.srand config.seed
62
+
63
+ # rspec-expectations config goes here. You can use an alternate
64
+ # assertion/expectation library such as wrong or the stdlib/minitest
65
+ # assertions if you prefer.
66
+ config.expect_with :rspec do |expectations|
67
+ # Enable only the newer, non-monkey-patching expect syntax.
68
+ # For more details, see:
69
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
70
+ expectations.syntax = :expect
71
+ end
72
+
73
+ # rspec-mocks config goes here. You can use an alternate test double
74
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
75
+ config.mock_with :rspec do |mocks|
76
+ # Enable only the newer, non-monkey-patching expect syntax.
77
+ # For more details, see:
78
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
79
+ mocks.syntax = :expect
80
+
81
+ # Prevents you from mocking or stubbing a method that does not exist on
82
+ # a real object. This is generally recommended.
83
+ mocks.verify_partial_doubles = true
84
+ end
85
+
86
+ config.filter_run_excluding(:integration => true) unless ENV['CFN_INTEGRATION'] == 'true'
87
+
88
+ end
89
+
90
+ ['cloud_formation_creator', 'file_support'].each do |file|
91
+ require File.join(__dir__, 'support', file)
92
+ end
@@ -0,0 +1,104 @@
1
+ require 'securerandom'
2
+ require 'aws/cloud_formation'
3
+ require 'aws/sns'
4
+
5
+ module CloudFormationCreator
6
+
7
+ COMPLETE_STATUSES = %w(
8
+ CREATE_FAILED
9
+ CREATE_COMPLETE
10
+ ROLLBACK_FAILED
11
+ ROLLBACK_COMPLETE
12
+ DELETE_FAILED
13
+ DELETE_COMPLETE
14
+ UPDATE_COMPLETE_CLEANUP_IN_PROGRESS
15
+ UPDATE_COMPLETE
16
+ UPDATE_ROLLBACK_FAILED
17
+ UPDATE_ROLLBACK_COMPLETE
18
+ )
19
+
20
+ def with_cloud_formation(file, params = {}, wait = true)
21
+ path = File.join(File.dirname(__FILE__), '..', 'files', "#{file}.json")
22
+ stack = cloud_formation.stacks.create(
23
+ "test-custom-#{SecureRandom.uuid}",
24
+ IO.read(path),
25
+ parameters: params)
26
+
27
+ wait_until_complete(stack) if wait
28
+
29
+ if block_given?
30
+ yield(stack)
31
+ stack.delete
32
+ end
33
+
34
+ stack
35
+ end
36
+
37
+ def cloud_formation
38
+ @cloud_formation ||= AWS::CloudFormation.new
39
+ end
40
+
41
+ def topics
42
+ @topics ||= sns.topics
43
+ end
44
+
45
+ def sns
46
+ @sns ||= AWS::SNS.new
47
+ end
48
+
49
+ def subscriptions
50
+ sns.subscriptions
51
+ end
52
+
53
+ def queues
54
+ @queues ||= AWS::SQS.new.queues
55
+ end
56
+
57
+ def wait_until(label, max_waits = 60)
58
+ waits = 0
59
+ while !yield
60
+ print '*'
61
+ waits += 1
62
+
63
+ if waits >= max_waits
64
+ raise "Waited for #{waits * 3} #{label} and it didn't finish, giving up"
65
+ end
66
+
67
+ sleep(3)
68
+ end
69
+ end
70
+
71
+ def wait_until_complete(stack, max_waits = 60)
72
+ waits = 0
73
+ while !COMPLETE_STATUSES.include?(stack.status)
74
+ print '*'
75
+ waits += 1
76
+
77
+ if waits >= max_waits
78
+ raise "Waited for #{waits * 3} and #{stack.name} status is still #{stack.status}, giving up"
79
+ end
80
+
81
+ sleep(3)
82
+ end
83
+ end
84
+
85
+ def stack_outputs(stack)
86
+ stack.outputs.inject({}) do |acc, output|
87
+ acc[output.key] = output.value
88
+ acc
89
+ end
90
+ end
91
+
92
+ def with_main_formation(&block)
93
+ with_cloud_formation 'test-formation' do |stack|
94
+ outputs = stack_outputs(stack)
95
+
96
+ poller = CloudFormation::Bridge::Poller.new(outputs["Queue"])
97
+
98
+ block.call(stack, poller, outputs)
99
+
100
+ poller.poll
101
+ end
102
+ end
103
+
104
+ end
@@ -0,0 +1,7 @@
1
+ module FileSupport
2
+
3
+ def read_file(name)
4
+ IO.read(File.join(__dir__, '..', 'files', name))
5
+ end
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,245 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cfn-bridge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maurício Linhares
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.5
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 10.3.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.3.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.11.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: aws-sdk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.50.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.50.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday_middleware
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: thor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.19.1
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.19.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: typhoeus
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.6.9
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.6.9
153
+ - !ruby/object:Gem::Dependency
154
+ name: rollbar
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.0.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 1.0.0
167
+ description: Implements custom operations for CF calls
168
+ email:
169
+ - mlinhares@neat.com
170
+ executables:
171
+ - cfn-bridge
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - Gemfile
177
+ - LICENSE.txt
178
+ - README.md
179
+ - Rakefile
180
+ - bin/cfn-bridge
181
+ - cfn-bridge.gemspec
182
+ - lib/cfn-bridge.rb
183
+ - lib/cloud_formation/bridge/cli.rb
184
+ - lib/cloud_formation/bridge/errors.rb
185
+ - lib/cloud_formation/bridge/exception_notifier.rb
186
+ - lib/cloud_formation/bridge/executor.rb
187
+ - lib/cloud_formation/bridge/http_bridge.rb
188
+ - lib/cloud_formation/bridge/names.rb
189
+ - lib/cloud_formation/bridge/poller.rb
190
+ - lib/cloud_formation/bridge/request.rb
191
+ - lib/cloud_formation/bridge/resources/base.rb
192
+ - lib/cloud_formation/bridge/resources/cloud_formation_outputs.rb
193
+ - lib/cloud_formation/bridge/resources/subscribe_queue_to_topic.rb
194
+ - lib/cloud_formation/bridge/version.rb
195
+ - spec/files/outputs-formation.json
196
+ - spec/files/sample-create-message.json
197
+ - spec/files/sample-delete-message.json
198
+ - spec/files/subscribe-to-sns-formation.json
199
+ - spec/files/test-formation.json
200
+ - spec/lib/cloud_formation/bridge/executor_spec.rb
201
+ - spec/lib/cloud_formation/bridge/poller_spec.rb
202
+ - spec/lib/cloud_formation/bridge/request_spec.rb
203
+ - spec/lib/cloud_formation/bridge/resources/cloud_formation_outputs_spec.rb
204
+ - spec/lib/cloud_formation/bridge/resources/subscribe_queue_to_topic_spec.rb
205
+ - spec/spec_helper.rb
206
+ - spec/support/cloud_formation_creator.rb
207
+ - spec/support/file_support.rb
208
+ homepage: https://github.com/TheNeatCompany/cfn-bridge
209
+ licenses:
210
+ - MIT
211
+ metadata: {}
212
+ post_install_message:
213
+ rdoc_options: []
214
+ require_paths:
215
+ - lib
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 2.2.2
229
+ signing_key:
230
+ specification_version: 4
231
+ summary: Implements custom operations for CF calls
232
+ test_files:
233
+ - spec/files/outputs-formation.json
234
+ - spec/files/sample-create-message.json
235
+ - spec/files/sample-delete-message.json
236
+ - spec/files/subscribe-to-sns-formation.json
237
+ - spec/files/test-formation.json
238
+ - spec/lib/cloud_formation/bridge/executor_spec.rb
239
+ - spec/lib/cloud_formation/bridge/poller_spec.rb
240
+ - spec/lib/cloud_formation/bridge/request_spec.rb
241
+ - spec/lib/cloud_formation/bridge/resources/cloud_formation_outputs_spec.rb
242
+ - spec/lib/cloud_formation/bridge/resources/subscribe_queue_to_topic_spec.rb
243
+ - spec/spec_helper.rb
244
+ - spec/support/cloud_formation_creator.rb
245
+ - spec/support/file_support.rb