MovableInkAWS 1.0.17 → 1.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4563a27230a7711f44768ef561751a2366e03195de236dfb18a29bbff559c78b
4
- data.tar.gz: b42568ac0c14f98d09420d4c2819b58eb047be5c31ca9a2e576c61685f69445b
3
+ metadata.gz: 7cefbe8ebb6f26b75ebbd79c72c54bee43338f21eabfe3402bdcd9496c66bbf4
4
+ data.tar.gz: 6fa2f605910e9cd4afbb1286a769f7ad6307ce0be94ba2933e2e567ef6cffd33
5
5
  SHA512:
6
- metadata.gz: e9d9d52abbe8c75ce57a6cbd4165ea5188341106c4cf79cdc49fb96b9eda8db2b1e2216b948c750867c6333a9d29c682ef12084fd75186619b29d435606a99b7
7
- data.tar.gz: c956e15226b703d33fdf7d74b367dac8259106cea459f5ca00ddfbe7fd05b17ccca18bdee22bde39c697370c7fb33ddd1ddf6210141efeea329f35b23f0a95c8
6
+ metadata.gz: 6ddba12e6beb952a764278aee29ed2e050f16d102b472acdc6bee2c93452516cb5022c3ff6763f39366bd6baaf06719fee29e697fe0f894e93a58e8c91f80da0
7
+ data.tar.gz: 4dc568a16f612ef6cc0afdbcd2842ef3a73b3224d0ad395655e7cf407d20ab209d17878c92e4415db71c8cdaa2f9cc6c580ac423a6be8093074c4c2ef2bfd860
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- MovableInkAWS (1.0.17)
4
+ MovableInkAWS (1.1.6)
5
5
  aws-sdk-athena (~> 1)
6
6
  aws-sdk-autoscaling (~> 1)
7
7
  aws-sdk-cloudwatch (~> 1)
@@ -20,48 +20,48 @@ GEM
20
20
  remote: https://rubygems.org/
21
21
  specs:
22
22
  aws-eventstream (1.1.0)
23
- aws-partitions (1.322.0)
24
- aws-sdk-athena (1.26.0)
25
- aws-sdk-core (~> 3, >= 3.71.0)
23
+ aws-partitions (1.351.0)
24
+ aws-sdk-athena (1.30.0)
25
+ aws-sdk-core (~> 3, >= 3.99.0)
26
26
  aws-sigv4 (~> 1.1)
27
- aws-sdk-autoscaling (1.37.0)
28
- aws-sdk-core (~> 3, >= 3.71.0)
27
+ aws-sdk-autoscaling (1.44.0)
28
+ aws-sdk-core (~> 3, >= 3.99.0)
29
29
  aws-sigv4 (~> 1.1)
30
- aws-sdk-cloudwatch (1.38.0)
31
- aws-sdk-core (~> 3, >= 3.71.0)
30
+ aws-sdk-cloudwatch (1.42.0)
31
+ aws-sdk-core (~> 3, >= 3.99.0)
32
32
  aws-sigv4 (~> 1.1)
33
- aws-sdk-core (3.97.0)
33
+ aws-sdk-core (3.104.3)
34
34
  aws-eventstream (~> 1, >= 1.0.2)
35
35
  aws-partitions (~> 1, >= 1.239.0)
36
36
  aws-sigv4 (~> 1.1)
37
37
  jmespath (~> 1.0)
38
- aws-sdk-ec2 (1.164.0)
39
- aws-sdk-core (~> 3, >= 3.71.0)
38
+ aws-sdk-ec2 (1.182.0)
39
+ aws-sdk-core (~> 3, >= 3.99.0)
40
40
  aws-sigv4 (~> 1.1)
41
- aws-sdk-elasticache (1.35.0)
42
- aws-sdk-core (~> 3, >= 3.71.0)
41
+ aws-sdk-elasticache (1.40.0)
42
+ aws-sdk-core (~> 3, >= 3.99.0)
43
43
  aws-sigv4 (~> 1.1)
44
- aws-sdk-kms (1.32.0)
45
- aws-sdk-core (~> 3, >= 3.71.0)
44
+ aws-sdk-kms (1.36.0)
45
+ aws-sdk-core (~> 3, >= 3.99.0)
46
46
  aws-sigv4 (~> 1.1)
47
- aws-sdk-rds (1.85.0)
48
- aws-sdk-core (~> 3, >= 3.71.0)
47
+ aws-sdk-rds (1.95.0)
48
+ aws-sdk-core (~> 3, >= 3.99.0)
49
49
  aws-sigv4 (~> 1.1)
50
- aws-sdk-route53 (1.35.0)
51
- aws-sdk-core (~> 3, >= 3.71.0)
50
+ aws-sdk-route53 (1.40.0)
51
+ aws-sdk-core (~> 3, >= 3.99.0)
52
52
  aws-sigv4 (~> 1.1)
53
- aws-sdk-s3 (1.67.0)
54
- aws-sdk-core (~> 3, >= 3.96.1)
53
+ aws-sdk-s3 (1.75.0)
54
+ aws-sdk-core (~> 3, >= 3.104.1)
55
55
  aws-sdk-kms (~> 1)
56
56
  aws-sigv4 (~> 1.1)
57
- aws-sdk-sns (1.24.0)
58
- aws-sdk-core (~> 3, >= 3.71.0)
57
+ aws-sdk-sns (1.29.0)
58
+ aws-sdk-core (~> 3, >= 3.99.0)
59
59
  aws-sigv4 (~> 1.1)
60
- aws-sdk-ssm (1.79.0)
61
- aws-sdk-core (~> 3, >= 3.71.0)
60
+ aws-sdk-ssm (1.86.0)
61
+ aws-sdk-core (~> 3, >= 3.99.0)
62
62
  aws-sigv4 (~> 1.1)
63
- aws-sigv4 (1.1.4)
64
- aws-eventstream (~> 1.0, >= 1.0.2)
63
+ aws-sigv4 (1.2.1)
64
+ aws-eventstream (~> 1, >= 1.0.2)
65
65
  diff-lcs (1.3)
66
66
  httparty (0.16.3)
67
67
  mime-types (~> 3.0)
@@ -75,15 +75,15 @@ GEM
75
75
  rspec-core (~> 3.9.0)
76
76
  rspec-expectations (~> 3.9.0)
77
77
  rspec-mocks (~> 3.9.0)
78
- rspec-core (3.9.0)
79
- rspec-support (~> 3.9.0)
80
- rspec-expectations (3.9.0)
78
+ rspec-core (3.9.2)
79
+ rspec-support (~> 3.9.3)
80
+ rspec-expectations (3.9.2)
81
81
  diff-lcs (>= 1.2.0, < 2.0)
82
82
  rspec-support (~> 3.9.0)
83
- rspec-mocks (3.9.0)
83
+ rspec-mocks (3.9.1)
84
84
  diff-lcs (>= 1.2.0, < 2.0)
85
85
  rspec-support (~> 3.9.0)
86
- rspec-support (3.9.0)
86
+ rspec-support (3.9.3)
87
87
 
88
88
  PLATFORMS
89
89
  ruby
@@ -93,4 +93,4 @@ DEPENDENCIES
93
93
  rspec (~> 3.6)
94
94
 
95
95
  BUNDLED WITH
96
- 1.17.3
96
+ 2.1.3
@@ -1,4 +1,5 @@
1
1
  require_relative 'aws/errors'
2
+ require_relative 'aws/metadata'
2
3
  require_relative 'aws/ec2'
3
4
  require_relative 'aws/sns'
4
5
  require_relative 'aws/autoscaling'
@@ -13,6 +14,7 @@ require 'aws-sdk-cloudwatch'
13
14
 
14
15
  module MovableInk
15
16
  class AWS
17
+ include Metadata
16
18
  include EC2
17
19
  include SNS
18
20
  include Autoscaling
@@ -61,6 +63,7 @@ module MovableInk
61
63
  Aws::EC2::Errors::ResourceAlreadyAssociated,
62
64
  Aws::EC2::Errors::Unavailable,
63
65
  Aws::SNS::Errors::ThrottledException,
66
+ Aws::AutoScaling::Errors::Throttling,
64
67
  Aws::AutoScaling::Errors::ThrottledException,
65
68
  Aws::S3::Errors::SlowDown,
66
69
  Aws::Route53::Errors::Throttling,
@@ -68,6 +71,7 @@ module MovableInk
68
71
  Aws::Route53::Errors::PriorRequestNotComplete,
69
72
  Aws::Route53::Errors::ServiceUnavailable,
70
73
  Aws::SSM::Errors::TooManyUpdates,
74
+ Aws::SSM::Errors::ThrottlingException,
71
75
  Aws::Athena::Errors::ThrottlingException,
72
76
  MovableInk::AWS::Errors::NoEnvironmentTagError
73
77
  sleep_time = (num+1)**2 + rand(10)
@@ -93,14 +97,6 @@ module MovableInk
93
97
  self.class.regions
94
98
  end
95
99
 
96
- def availability_zone
97
- @availability_zone ||= begin
98
- az = `ec2metadata --availability-zone 2>/dev/null`.chomp
99
- raise(MovableInk::AWS::Errors::EC2Required) if az.empty?
100
- az
101
- end
102
- end
103
-
104
100
  def my_region
105
101
  @my_region ||= availability_zone.chop
106
102
  end
@@ -63,14 +63,6 @@ module MovableInk
63
63
  end
64
64
  end
65
65
 
66
- def instance_id
67
- @instance_id ||= begin
68
- id = `ec2metadata --instance-id 2>/dev/null`.chomp
69
- raise(MovableInk::AWS::Errors::EC2Required) if id.empty?
70
- id
71
- end
72
- end
73
-
74
66
  def instance_tags
75
67
  @instance_tags ||= run_with_backoff(quiet: true) do
76
68
  ec2.describe_tags({
@@ -79,14 +71,6 @@ module MovableInk
79
71
  end
80
72
  end
81
73
 
82
- def private_ipv4
83
- @ipv4 ||= begin
84
- ipv4 = `ec2metadata --local-ipv4 2>/dev/null`.chomp
85
- raise(MovableInk::AWS::Errors::EC2Required) if ipv4.empty?
86
- ipv4
87
- end
88
- end
89
-
90
74
  def me
91
75
  @me ||= all_instances.select{|instance| instance.instance_id == instance_id}.first rescue nil
92
76
  end
@@ -98,7 +82,7 @@ module MovableInk
98
82
  name: 'tag:mi:roles',
99
83
  values: roles
100
84
  })
101
- instances = load_all_instances(my_region, filter: filter)
85
+ instances = load_all_instances(region, filter: filter)
102
86
  else
103
87
  instances = all_instances(region: region).select { |instance|
104
88
  instance.tags.select{ |tag| tag.key == 'mi:roles' }.detect { |tag|
@@ -127,15 +111,15 @@ module MovableInk
127
111
  end
128
112
 
129
113
  def statsd_host
130
- instance_ip_addresses_by_role(role: 'statsd', availability_zone: availability_zone).sample
114
+ instance_ip_addresses_by_role(role: 'statsd', availability_zone: availability_zone, use_cache: false).sample
131
115
  end
132
116
 
133
117
  def private_ip_addresses(instances)
134
118
  instances.map(&:private_ip_address)
135
119
  end
136
120
 
137
- def instance_ip_addresses_by_role(role:, exclude_roles: [], region: my_region, availability_zone: nil, exact_match: false)
138
- private_ip_addresses(instances(role: role, exclude_roles: exclude_roles, region: region, availability_zone: availability_zone, exact_match: exact_match))
121
+ def instance_ip_addresses_by_role(role:, exclude_roles: [], region: my_region, availability_zone: nil, exact_match: false, use_cache: true)
122
+ private_ip_addresses(instances(role: role, exclude_roles: exclude_roles, region: region, availability_zone: availability_zone, exact_match: exact_match, use_cache: use_cache))
139
123
  end
140
124
 
141
125
  def instance_ip_addresses_by_role_ordered(role:, exclude_roles: [], region: my_region, exact_match: false)
@@ -0,0 +1,62 @@
1
+ require 'net/http'
2
+
3
+ module MovableInk
4
+ class AWS
5
+ module Metadata
6
+ def http
7
+ @http ||= begin
8
+ http = Net::HTTP.new("169.254.169.254", 80)
9
+ http.open_timeout = 1
10
+ http.read_timeout = 1
11
+ http
12
+ end
13
+ end
14
+
15
+ def retrieve_metadata(key)
16
+ request = Net::HTTP::Get.new("/latest/meta-data/#{key}")
17
+ request['X-aws-ec2-metadata-token'] = imds_token
18
+ response = http.request(request)
19
+ response.body
20
+ rescue
21
+ ""
22
+ end
23
+
24
+ def availability_zone
25
+ @availability_zone ||= begin
26
+ az = retrieve_metadata('placement/availability-zone')
27
+ raise(MovableInk::AWS::Errors::EC2Required) if az.empty?
28
+ az
29
+ end
30
+ end
31
+
32
+ def instance_id
33
+ @instance_id ||= begin
34
+ id = retrieve_metadata('instance-id')
35
+ raise(MovableInk::AWS::Errors::EC2Required) if id.empty?
36
+ id
37
+ end
38
+ end
39
+
40
+ def private_ipv4
41
+ @ipv4 ||= begin
42
+ ipv4 = retrieve_metadata('local-ipv4')
43
+ raise(MovableInk::AWS::Errors::EC2Required) if ipv4.empty?
44
+ ipv4
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def imds_token
51
+ begin
52
+ request = Net::HTTP::Put.new('/latest/api/token')
53
+ request['X-aws-ec2-metadata-token-ttl-seconds'] = 120
54
+ response = http.request(request)
55
+ response.body
56
+ rescue
57
+ nil
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,5 +1,5 @@
1
1
  module MovableInk
2
2
  class AWS
3
- VERSION = '1.0.17'
3
+ VERSION = '1.1.6'
4
4
  end
5
5
  end
@@ -2,15 +2,6 @@ require_relative '../lib/movable_ink/aws'
2
2
 
3
3
  describe MovableInk::AWS do
4
4
  context "outside EC2" do
5
- it "should raise an error if EC2 is required" do
6
- aws = MovableInk::AWS.new
7
- allow(aws).to receive(:`).with('ec2metadata --instance-id 2>/dev/null').and_return("")
8
- allow(aws).to receive(:`).with('ec2metadata --availability-zone 2>/dev/null').and_return("")
9
-
10
- expect{ aws.instance_id }.to raise_error(MovableInk::AWS::Errors::EC2Required)
11
- expect{ aws.availability_zone }.to raise_error(MovableInk::AWS::Errors::EC2Required)
12
- end
13
-
14
5
  it 'doesnt raise an error if instance_id is set' do
15
6
  aws = MovableInk::AWS.new(instance_id: 'i-987654321')
16
7
  expect(aws.instance_id).to eq('i-987654321')
@@ -18,21 +9,9 @@ describe MovableInk::AWS do
18
9
  end
19
10
 
20
11
  context "inside EC2" do
21
- it "should call ec2metadata to get the instance ID" do
22
- aws = MovableInk::AWS.new
23
- expect(aws).to receive(:`).with('ec2metadata --instance-id 2>/dev/null').and_return("i-12345\n")
24
- expect(aws.instance_id).to eq('i-12345')
25
- end
26
-
27
- it "should call ec2metadata to get the availability zone" do
28
- aws = MovableInk::AWS.new
29
- expect(aws).to receive(:`).with('ec2metadata --availability-zone 2>/dev/null').and_return("us-east-1a\n")
30
- expect(aws.availability_zone).to eq('us-east-1a')
31
- end
32
-
33
12
  it "should find the datacenter by region" do
34
13
  aws = MovableInk::AWS.new
35
- expect(aws).to receive(:`).with('ec2metadata --availability-zone 2>/dev/null').and_return("us-east-1a\n")
14
+ expect(aws).to receive(:retrieve_metadata).with('placement/availability-zone').and_return("us-east-1a")
36
15
  expect(aws.datacenter).to eq('iad')
37
16
  end
38
17
 
@@ -4,17 +4,11 @@ describe MovableInk::AWS::EC2 do
4
4
  context "outside EC2" do
5
5
  it "should raise an error if trying to load mi_env outside of EC2" do
6
6
  aws = MovableInk::AWS.new
7
- allow(aws).to receive(:`).with('ec2metadata --instance-id 2>/dev/null').and_return("")
8
- allow(aws).to receive(:`).with('ec2metadata --availability-zone 2>/dev/null').and_return("")
7
+ allow(aws).to receive(:retrieve_metadata).with('instance-id').and_return("")
8
+ allow(aws).to receive(:retrieve_metadata).with('placement/availability-zone').and_return("")
9
9
  expect{ aws.mi_env }.to raise_error(MovableInk::AWS::Errors::EC2Required)
10
10
  end
11
11
 
12
- it 'should raise an error if trying to load private_ipv4 outside of EC2' do
13
- aws = MovableInk::AWS.new
14
- allow(aws).to receive(:`).with('ec2metadata --local-ipv4 2>/dev/null').and_return('')
15
- expect{ aws.private_ipv4 }.to raise_error(MovableInk::AWS::Errors::EC2Required)
16
- end
17
-
18
12
  it "should use the provided environment" do
19
13
  aws = MovableInk::AWS.new(environment: 'test')
20
14
  expect(aws.mi_env).to eq('test')
@@ -67,12 +61,6 @@ describe MovableInk::AWS::EC2 do
67
61
  expect(aws.mi_env).to eq('test')
68
62
  end
69
63
 
70
- it 'calls ec2metadata to get the private ipv4 address of the instance' do
71
- aws = MovableInk::AWS.new
72
- allow(aws).to receive(:`).with('ec2metadata --local-ipv4 2>/dev/null').and_return('10.0.0.1')
73
- expect(aws.private_ipv4).to eq('10.0.0.1')
74
- end
75
-
76
64
  context 'instance_tags' do
77
65
  it 'returns the tags of the current instance' do
78
66
  ec2.stub_responses(:describe_tags, tag_data)
@@ -153,18 +141,6 @@ describe MovableInk::AWS::EC2 do
153
141
  availability_zone: availability_zone
154
142
  }
155
143
  },
156
- {
157
- tags: [
158
- {
159
- key: 'mi:roles',
160
- value: 'something_else'
161
- }
162
- ],
163
- private_ip_address: '10.0.0.3',
164
- placement: {
165
- availability_zone: availability_zone
166
- }
167
- }
168
144
  ]])
169
145
  }
170
146
 
@@ -0,0 +1,40 @@
1
+ require_relative '../lib/movable_ink/aws'
2
+
3
+ describe MovableInk::AWS::Metadata do
4
+ context 'outside ec2' do
5
+ it 'should raise an error if EC2 is required' do
6
+ aws = MovableInk::AWS.new
7
+ allow(aws).to receive(:retrieve_metadata).with('instance-id').and_return("")
8
+ allow(aws).to receive(:retrieve_metadata).with('placement/availability-zone').and_return("")
9
+
10
+ expect{ aws.instance_id }.to raise_error(MovableInk::AWS::Errors::EC2Required)
11
+ expect{ aws.availability_zone }.to raise_error(MovableInk::AWS::Errors::EC2Required)
12
+ end
13
+
14
+ it 'should raise an error if trying to load private_ipv4 outside of EC2' do
15
+ aws = MovableInk::AWS.new
16
+ allow(aws).to receive(:retrieve_metadata).with('local-ipv4').and_return('')
17
+ expect{ aws.private_ipv4 }.to raise_error(MovableInk::AWS::Errors::EC2Required)
18
+ end
19
+ end
20
+
21
+ context 'inside ec2' do
22
+ it 'calls the EC2 metadata service to get the private ipv4 address of the instance' do
23
+ aws = MovableInk::AWS.new
24
+ allow(aws).to receive(:retrieve_metadata).with('local-ipv4').and_return('10.0.0.1')
25
+ expect(aws.private_ipv4).to eq('10.0.0.1')
26
+ end
27
+
28
+ it 'calls the EC2 metadata service to get the instance ID' do
29
+ aws = MovableInk::AWS.new
30
+ expect(aws).to receive(:retrieve_metadata).with('instance-id').and_return("i-12345")
31
+ expect(aws.instance_id).to eq('i-12345')
32
+ end
33
+
34
+ it 'calls the EC2 metadata service to get the availability zone' do
35
+ aws = MovableInk::AWS.new
36
+ expect(aws).to receive(:retrieve_metadata).with('placement/availability-zone').and_return("us-east-1a")
37
+ expect(aws.availability_zone).to eq('us-east-1a')
38
+ end
39
+ end
40
+ end
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: 1.0.17
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Chesler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -212,6 +212,7 @@ files:
212
212
  - lib/movable_ink/aws/ec2.rb
213
213
  - lib/movable_ink/aws/elasticache.rb
214
214
  - lib/movable_ink/aws/errors.rb
215
+ - lib/movable_ink/aws/metadata.rb
215
216
  - lib/movable_ink/aws/route53.rb
216
217
  - lib/movable_ink/aws/s3.rb
217
218
  - lib/movable_ink/aws/sns.rb
@@ -221,6 +222,7 @@ files:
221
222
  - spec/aws_spec.rb
222
223
  - spec/ec2_spec.rb
223
224
  - spec/elasticache_spec.rb
225
+ - spec/metadata_spec.rb
224
226
  - spec/route53_spec.rb
225
227
  - spec/s3_spec.rb
226
228
  - spec/sns_spec.rb
@@ -243,8 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
245
  - !ruby/object:Gem::Version
244
246
  version: '0'
245
247
  requirements: []
246
- rubyforge_project:
247
- rubygems_version: 2.7.7
248
+ rubygems_version: 3.0.8
248
249
  signing_key:
249
250
  specification_version: 4
250
251
  summary: AWS Utility methods for MovableInk