infopark-aws_utils 0.8.1 → 1.0.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
- SHA1:
3
- metadata.gz: 006b2100b6b073324eaca1778953e0145be0fd50
4
- data.tar.gz: 81aef7b6cb4db98985357c06a27ac58309541b3a
2
+ SHA256:
3
+ metadata.gz: d3e7e356a45fa25bf635a55425020ea0b6a05af17731565e996ac52d444eec87
4
+ data.tar.gz: 138f8b6bf8e7266956756eca4511544d6386eb4e41de0c1887c3fc642910ba88
5
5
  SHA512:
6
- metadata.gz: 32e2faf37d95a697c58fa97cbe3460cf2024e42ab098c34127ad31703cc64ef4ce63176d038946d29972d6fdf2d6e69142abaefc97ccf7328c8972fc8cef0b3c
7
- data.tar.gz: a185ecc2feabf5fb080c00f2b754720e857c10ef7dc2a9f071ddb26ce06d20c5d085bfeb24a66cb9bfae49c5ee2baa21cfc2667c8dd34f7dc5d4d8d8732ff87f
6
+ metadata.gz: e162493fcf4a2de9eb0a68f1cf5781d40a586f6a12e6d49f379002d65dc4009a7aae5b2a5016489b71fe301e24ad587b0343b79e20846adc267f99976e766a5d
7
+ data.tar.gz: 8e74fb1c214710bc22201e59e3da2d71fc8a68dd0a6ed7e8afd8c3e1e0310736ed1a5d736ac622169899445fc3cd4e190294d67da6fa40b0a3023da3258996b8
@@ -6,7 +6,7 @@ module Infopark
6
6
  AWS_AMI_OWNER = "137112412989"
7
7
 
8
8
  class << self
9
- def gather_all(client, method, **options)
9
+ def gather_all(client:, method:, response_key:, **options)
10
10
  unless block_given?
11
11
  @gather_cache ||= {}
12
12
  cache_key = [client, method, options]
@@ -16,14 +16,13 @@ module Infopark
16
16
  result = []
17
17
  loop do
18
18
  response = retry_on_throttle { client.send(method, **options) }
19
- key = (response.members - [:next_token, :failures]).first
20
19
  if response.members.include?(:failures) && !response.failures.empty?
21
20
  raise "Failed gathering all #{method}: #{response.failures}"
22
21
  end
23
22
  if block_given?
24
- response[key].each {|entity| retry_on_throttle { yield entity } }
23
+ response[response_key].each {|entity| retry_on_throttle { yield entity } }
25
24
  else
26
- result += response[key]
25
+ result += response[response_key]
27
26
  end
28
27
  unless options[:next_token] = response.members.include?(:next_token) && response.next_token
29
28
  break
@@ -110,18 +110,22 @@ class Env
110
110
  else
111
111
  raise "invalid root_device_type: #{root_device_type}"
112
112
  end
113
- available_images = AwsUtils.gather_all(ec2, :describe_images,
114
- owners: [AWS_AMI_OWNER],
115
- filters: [
116
- {name: "root-device-type", values: root_device_filter_value},
117
- {name: "ena-support", values: ["true"]},
118
- {name: "image-type", values: ["machine"]},
119
- {name: "virtualization-type", values: ["hvm"]},
120
- ])
121
- .reject {|image| image.name.include?(".rc-") }
122
- .reject {|image| image.name.include?("-minimal-") }
123
- .reject {|image| image.name.include?("-test") }
124
- .reject {|image| image.name.include?("amzn-ami-vpc-nat-") }
113
+ available_images = AwsUtils.gather_all(
114
+ client: ec2,
115
+ method: :describe_images,
116
+ response_key: :image_details,
117
+ owners: [AWS_AMI_OWNER],
118
+ filters: [
119
+ {name: "root-device-type", values: root_device_filter_value},
120
+ {name: "ena-support", values: ["true"]},
121
+ {name: "image-type", values: ["machine"]},
122
+ {name: "virtualization-type", values: ["hvm"]},
123
+ ],
124
+ )
125
+ .reject {|image| image.name.include?(".rc-") }
126
+ .reject {|image| image.name.include?("-minimal-") }
127
+ .reject {|image| image.name.include?("-test") }
128
+ .reject {|image| image.name.include?("amzn-ami-vpc-nat-") }
125
129
  (reject_image_name_patterns || []).each do |pattern|
126
130
  available_images.reject! {|image| image.name =~ pattern }
127
131
  end
@@ -129,12 +133,22 @@ class Env
129
133
  end
130
134
 
131
135
  def find_image_by_id(id)
132
- AwsUtils.gather_all(ec2, :describe_images, image_ids: [id]).first
136
+ AwsUtils.gather_all(
137
+ client: ec2,
138
+ method: :describe_images,
139
+ response_key: :image_details,
140
+ image_ids: [id],
141
+ ).first
133
142
  end
134
143
 
135
144
  def find_image_by_name(name)
136
- AwsUtils.gather_all(ec2, :describe_images, owners: [DEV_ACCOUNT_ID],
137
- filters: [{name: "name", values: [name]}]).first
145
+ AwsUtils.gather_all(
146
+ client: ec2,
147
+ method: :describe_images,
148
+ response_key: :image_details,
149
+ owners: [DEV_ACCOUNT_ID],
150
+ filters: [{name: "name", values: [name]}],
151
+ ).first
138
152
  end
139
153
 
140
154
  private
@@ -1,5 +1,5 @@
1
1
  module Infopark
2
2
  module AwsUtils
3
- VERSION = "0.8.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark-aws_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilo Prütz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-12 00:00:00.000000000 Z
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-applicationautoscaling
@@ -200,8 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  requirements: []
203
- rubyforge_project:
204
- rubygems_version: 2.6.13
203
+ rubygems_version: 3.0.3
205
204
  signing_key:
206
205
  specification_version: 4
207
206
  summary: A utility lib to ease the use of the AWS SDK