infopark-aws_utils 0.8.0 → 0.8.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
  SHA1:
3
- metadata.gz: fd62159a173f03f500066e9abfdaa4c07ab91437
4
- data.tar.gz: 07053c3acbeeaa985256b30dbb8d8299922c0c9a
3
+ metadata.gz: 006b2100b6b073324eaca1778953e0145be0fd50
4
+ data.tar.gz: 81aef7b6cb4db98985357c06a27ac58309541b3a
5
5
  SHA512:
6
- metadata.gz: 4650e70e0480fa700d93cd1fab9393fd67cfa1fe76725a21dc69167260f82507bd1cbd0bd1121dc7e19e90408ab192453beb212e7a98b29e73774dc2a1d5f6bf
7
- data.tar.gz: 9c409dd94f8874f69fc176876bfe30b20a0a32bf4897940c4018e434a2379a5a6e1cde4e91ed05987b6d66f249e6c010044012da3407d9758eb7447c1f3134ff
6
+ metadata.gz: 32e2faf37d95a697c58fa97cbe3460cf2024e42ab098c34127ad31703cc64ef4ce63176d038946d29972d6fdf2d6e69142abaefc97ccf7328c8972fc8cef0b3c
7
+ data.tar.gz: a185ecc2feabf5fb080c00f2b754720e857c10ef7dc2a9f071ddb26ce06d20c5d085bfeb24a66cb9bfae49c5ee2baa21cfc2667c8dd34f7dc5d4d8d8732ff87f
@@ -1,14 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
4
- - 2.3
3
+ - 2.4
4
+ - 2.5
5
+ - 2.6
5
6
  script:
6
7
  - bundle exec rspec spec
7
- deploy:
8
- provider: rubygems
9
- api_key:
10
- secure: e4QeU1KKglgUR6y0kWCxGTjjhmC1Txmw4p1PiWt5Sj+dg3eSnr5PO5cCU+YsBo1fVBOhxpcZXwDk0iv8q0s3SqWbask6awXCBh9I7nnstLI5HgoR0ydS6rVsOUX7tWSPHVwHFUBL83iArHkuFRvsCZl2HQr3YecvBAQzXVc7EsPfvu1Rpfjyz3N4wWzpkItge+j5m6uX80dacOpPd9YXOMMd1qMzAB3VbySN8KUXszJL3YgMV/MAaEc4djj+s3GiPCnVjTPVdIb5ZVl0HH+LtkXfgVgxHMyDhwPflBmgg/lnYQG51DcrlHn8mNsJOO0crgqc/B6xqjAalaRLf6iBDqSdx08TulgwQeBlhuq+YWBsV7ZL39NZgZiXLU+NW9ZW9iXy1I7z0PAhHlx1JaCVpNxUlG5fGvPkvOywo368taFJaYvdiTjW+IyaPO5UwcxTlWZlR+vQD/QEc7dsIHXu9/pWxfyycZI/hSnGJwa3lOx+mnU8GZbtufWsIRqnfxM6X0BVWS2BNLlK5drluj+jt0aW8tLSiYRNSY1DuL8U2CM9p3TjeOWvgBPGGzwApBI9/2RRP/E4KtW6ms+YnjT5veXE5rz1z/WmCoyWPdVfchd9J421+QGpq8WNGxnYImug0/mZtkGNkHg0b6nRWuorao/fxWkkDstjK/tk7T0iTug=
11
- gem: cloudscopes
12
- on:
13
- tags: true
14
- repo: infopark/aws_utils
@@ -26,10 +26,21 @@ class Env
26
26
 
27
27
  def initialize(profile_name = nil)
28
28
  @credentials = Aws::SharedCredentials.new(profile_name: profile_name)
29
+ if @credentials.credentials.nil?
30
+ raise "No credentials for AWS profile “#{profile_name}” found."\
31
+ " Please provide them via ~/.aws/credentials."
32
+ end
33
+
34
+ region = Aws.shared_config.region(profile: profile_name)
35
+ if region.nil?
36
+ raise "No region for AWS profile “#{profile_name}” found."\
37
+ " Please provide them via ~/.aws/config."
38
+ end
39
+
29
40
  @clients = Hash.new do |clients, mod|
30
41
  clients[mod] = mod.const_get(:Client).new(
31
42
  credentials: @credentials,
32
- region: Aws.shared_config.region(profile: profile_name),
43
+ region: region,
33
44
  )
34
45
  end
35
46
  end
@@ -1,5 +1,5 @@
1
1
  module Infopark
2
2
  module AwsUtils
3
- VERSION = "0.8.0"
3
+ VERSION = "0.8.1"
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  RSpec.describe Infopark::AwsUtils::Env do
2
2
  let(:account_id) { nil }
3
3
  let(:sts) do
4
- Aws::STS::Client.new.tap do |client|
4
+ Aws::STS::Client.new(region: "eu-west-1").tap do |client|
5
5
  allow(client).to receive(:get_caller_identity)
6
6
  .and_return(double(:caller_identity, account: account_id))
7
7
  end
@@ -18,8 +18,16 @@ RSpec.describe Infopark::AwsUtils::Env do
18
18
  subject { Infopark::AwsUtils::Env.profile(requested_profile) }
19
19
 
20
20
  before do
21
- allow(Aws::SharedCredentials).to receive(:new).with(profile_name: requested_profile).
22
- and_return(instance_double(Aws::SharedCredentials, profile_name: requested_profile))
21
+ allow(Aws::SharedCredentials).to receive(:new).with(profile_name: requested_profile)
22
+ .and_return(
23
+ instance_double(
24
+ Aws::SharedCredentials,
25
+ profile_name: requested_profile,
26
+ credentials: instance_double(Aws::Credentials),
27
+ ),
28
+ )
29
+ allow(Aws.shared_config).to receive(:region).with(profile: requested_profile)
30
+ .and_return("eu-west-1")
23
31
  end
24
32
 
25
33
  it { is_expected.to be_a(Infopark::AwsUtils::Env) }
@@ -42,14 +50,55 @@ RSpec.describe Infopark::AwsUtils::Env do
42
50
  end
43
51
  end
44
52
 
53
+ context "when requested profile has no credentials configured" do
54
+ before do
55
+ allow(Aws::SharedCredentials).to receive(:new).with(profile_name: requested_profile)
56
+ .and_return(
57
+ instance_double(
58
+ Aws::SharedCredentials,
59
+ profile_name: requested_profile,
60
+ credentials: nil,
61
+ ),
62
+ )
63
+ end
64
+
65
+ it "raises an error, asking for the credentials to be configured" do
66
+ expect {
67
+ subject
68
+ }.to raise_error("No credentials for AWS profile “#{requested_profile}” found."\
69
+ " Please provide them via ~/.aws/credentials.")
70
+ end
71
+ end
72
+
73
+ context "when requested profile has no region configured" do
74
+ before do
75
+ allow(Aws.shared_config).to receive(:region).with(profile: requested_profile)
76
+ .and_return(nil)
77
+ end
78
+
79
+ it "raises an error, asking for the region to be configured" do
80
+ expect {
81
+ subject
82
+ }.to raise_error("No region for AWS profile “#{requested_profile}” found."\
83
+ " Please provide them via ~/.aws/config.")
84
+ end
85
+ end
86
+
45
87
  context "when environment variable is set" do
46
88
  let(:value) { "#{requested_profile}_by_env" }
47
89
 
48
90
  before do
49
91
  allow(ENV).to receive(:[]).and_call_original
50
92
  allow(ENV).to receive(:[]).with(env_var).and_return(value)
51
- allow(Aws::SharedCredentials).to receive(:new).with(profile_name: value).
52
- and_return(instance_double(Aws::SharedCredentials, profile_name: value))
93
+ allow(Aws::SharedCredentials).to receive(:new).with(profile_name: value).and_return(
94
+ instance_double(
95
+ Aws::SharedCredentials,
96
+ profile_name: value,
97
+ credentials: instance_double(Aws::Credentials),
98
+ ),
99
+ )
100
+ allow(Aws.shared_config).to receive(:region).with(profile: value)
101
+ .and_return("eu-west-1")
53
102
  end
54
103
 
55
104
  it "uses credentials for this profile" do
@@ -73,6 +122,17 @@ RSpec.describe Infopark::AwsUtils::Env do
73
122
  end
74
123
 
75
124
  describe "#account_type" do
125
+ before do
126
+ allow(Aws::SharedCredentials).to receive(:new).and_return(
127
+ instance_double(
128
+ Aws::SharedCredentials,
129
+ profile_name: "foo",
130
+ credentials: instance_double(Aws::Credentials),
131
+ ),
132
+ )
133
+ allow(Aws.shared_config).to receive(:region).and_return("eu-west-1")
134
+ end
135
+
76
136
  subject(:account_type) { env.account_type }
77
137
 
78
138
  context "for profile in development account" do
@@ -99,6 +159,17 @@ RSpec.describe Infopark::AwsUtils::Env do
99
159
  end
100
160
 
101
161
  describe "#dev_account?" do
162
+ before do
163
+ allow(Aws::SharedCredentials).to receive(:new).and_return(
164
+ instance_double(
165
+ Aws::SharedCredentials,
166
+ profile_name: "foo",
167
+ credentials: instance_double(Aws::Credentials),
168
+ ),
169
+ )
170
+ allow(Aws.shared_config).to receive(:region).and_return("eu-west-1")
171
+ end
172
+
102
173
  subject { env.dev_account? }
103
174
 
104
175
  context "for development account" do
@@ -121,6 +192,17 @@ RSpec.describe Infopark::AwsUtils::Env do
121
192
  end
122
193
 
123
194
  describe "#prod_account?" do
195
+ before do
196
+ allow(Aws::SharedCredentials).to receive(:new).and_return(
197
+ instance_double(
198
+ Aws::SharedCredentials,
199
+ profile_name: "foo",
200
+ credentials: instance_double(Aws::Credentials),
201
+ ),
202
+ )
203
+ allow(Aws.shared_config).to receive(:region).and_return("eu-west-1")
204
+ end
205
+
124
206
  subject { env.prod_account? }
125
207
 
126
208
  context "for development account" do
@@ -154,6 +236,17 @@ RSpec.describe Infopark::AwsUtils::Env do
154
236
  [:sts, Aws::STS],
155
237
  ].each do |_client, _mod|
156
238
  describe "##{_client}" do
239
+ before do
240
+ allow(Aws::SharedCredentials).to receive(:new).and_return(
241
+ instance_double(
242
+ Aws::SharedCredentials,
243
+ profile_name: "foo",
244
+ credentials: instance_double(Aws::Credentials),
245
+ ),
246
+ )
247
+ allow(Aws.shared_config).to receive(:region).and_return("eu-west-1")
248
+ end
249
+
157
250
  subject(:client) { env.send(_client) }
158
251
 
159
252
  it { is_expected.to be_a(_mod.const_get("Client")) }
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.0
4
+ version: 0.8.1
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-11 00:00:00.000000000 Z
11
+ date: 2020-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-applicationautoscaling