opsicle 0.10.0 → 0.11.0

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
  SHA1:
3
- metadata.gz: 4e1ae90db98327bdf981f1d0fc69b7488d091a68
4
- data.tar.gz: c591e7f2567cfc9f5eb15e4f83762b29a7b54c08
3
+ metadata.gz: ab993b3d50de8fe63817cfdadf477b2226e7b988
4
+ data.tar.gz: 627593752949a28787510fcb7808fac626fe2f22
5
5
  SHA512:
6
- metadata.gz: bbebdecd44667c6f4533f3466eb2674afd75456d35f07d6c6e4cf80f134ed8866e0bcc81f8405b7ab1446a592addec81b631ad2ea0770ba634a98643e96c4049
7
- data.tar.gz: f5f7997debb53669e4ee64010a763448c16ffc282ddbe69daabe0479068370e51bfc56fe401e36b16ff5075a1a0dfc626da9b5d44db5d811cb59937e22490a5b
6
+ metadata.gz: 27dc029b0626c90206a77eb74f8e14b8a74a3b68c30d4a9d5acdfb059690354036d6fa1e7b66ffa18081f36be65f1f1ded65ddb23b4d1255b047e5a57d45f585
7
+ data.tar.gz: e573205db262222309adad4b7d30f2a7a897ed302199aa09440fbb4c72b878b0353624fb6b7c5b3541751dea8495cb23a67245754650f3f41527ebfdfe476d0a
@@ -5,7 +5,7 @@ module Opsicle
5
5
  class Config
6
6
  FOG_CONFIG_PATH = '~/.fog'
7
7
  OPSICLE_CONFIG_PATH = './.opsicle'
8
-
8
+ SESSION_DURATION = 3600
9
9
 
10
10
  attr_reader :environment
11
11
 
@@ -15,8 +15,16 @@ module Opsicle
15
15
 
16
16
  def aws_config
17
17
  return @aws_config if @aws_config
18
- fog_config = load_config(File.expand_path(FOG_CONFIG_PATH))
19
- @aws_config = { access_key_id: fog_config[:aws_access_key_id], secret_access_key: fog_config[:aws_secret_access_key] }
18
+ if fog_config[:mfa_serial_number]
19
+ @aws_config = get_session.credentials
20
+ else
21
+ @aws_config = { access_key_id: fog_config[:aws_access_key_id], secret_access_key: fog_config[:aws_secret_access_key] }
22
+ end
23
+ end
24
+
25
+ def fog_config
26
+ return @fog_config if @fog_config
27
+ @fog_config = load_config(File.expand_path(FOG_CONFIG_PATH))
20
28
  end
21
29
 
22
30
  def opsworks_config
@@ -35,6 +43,23 @@ module Opsicle
35
43
  env_config
36
44
  end
37
45
 
46
+ def get_mfa_token
47
+ Output.ask("Enter MFA token: "){ |q| q.validate = /^\d{6}$/ }
48
+ end
49
+
50
+ def get_session
51
+ return @session if @session
52
+ sts = AWS::STS.new(access_key_id: fog_config[:aws_access_key_id],
53
+ secret_access_key: fog_config[:aws_secret_access_key])
54
+ @session = sts.new_session(duration: session_duration, serial_number: fog_config[:mfa_serial_number],
55
+ token_code: get_mfa_token)
56
+ end
57
+
58
+ def session_duration
59
+ fog_config = load_config(File.expand_path(FOG_CONFIG_PATH))
60
+ fog_config[:session_duration] || SESSION_DURATION
61
+ end
62
+
38
63
  # We want all ouf our YAML loaded keys to be symbols
39
64
  # taken from http://devblog.avdi.org/2009/07/14/recursively-symbolize-keys/
40
65
  def symbolize_keys(hash)
@@ -30,8 +30,8 @@ module Opsicle
30
30
  terminal.say "<%= color('#{msg}', 'verbose') %>" if $verbose
31
31
  end
32
32
 
33
- def self.ask(*args)
34
- terminal.ask(*args)
33
+ def self.ask(*args, &block)
34
+ terminal.ask(*args, &block)
35
35
  end
36
36
  end
37
37
  end
@@ -1,3 +1,3 @@
1
1
  module Opsicle
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -40,6 +40,31 @@ module Opsicle
40
40
  end
41
41
  end
42
42
 
43
+ context "with a valid MFA config" do
44
+ before do
45
+ allow(File).to receive(:exist?).with(File.expand_path '~/.fog').and_return(true)
46
+ mock_fog = { 'derp' => { 'aws_access_key_id' => 'key', 'aws_secret_access_key' => 'secret',
47
+ 'mfa_serial_number' => 'tacos' }}
48
+ allow(YAML).to receive(:load_file).with(File.expand_path '~/.fog').and_return(mock_fog)
49
+
50
+ mock_sts = Class.new
51
+ mock_session = Class.new
52
+ mock_credentials = { access_key_id: 'key', secret_access_key: 'secret', session_token: 'cats' }
53
+ allow(mock_session).to receive(:credentials).and_return(mock_credentials)
54
+ allow(mock_sts).to receive(:new_session).and_return(mock_session)
55
+ allow(AWS::STS).to receive(:new).and_return(mock_sts)
56
+ allow(Output).to receive(:ask).and_return(123456)
57
+ end
58
+
59
+ context "#configure_aws!" do
60
+ it "should load the config into the AWS module" do
61
+ expect(AWS).to receive(:config).with(hash_including(access_key_id: 'key', secret_access_key: 'secret',
62
+ session_token: 'cats'))
63
+ subject.configure_aws!
64
+ end
65
+ end
66
+ end
67
+
43
68
  context "missing configs" do
44
69
  before do
45
70
  allow(File).to receive(:exist?).with(File.expand_path '~/.fog').and_return(false)
@@ -52,6 +77,12 @@ module Opsicle
52
77
  end
53
78
  end
54
79
 
80
+ context "#fog_config" do
81
+ it "should gracefully raise an exception if no .fog file was found" do
82
+ expect {subject.aws_config}.to raise_exception(Config::MissingConfig)
83
+ end
84
+ end
85
+
55
86
  context "#opsworks_config" do
56
87
  it "should gracefully raise an exception if no .fog file was found" do
57
88
  expect {subject.opsworks_config}.to raise_exception(Config::MissingConfig)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsicle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Fleener
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-23 00:00:00.000000000 Z
12
+ date: 2015-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -249,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
249
  version: '0'
250
250
  requirements: []
251
251
  rubyforge_project:
252
- rubygems_version: 2.2.2
252
+ rubygems_version: 2.4.2
253
253
  signing_key:
254
254
  specification_version: 4
255
255
  summary: An opsworks specific abstraction on top of the aws sdk