awspec 0.86.0 → 0.87.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Rakefile +6 -1
- data/lib/awspec/helper/client_wrap.rb +46 -0
- data/lib/awspec/helper/finder.rb +6 -1
- data/lib/awspec/helper/finder/cloudwatch_logs.rb +1 -1
- data/lib/awspec/helper/finder/ec2.rb +8 -6
- data/lib/awspec/helper/finder/iam.rb +9 -7
- data/lib/awspec/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0bcfc84f264a0b85f2f18f22519ed7aab5ffde2
|
4
|
+
data.tar.gz: 23da8dcad88edde7095a351e0c438dbde7f81f84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c9ccb900e383f560887452ec04f430eb8ee5a2c8b5532bce01d7b080b8c886e781d98e9a2c4c3d9108ed18af398b462f4291100256129341d9fb86d790cace9
|
7
|
+
data.tar.gz: 721e77e16de76fc711c7196330804ad48492ccc4dae6b1853a54bada63f04057cdbcdbef1be41fd393c9ed77514ef9464449276d4d03838dfb858d140f86d506
|
data/.gitignore
CHANGED
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
|
data/lib/awspec/helper/finder.rb
CHANGED
@@ -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(
|
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.
|
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.
|
45
|
-
|
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.
|
50
|
-
|
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.
|
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.
|
44
|
-
|
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.
|
51
|
-
|
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
|
data/lib/awspec/version.rb
CHANGED
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.
|
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-
|
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
|