infopark-aws_utils 0.2.0 → 0.3.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: df988677926dfd832032075922d5d8bcede5a1ee
4
- data.tar.gz: 1adf0b273559efbf4a60014e3d84f6bda1e8f0ab
3
+ metadata.gz: e0d43481b6e81976e5723210fe26dc970074a80c
4
+ data.tar.gz: 97dc1c25303e388d14b1a3f70a32ae8531b6e72e
5
5
  SHA512:
6
- metadata.gz: 707983d4bada5d538aa8bf99813b9f0e6e5520f65bda7826cd41d6186012d29bd6c81ec3d1029e2589ff6342ca08e5425f8908aa47842b9f27b39cc5be46b208
7
- data.tar.gz: 8f972279c09fb09f5d4906c5bc52d5a55475cd0eb577a8a547d8ba9d1d92eea5534d407a1590b939d4e470a3e03e2173b4440560b0f5fd10a055699327d80851
6
+ metadata.gz: 9ee0d9b64bf01ae484874b7542a22ac7146e0f9b5fbd14aab5a26fe5fd3b269fd78908659ad267ff5df4654a2ec673ad64f7727f6538acacf14cb0533a515df0
7
+ data.tar.gz: be02f4f16a7676df95e7a6427efdad5a408f22ec0e3d7431e09fbfc27371a48ea7b7acda52dcbfa660a6628257edcf33341920f535b8bfc446efe753a493c68a
@@ -67,7 +67,7 @@ class Env
67
67
 
68
68
  def account_type
69
69
  return "dev" if dev_account?
70
- return "prod" if account?(PROD_ACCOUNT_ID)
70
+ return "prod" if prod_account?
71
71
  raise "Could not determine account type."
72
72
  end
73
73
 
@@ -75,6 +75,10 @@ class Env
75
75
  account?(DEV_ACCOUNT_ID)
76
76
  end
77
77
 
78
+ def prod_account?
79
+ account?(PROD_ACCOUNT_ID)
80
+ end
81
+
78
82
  def latest_base_image
79
83
  available_images = AwsUtils.gather_all(ec2, :describe_images,
80
84
  owners: [AWS_AMI_OWNER],
@@ -1,5 +1,5 @@
1
1
  module Infopark
2
2
  module AwsUtils
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/spec/env_spec.rb CHANGED
@@ -1,4 +1,14 @@
1
1
  RSpec.describe Infopark::AwsUtils::Env do
2
+ let(:account_id) { nil }
3
+ let(:sts) do
4
+ Aws::STS::Client.new.tap do |client|
5
+ allow(client).to receive(:get_caller_identity)
6
+ .and_return(double(:caller_identity, account: account_id))
7
+ end
8
+ end
9
+
10
+ before { allow(Aws::STS::Client).to receive(:new).and_return(sts) }
11
+
2
12
  subject(:env) { Infopark::AwsUtils::Env.new }
3
13
 
4
14
  describe ".profile" do
@@ -63,25 +73,16 @@ RSpec.describe Infopark::AwsUtils::Env do
63
73
  end
64
74
 
65
75
  describe "#account_type" do
66
- let(:account_id) { nil }
67
- let(:sts) do
68
- instance_double(Aws::STS::Client,
69
- get_caller_identity: double(:caller_identity, account: account_id)
70
- )
71
- end
72
-
73
- before { allow(Aws::STS::Client).to receive(:new).and_return(sts) }
74
-
75
76
  subject(:account_type) { env.account_type }
76
77
 
77
78
  context "for profile in development account" do
78
- let(:account_id) { "012615398682" }
79
+ let(:account_id) { "the_dev_account" }
79
80
 
80
81
  it { is_expected.to eq("dev") }
81
82
  end
82
83
 
83
84
  context "for profile in production account" do
84
- let(:account_id) { "115379056088" }
85
+ let(:account_id) { "the_prod_account" }
85
86
 
86
87
  it { is_expected.to eq("prod") }
87
88
  end
@@ -97,6 +98,50 @@ RSpec.describe Infopark::AwsUtils::Env do
97
98
  end
98
99
  end
99
100
 
101
+ describe "#dev_account?" do
102
+ subject { env.dev_account? }
103
+
104
+ context "for development account" do
105
+ let(:account_id) { "the_dev_account" }
106
+
107
+ it { is_expected.to be true }
108
+ end
109
+
110
+ context "for production account" do
111
+ let(:account_id) { "the_prod_account" }
112
+
113
+ it { is_expected.to be false }
114
+ end
115
+
116
+ context "for some other account" do
117
+ let(:account_id) { "137112412989" }
118
+
119
+ it { is_expected.to be false }
120
+ end
121
+ end
122
+
123
+ describe "#prod_account?" do
124
+ subject { env.prod_account? }
125
+
126
+ context "for development account" do
127
+ let(:account_id) { "the_dev_account" }
128
+
129
+ it { is_expected.to be false }
130
+ end
131
+
132
+ context "for production account" do
133
+ let(:account_id) { "the_prod_account" }
134
+
135
+ it { is_expected.to be true }
136
+ end
137
+
138
+ context "for some other account" do
139
+ let(:account_id) { "137112412989" }
140
+
141
+ it { is_expected.to be false }
142
+ end
143
+ end
144
+
100
145
  [
101
146
  [:aas, Aws::ApplicationAutoScaling],
102
147
  [:alb, Aws::ElasticLoadBalancingV2],
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ ENV['INFOPARK_AWS_DEV_ACCOUNT_ID'] = 'the_dev_account'
2
+ ENV['INFOPARK_AWS_PROD_ACCOUNT_ID'] = 'the_prod_account'
3
+
1
4
  require 'infopark/aws_utils'
2
5
 
3
6
  RSpec.configure do |config|
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.2.0
4
+ version: 0.3.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-11 00:00:00.000000000 Z
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk