aws-dev-utils 1.4.9 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/aws-dev-utils/client_wrapper.rb +1 -1
- data/lib/aws-dev-utils/next_token_wrapper.rb +32 -21
- data/lib/aws-dev-utils/refinements.rb +2 -1
- data/lib/aws-dev-utils/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fa3a5f5b41c92caa60a64b79f2c1710d6600f0306e48ef33f9c338489b23a11
|
4
|
+
data.tar.gz: 5673be8d53221e6997e7eb0c68245481fefe7587352f40b329820a7aa88a2cd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4c426208915958d31aa394852de7c4bb6998c6e93a3e8562db7c8a84a38f65b3f481fbc16bbd45f658450f3a960873b0a16be76de21cf7949f92f49cd452a8a
|
7
|
+
data.tar.gz: '08febba1667d5f9865980fc6161bdd70b620586d9acbb2409c6f7b6b0c6481c7301267fd87a7c4ebb76c58c97427e67b8d4747a7a41fa35952e9ee9699365a88'
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ AWS Dev Utilities is available from RubyGems.
|
|
9
9
|
### Option 1: Via Bundler
|
10
10
|
Add the following to your application's Gemfile:
|
11
11
|
```ruby
|
12
|
-
gem 'aws-dev-utils', '~> 1.
|
12
|
+
gem 'aws-dev-utils', '~> 1.5'
|
13
13
|
```
|
14
14
|
And then execute:
|
15
15
|
```
|
@@ -18,7 +18,7 @@ $ bundle install
|
|
18
18
|
### Option 2: Via `gem install`
|
19
19
|
Execute the following inside your application directory:
|
20
20
|
```
|
21
|
-
$ gem install aws-dev-utils -v '~> 1.
|
21
|
+
$ gem install aws-dev-utils -v '~> 1.5'
|
22
22
|
```
|
23
23
|
## Usage
|
24
24
|
Add the following at the top of each Ruby script, or in each module/class you want to use the `with_next_token`, `with_cache` or `with_retry` functions:
|
@@ -32,7 +32,7 @@ Many AWS operations limit the number of results returned with each response. To
|
|
32
32
|
This functionality is rarely needed and causes a lot of boilerplate code.
|
33
33
|
Using the `client.with_next_token` the paged results will be collected for you.
|
34
34
|
The AWS client function and its results will be concatenated until either no more results are available or the max number of requests is reached.
|
35
|
-
_`with_next_token` works with APIs that use `next_token`, `next_marker` or `
|
35
|
+
_`with_next_token` works with APIs that use `next_token`, `next_marker`, `next_continuation_token` or `next_record_name`._
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
require 'aws-dev-utils'
|
@@ -1,42 +1,53 @@
|
|
1
1
|
module AwsDevUtils
|
2
2
|
class NextTokenWrapper
|
3
3
|
|
4
|
+
DEFAULT_MAX=100
|
5
|
+
|
4
6
|
# Initialize a new NextTokenWrapper, internal use only
|
5
7
|
# @params client [Aws client / NextTokenWrapper / RetryWrapper]
|
6
8
|
# @param max [Integer] - max number of requests
|
7
|
-
def initialize client, max=
|
9
|
+
def initialize client, max=DEFAULT_MAX
|
8
10
|
@client = client
|
9
11
|
@max = max
|
10
12
|
end
|
11
13
|
|
12
|
-
def method_missing
|
13
|
-
do_call(
|
14
|
+
def method_missing method, *args, &block
|
15
|
+
do_call(method, *args, &block)
|
14
16
|
end
|
15
17
|
|
16
18
|
private
|
19
|
+
def do_call method, *args, &block
|
20
|
+
response = @client.send(method, *args, &block).to_h
|
21
|
+
i = 1
|
22
|
+
req_keys, next_req_keys = extract_keys response
|
23
|
+
|
24
|
+
return response if req_keys.nil?
|
25
|
+
|
26
|
+
props = args.first || {}
|
27
|
+
while req_keys.all?{ |req_keys| response[req_keys] } && i < @max do
|
28
|
+
i += 1
|
29
|
+
pagination_token_props = Hash[next_req_keys.zip(req_keys.map { |req_keys| response[req_keys] } ) ]
|
30
|
+
new_response = @client.send(method, props.merge(pagination_token_props)).to_h
|
17
31
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
key, key2 = extract_keys r
|
22
|
-
while(key && r[key] && i < @max) do
|
23
|
-
i += 1
|
24
|
-
res = @client.send(m, (args[0]||{}).merge(key2 => r[key])).to_h
|
25
|
-
res.each { |k,v| r[k] = v.is_a?(Array) ? r[k].concat(v) : v }
|
26
|
-
r.delete_if {|k,v| !res.keys.include?(k) }
|
27
|
-
end
|
28
|
-
r.delete key
|
32
|
+
new_response.each { |k,v| new_response[k] = v.is_a?(Array) ? response[k]+new_response[k] : v }
|
33
|
+
|
34
|
+
response = new_response
|
29
35
|
end
|
36
|
+
|
37
|
+
req_keys.each { |req_keys| response.delete req_keys}
|
38
|
+
response
|
30
39
|
end
|
31
40
|
|
32
|
-
def extract_keys
|
41
|
+
def extract_keys response
|
33
42
|
case
|
34
|
-
when
|
35
|
-
[:next_token, :next_token]
|
36
|
-
when
|
37
|
-
[:next_marker, :marker]
|
38
|
-
when
|
39
|
-
[:next_continuation_token, :continuation_token]
|
43
|
+
when response[:next_token]
|
44
|
+
[[:next_token], [:next_token]]
|
45
|
+
when response[:next_marker]
|
46
|
+
[[:next_marker], [:marker]]
|
47
|
+
when response[:next_continuation_token]
|
48
|
+
[[:next_continuation_token], [:continuation_token]]
|
49
|
+
when response[:next_record_name]
|
50
|
+
[[:next_record_type, :next_record_name], [:start_record_type, :start_record_name]]
|
40
51
|
else nil
|
41
52
|
end
|
42
53
|
end
|
@@ -5,7 +5,8 @@ module AwsDevUtils
|
|
5
5
|
|
6
6
|
refine Seahorse::Client::Base do
|
7
7
|
def with_next_token *args
|
8
|
-
AwsDevUtils::ClientWrapper.new(self)
|
8
|
+
c = AwsDevUtils::ClientWrapper.new(self)
|
9
|
+
c.send(__callee__, *args)
|
9
10
|
end
|
10
11
|
alias_method :with_retry, :with_next_token
|
11
12
|
alias_method :with_cache, :with_next_token
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-dev-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amobee BI Infrastructure
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -70,14 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
70
|
requirements:
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: 2.
|
73
|
+
version: 2.3.0
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
|
-
rubygems_version: 3.0.
|
80
|
+
rubygems_version: 3.0.9
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: Ruby library gem that provides common AWS utilities
|