awspec 0.86.0 → 0.87.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d9ac6e4891eae5bfd514aee8f72a6a323b0b5c0
4
- data.tar.gz: de536803219c6b32193384ad01b82ea0f23a6bfb
3
+ metadata.gz: f0bcfc84f264a0b85f2f18f22519ed7aab5ffde2
4
+ data.tar.gz: 23da8dcad88edde7095a351e0c438dbde7f81f84
5
5
  SHA512:
6
- metadata.gz: 385162854f73f06848cca0c82d8530600b95d10b32d5caa81cf3ef2da487f9f164fdbbec5d7aae4f1c47e9bf9ff2db741d4866c978bd38ef692cc7a83f19106e
7
- data.tar.gz: 1be74de00693e74ce843ee2ff3f83f150d201363c4a3e2cf80018eff794b53e52593a728033eea8586aa7e4d67fccd51d6cc2bb4fdacc69062a9a7e1e57f282c
6
+ metadata.gz: 4c9ccb900e383f560887452ec04f430eb8ee5a2c8b5532bce01d7b080b8c886e781d98e9a2c4c3d9108ed18af398b462f4291100256129341d9fb86d790cace9
7
+ data.tar.gz: 721e77e16de76fc711c7196330804ad48492ccc4dae6b1853a54bada63f04057cdbcdbef1be41fd393c9ed77514ef9464449276d4d03838dfb858d140f86d506
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /tmp/
9
9
  /spec/secrets.yml
10
10
  /.ruby-version
11
+ *.sw*
12
+ *.gem
data/Rakefile CHANGED
@@ -23,7 +23,8 @@ if defined?(RSpec)
23
23
  'spec:core',
24
24
  'spec:generator_spec',
25
25
  'spec:generator_doc',
26
- 'spec:rubocop']
26
+ 'spec:rubocop',
27
+ 'spec:helper']
27
28
 
28
29
  task type: types
29
30
 
@@ -49,6 +50,10 @@ if defined?(RSpec)
49
50
  t.pattern = 'spec/generator/doc/*_spec.rb'
50
51
  end
51
52
 
53
+ RSpec::Core::RakeTask.new(:helper) do |t|
54
+ t.pattern = 'spec/lib/awspec/helper/*_spec.rb'
55
+ end
56
+
52
57
  RuboCop::RakeTask.new
53
58
  end
54
59
  end
@@ -0,0 +1,46 @@
1
+ module Awspec::Helper
2
+ class ClientWrap
3
+ attr_reader :client, :backoff, :iteration, :backoff_limit, :symbol
4
+ def initialize(real_client = nil, args = {})
5
+ raise ArgumentError, 'Client can not be nil' if real_client.nil?
6
+ @client = real_client
7
+ @backoff = args.key?(:backoff) ? args[:backoff] : 0.0
8
+ @orig_backoff = @backoff
9
+ @iteration = args.key?(:iteration) ? args[:iteration] : 1
10
+ @orig_iter = @iteration
11
+ @backoff_limit = args.key?(:backoff_limit) ? args[:backoff_limit] : 30.0
12
+ # build the symbol we'll use to compare to any errors caught in method_missing
13
+ # below.
14
+ @symbol = real_client.class.to_s.split('::').shift(2).push('Errors', 'RequestLimitExceeded').join('::').to_sym
15
+ end
16
+
17
+ protected
18
+
19
+ # used to capture only the "RequestLimitExceeded" error from an aws
20
+ # client api call. In the case of matching it we want to try again,
21
+ # backing off successively each time, until the backoff_limit is reached or
22
+ # exceeded, in which case, the error will be re-raised and it should fail
23
+ # as expected.
24
+ def method_missing(m, *args, &block)
25
+ begin
26
+ results = client.send(m, *args, &block)
27
+ rescue Exception => e # rubocop:disable Lint/RescueException
28
+ raise unless e.class.to_s == symbol.to_s && backoff < backoff_limit
29
+
30
+ @backoff = backoff + (iteration * iteration * 0.5)
31
+ @iteration += 1
32
+ sleep backoff
33
+ results = self.send(m, *args, &block)
34
+ end
35
+
36
+ reset_backoff
37
+
38
+ results
39
+ end
40
+
41
+ def reset_backoff
42
+ @backoff = @orig_backoff
43
+ @iteration = @orig_iter
44
+ end
45
+ end
46
+ end
@@ -35,6 +35,8 @@ require 'awspec/helper/finder/cloudformation'
35
35
 
36
36
  require 'awspec/helper/finder/account_attributes'
37
37
 
38
+ require 'awspec/helper/client_wrap'
39
+
38
40
  module Awspec::Helper
39
41
  module Finder
40
42
  include Awspec::Helper::Finder::Alb
@@ -111,7 +113,10 @@ module Awspec::Helper
111
113
  CLIENTS.each do |method_name, client|
112
114
  define_method method_name do
113
115
  unless self.methods.include? "@#{method_name}"
114
- instance_variable_set("@#{method_name}", client.new(CLIENT_OPTIONS))
116
+ instance_variable_set(
117
+ "@#{method_name}",
118
+ Awspec::Helper::ClientWrap.new(client.new(CLIENT_OPTIONS))
119
+ )
115
120
  end
116
121
  end
117
122
  end
@@ -50,7 +50,7 @@ module Awspec::Helper
50
50
  method_name = 'describe_' + type + '_filters'
51
51
  resources = []
52
52
  loop do
53
- res = cloudwatch_logs_client.method(method_name).call(req)
53
+ res = cloudwatch_logs_client.send(method_name, req)
54
54
  case type
55
55
  when 'metric' then
56
56
  resources.push(*res.metric_filters)
@@ -41,14 +41,16 @@ module Awspec::Helper
41
41
  define_method 'find_' + type + '_gateway' do |*args|
42
42
  gateway_id = args.first
43
43
  method_name = 'describe_' + type + '_gateways'
44
- res = ec2_client.method(method_name).call({
45
- filters: [{ name: type + '-gateway-id', values: [gateway_id] }]
46
- })
44
+ res = ec2_client.send(
45
+ method_name,
46
+ { filters: [{ name: type + '-gateway-id', values: [gateway_id] }] }
47
+ )
47
48
  resource = res[type + '_gateways'].single_resource(gateway_id)
48
49
  return resource if resource
49
- res = ec2_client.method(method_name).call({
50
- filters: [{ name: 'tag:Name', values: [gateway_id] }]
51
- })
50
+ res = ec2_client.send(
51
+ method_name,
52
+ { filters: [{ name: 'tag:Name', values: [gateway_id] }] }
53
+ )
52
54
  res[type + '_gateways'].single_resource(gateway_id)
53
55
  end
54
56
  end
@@ -7,7 +7,7 @@ module Awspec::Helper
7
7
  define_method 'find_iam_' + type do |*args|
8
8
  id = args.first
9
9
  selected = []
10
- res = iam_client.method('list_' + type.pluralize).call
10
+ res = iam_client.send('list_' + type.pluralize)
11
11
  loop do
12
12
  selected += res[type.pluralize].select do |u|
13
13
  u[type + '_name'] == id || u[type + '_id'] == id || u.arn == id
@@ -40,16 +40,18 @@ module Awspec::Helper
40
40
 
41
41
  %w(user group role).each do |type|
42
42
  define_method 'select_iam_policy_by_' + type + '_name' do |name|
43
- res = iam_client.method('list_attached_' + type + '_policies').call({
44
- (type + '_name').to_sym => name
45
- })
43
+ res = iam_client.send(
44
+ 'list_attached_' + type + '_policies',
45
+ { (type + '_name').to_sym => name }
46
+ )
46
47
  res.attached_policies
47
48
  end
48
49
 
49
50
  define_method 'select_inline_policy_by_' + type + '_name' do |name|
50
- res = iam_client.method('list_' + type + '_policies').call({
51
- (type + '_name').to_sym => name
52
- })
51
+ res = iam_client.send(
52
+ 'list_' + type + '_policies',
53
+ { (type + '_name').to_sym => name }
54
+ )
53
55
  res.policy_names
54
56
  end
55
57
  end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.86.0'
2
+ VERSION = '0.87.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.86.0
4
+ version: 0.87.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-04 00:00:00.000000000 Z
11
+ date: 2017-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -368,6 +368,7 @@ files:
368
368
  - lib/awspec/generator/spec/vpc.rb
369
369
  - lib/awspec/generator/template.rb
370
370
  - lib/awspec/helper.rb
371
+ - lib/awspec/helper/client_wrap.rb
371
372
  - lib/awspec/helper/color.rb
372
373
  - lib/awspec/helper/finder.rb
373
374
  - lib/awspec/helper/finder/account_attributes.rb