MovableInkAWS 2.5.0 → 2.5.1

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
  SHA256:
3
- metadata.gz: 673dc5d1f0f353ad1795ea2e27bed707c2e67571dfd1b62080c49dd91d50e1dd
4
- data.tar.gz: a85ec079fa09d003068621e092cb0268a1aa9ed2106fcf744b996f178f0562d6
3
+ metadata.gz: bf00286ca6df97b28e2721514ae975f5033f1c1645270b787acdade801895431
4
+ data.tar.gz: 18cced6b07a7ed5b683c6ccfe037aabadd6d54eb58eee399eb23cb2d0a2e152a
5
5
  SHA512:
6
- metadata.gz: 94aea2b4db39beff8cf8abf6bc5c0953855b15f3bd2d82a333b055a7e191a74702670c0a4aa9c2a5ec530f32ebe0d9c15681dd71f333f8db28914a950f0fcce8
7
- data.tar.gz: e1e34005c48e3677b18c4e88a8414f543919ccce8d35ec66710f0e01e0ac1c3172a0ff59a72e62f6fb436b19b62b6d58de184916b73b754e36e8bc995c486370
6
+ metadata.gz: d690d05079f5d2b51b87003e5de4a6322110897935e8a2a5fa387fe12a242b017ed0b6fcad3dfbd9976a50d81c22a78788009bf2c52bce25c338ad784a5aa753
7
+ data.tar.gz: 9026ea88eecfaa54abfbe18df7856d2e481279d4dd2ada91c1ed60b94a883b8cf527d402f513c24622227adb9b669bb2acbf43033a2f47b8841ba196e461ef85
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- MovableInkAWS (2.5.0)
4
+ MovableInkAWS (2.5.1)
5
5
  aws-sdk-athena (~> 1)
6
6
  aws-sdk-autoscaling (~> 1)
7
7
  aws-sdk-cloudwatch (~> 1)
@@ -23,8 +23,8 @@ GEM
23
23
  specs:
24
24
  addressable (2.7.0)
25
25
  public_suffix (>= 2.0.2, < 5.0)
26
- aws-eventstream (1.1.1)
27
- aws-partitions (1.445.0)
26
+ aws-eventstream (1.2.0)
27
+ aws-partitions (1.554.0)
28
28
  aws-sdk-athena (1.37.0)
29
29
  aws-sdk-core (~> 3, >= 3.112.0)
30
30
  aws-sigv4 (~> 1.1)
@@ -34,9 +34,9 @@ GEM
34
34
  aws-sdk-cloudwatch (1.51.0)
35
35
  aws-sdk-core (~> 3, >= 3.112.0)
36
36
  aws-sigv4 (~> 1.1)
37
- aws-sdk-core (3.114.0)
37
+ aws-sdk-core (3.126.1)
38
38
  aws-eventstream (~> 1, >= 1.0.2)
39
- aws-partitions (~> 1, >= 1.239.0)
39
+ aws-partitions (~> 1, >= 1.525.0)
40
40
  aws-sigv4 (~> 1.1)
41
41
  jmespath (~> 1.0)
42
42
  aws-sdk-ec2 (1.234.0)
@@ -67,11 +67,11 @@ GEM
67
67
  aws-sdk-ssm (1.108.0)
68
68
  aws-sdk-core (~> 3, >= 3.112.0)
69
69
  aws-sigv4 (~> 1.1)
70
- aws-sigv4 (1.2.3)
70
+ aws-sigv4 (1.4.0)
71
71
  aws-eventstream (~> 1, >= 1.0.2)
72
72
  crack (0.4.3)
73
73
  safe_yaml (~> 1.0.0)
74
- deep_merge (1.2.1)
74
+ deep_merge (1.2.2)
75
75
  diff-lcs (1.3)
76
76
  diplomat (2.4.2)
77
77
  deep_merge (~> 1.0, >= 1.0.1)
@@ -82,7 +82,7 @@ GEM
82
82
  httparty (0.16.3)
83
83
  mime-types (~> 3.0)
84
84
  multi_xml (>= 0.5.2)
85
- jmespath (1.4.0)
85
+ jmespath (1.6.0)
86
86
  mime-types (3.3.1)
87
87
  mime-types-data (~> 3.2015)
88
88
  mime-types-data (3.2021.0225)
@@ -117,4 +117,4 @@ DEPENDENCIES
117
117
  webmock
118
118
 
119
119
  BUNDLED WITH
120
- 2.1.3
120
+ 2.1.4
@@ -1,4 +1,5 @@
1
1
  require 'net/http'
2
+ require 'json'
2
3
 
3
4
  module MovableInk
4
5
  class AWS
@@ -12,10 +13,10 @@ module MovableInk
12
13
  end
13
14
  end
14
15
 
15
- def retrieve_metadata(key, tries: 3)
16
+ def retrieve_data(url, tries: 3)
16
17
  tries.times do |num|
17
18
  num += 1
18
- request = Net::HTTP::Get.new("/latest/meta-data/#{key}")
19
+ request = Net::HTTP::Get.new(url)
19
20
  request['X-aws-ec2-metadata-token'] = imds_token
20
21
  response = http(timeout_seconds: num * 3).request(request)
21
22
  return response.body
@@ -26,6 +27,20 @@ module MovableInk
26
27
  raise MovableInk::AWS::Errors::MetadataTimeout
27
28
  end
28
29
 
30
+ def retrieve_metadata(key, tries: 3)
31
+ retrieve_data("/latest/meta-data/#{key}", tries: tries)
32
+ end
33
+
34
+ def retrieve_dynamicdata(key, tries: 3)
35
+ retrieve_data("/latest/dynamic/#{key}", tries: tries)
36
+ end
37
+
38
+ def instance_identity_document
39
+ @instance_identity_document ||= JSON.parse(retrieve_dynamicdata('instance-identity/document'))
40
+ rescue JSON::ParserError
41
+ return
42
+ end
43
+
29
44
  def availability_zone
30
45
  @availability_zone ||= retrieve_metadata('placement/availability-zone')
31
46
  end
@@ -1,5 +1,5 @@
1
1
  module MovableInk
2
2
  class AWS
3
- VERSION = '2.5.0'
3
+ VERSION = '2.5.1'
4
4
  end
5
5
  end
@@ -15,6 +15,19 @@ describe MovableInk::AWS::Metadata do
15
15
  expect{ aws.availability_zone }.to raise_error(MovableInk::AWS::Errors::MetadataTimeout)
16
16
  end
17
17
 
18
+ it 'should raise an error if the metadata service times out on getting dynamic data' do
19
+ aws = MovableInk::AWS.new
20
+ # stub an error making a request to the metadata api
21
+ stub_request(:put, 'http://169.254.169.254/latest/api/token').to_raise(Net::OpenTimeout)
22
+ expect{ aws.instance_identity_document }.to raise_error(MovableInk::AWS::Errors::MetadataTimeout)
23
+ end
24
+
25
+ it 'should return nil if the metadata service returns unparseable dynamic data' do
26
+ aws = MovableInk::AWS.new
27
+ expect(aws).to receive(:retrieve_data).with('/latest/dynamic/instance-identity/document', {tries: 3}).and_return("something")
28
+ expect(aws.instance_identity_document).to eq(nil)
29
+ end
30
+
18
31
  it 'should raise an error if trying to load private_ipv4 outside of EC2' do
19
32
  aws = MovableInk::AWS.new
20
33
  # stub an error making a request to the metadata api
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MovableInkAWS
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Chesler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-22 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core