infopark-aws_utils 0.1.1 → 0.2.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
2
  SHA1:
3
- metadata.gz: 4a0a126ad819e08ba69be679b4a22a37bd49dd9d
4
- data.tar.gz: b64542e28b091da7e59472720ff3911390e7f3f6
3
+ metadata.gz: df988677926dfd832032075922d5d8bcede5a1ee
4
+ data.tar.gz: 1adf0b273559efbf4a60014e3d84f6bda1e8f0ab
5
5
  SHA512:
6
- metadata.gz: 1e5d3675484ee47605025d6be28c66acaf4f849effe1efbc4b59424da8d8a464371ee159a5df6da088ab86d858085f83bd61faf78801647b161f56e0f4d517cf
7
- data.tar.gz: 26f575cd4de6b834565c7963792459434bf7d5d3d43939fb134cedcb36f8b5a88ce0a5be520492a1306d33ee0b1227056588e1b7f83076a3a156499cb79c08ff
6
+ metadata.gz: 707983d4bada5d538aa8bf99813b9f0e6e5520f65bda7826cd41d6186012d29bd6c81ec3d1029e2589ff6342ca08e5425f8908aa47842b9f27b39cc5be46b208
7
+ data.tar.gz: 8f972279c09fb09f5d4906c5bc52d5a55475cd0eb577a8a547d8ba9d1d92eea5534d407a1590b939d4e470a3e03e2173b4440560b0f5fd10a055699327d80851
@@ -6,6 +6,17 @@ module Infopark
6
6
  module AwsUtils
7
7
 
8
8
  class Env
9
+ class << self
10
+ def profile(name)
11
+ env_var = "AWS_#{name.upcase}_PROFILE"
12
+ profile_name = ENV[env_var] || name
13
+ new(profile_name)
14
+ rescue Aws::Errors::NoSuchProfileError
15
+ raise "AWS profile “#{profile_name}” not found."\
16
+ " Please provide the #{name} profile via #{env_var}."
17
+ end
18
+ end
19
+
9
20
  def initialize(profile_name = nil)
10
21
  @credentials = Aws::SharedCredentials.new(profile_name: profile_name)
11
22
  @clients = Hash.new do |clients, mod|
@@ -1,5 +1,5 @@
1
1
  module Infopark
2
2
  module AwsUtils
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/spec/env_spec.rb CHANGED
@@ -1,6 +1,67 @@
1
1
  RSpec.describe Infopark::AwsUtils::Env do
2
2
  subject(:env) { Infopark::AwsUtils::Env.new }
3
3
 
4
+ describe ".profile" do
5
+ let(:requested_profile) { "foo" }
6
+ let(:env_var) { "AWS_#{requested_profile.upcase}_PROFILE" }
7
+
8
+ subject { Infopark::AwsUtils::Env.profile(requested_profile) }
9
+
10
+ before do
11
+ allow(Aws::SharedCredentials).to receive(:new).with(profile_name: requested_profile).
12
+ and_return(instance_double(Aws::SharedCredentials, profile_name: requested_profile))
13
+ end
14
+
15
+ it { is_expected.to be_a(Infopark::AwsUtils::Env) }
16
+
17
+ it "uses credentials for the requested profile" do
18
+ expect(subject.ecs.config.credentials.profile_name).to eq(requested_profile)
19
+ end
20
+
21
+ context "when requested profile does not exist" do
22
+ before do
23
+ allow(Aws::SharedCredentials).to receive(:new).with(profile_name: requested_profile).
24
+ and_raise(Aws::Errors::NoSuchProfileError, "does not exist")
25
+ end
26
+
27
+ it "raises an error, asking for an environment variable specifiying the profile" do
28
+ expect {
29
+ subject
30
+ }.to raise_error("AWS profile “#{requested_profile}” not found."\
31
+ " Please provide the #{requested_profile} profile via #{env_var}.")
32
+ end
33
+ end
34
+
35
+ context "when environment variable is set" do
36
+ let(:value) { "#{requested_profile}_by_env" }
37
+
38
+ before do
39
+ allow(ENV).to receive(:[]).and_call_original
40
+ allow(ENV).to receive(:[]).with(env_var).and_return(value)
41
+ allow(Aws::SharedCredentials).to receive(:new).with(profile_name: value).
42
+ and_return(instance_double(Aws::SharedCredentials, profile_name: value))
43
+ end
44
+
45
+ it "uses credentials for this profile" do
46
+ expect(subject.ecs.config.credentials.profile_name).to eq(value)
47
+ end
48
+
49
+ context "when profile does not exist" do
50
+ before do
51
+ allow(Aws::SharedCredentials).to receive(:new).with(profile_name: value).
52
+ and_raise(Aws::Errors::NoSuchProfileError, "does not exist")
53
+ end
54
+
55
+ it "raises an error, asking for correct environment variable" do
56
+ expect {
57
+ subject
58
+ }.to raise_error("AWS profile “#{value}” not found."\
59
+ " Please provide the #{requested_profile} profile via #{env_var}.")
60
+ end
61
+ end
62
+ end
63
+ end
64
+
4
65
  describe "#account_type" do
5
66
  let(:account_id) { nil }
6
67
  let(:sts) do
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.1.1
4
+ version: 0.2.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: 2017-07-10 00:00:00.000000000 Z
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk