thor-aws 0.0.2 → 0.0.3

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: 30c282c16eec2450dd0a2fc511795c0c30a2459e
4
- data.tar.gz: 8f6c3476f1de624ff95864a301ac036858ad1530
3
+ metadata.gz: a0f0a273cc975981db6ac25ffbbc4cc560632bec
4
+ data.tar.gz: ee2f23f9dcd865d7922f37a36f9c774c737c640e
5
5
  SHA512:
6
- metadata.gz: 3ffd713c06d1b71d5a412408d854dc5701c5b1bd4a589bfdcff731d53724d45166eefcce84c278cd0ef334819a969576a6015c1d5fe49faf7fe28675c737072c
7
- data.tar.gz: cfd04a26ca4893acbe2cbe912b7770260314b1b9b8a350d0a808f20812ce649f685b22b5221e2f7010e7765f1d616e802067c7f5b8f4801e7d6987be60a2ff9d
6
+ metadata.gz: 2f05634350ac49d4eabdc50468980a22636484f5c4dc09f4dad1af0a5b6646aeb8295348d15425adad3b41c64b869eff1abc68d709261e7bdc20aa0942b05f2d
7
+ data.tar.gz: 6fc518295e8bcae5e0a393e6c5e4ff57677aa8119fb0d7535dcaa5482c88f6cadf86aeccb6bc72784c18841d7190d9ff0bd591477086d53e997168db08aa09f6
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Thor::Aws
2
2
 
3
+ [![Gem Version](https://img.shields.io/gem/v/thor-aws.svg)](http://rubygems.org/gems/thor-aws) [![Build Status](https://travis-ci.org/y13i/thor-aws.svg)](https://travis-ci.org/y13i/thor-aws)
4
+
3
5
  Thor extension for building CLI to deal with AWS.
4
6
 
5
7
  ## Installation
@@ -45,6 +47,17 @@ class MyAwsCLI < Thor
45
47
  end
46
48
  ```
47
49
 
50
+ ## Changelog
51
+
52
+ **0.0.3**: Add `--shared-credentials-path` option.
53
+
54
+ ## Testing
55
+
56
+ ```
57
+ bundle install --path vendor/bundle
58
+ bundle exec rake spec
59
+ ```
60
+
48
61
  ## Contributing
49
62
 
50
63
  1. [Fork it](https://github.com/y13i/thor-aws/fork)
@@ -9,7 +9,7 @@ module Thor::Aws
9
9
  def self.included klass
10
10
  klass.class_eval do
11
11
  class_option(:profile,
12
- desc: "Load credentials by profile name from shared credentials file (~/.aws/credentials).",
12
+ desc: "Load credentials by profile name from shared credentials file.",
13
13
  aliases: [:p],
14
14
  )
15
15
 
@@ -27,20 +27,32 @@ module Thor::Aws
27
27
  desc: "AWS region.",
28
28
  aliases: [:r],
29
29
  )
30
+
31
+ class_option(:shared_credentials_path,
32
+ desc: "AWS shared credentials path.",
33
+ )
30
34
  end
31
35
  end
32
36
 
33
37
  private
34
38
 
35
39
  def aws_configuration
36
- hash = {}
40
+ return @aws_configuration if @aws_configuration
41
+
42
+ @aws_configuration = {}
43
+
44
+ [:access_key_id, :secret_access_key, :region].each do |option|
45
+ @aws_configuration.update(option => options[option]) if options[option]
46
+ end
47
+
48
+ @aws_configuration.update(region: own_region) if @aws_configuration[:region].nil? && ENV["AWS_REGION"].nil?
37
49
 
38
- [:profile, :access_key_id, :secret_access_key, :region].each do |option|
39
- hash.update(option => options[option]) if options[option]
50
+ if [:profile, :shared_credentials_path].any?
51
+ credentials = Aws::SharedCredentials.new path: options.shared_credentials_path, profile_name: options.profile
52
+ @aws_configuration.update credentials: credentials
40
53
  end
41
54
 
42
- hash.update(region: own_region) if hash[:region].nil? && ENV["AWS_REGION"].nil?
43
- hash
55
+ @aws_configuration
44
56
  end
45
57
 
46
58
  def own_region
@@ -1,3 +1,3 @@
1
1
  module Thor::Aws
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -9,4 +9,16 @@ class MyAwsCLI < Thor
9
9
  def list
10
10
  p ec2.instances.to_a
11
11
  end
12
+
13
+ desc :showkey, "Show access key ID for testing"
14
+
15
+ def showkey
16
+ p ec2.client.config.credentials.access_key_id
17
+ end
18
+
19
+ desc :showregion, "Show region for testing"
20
+
21
+ def showregion
22
+ p ec2.client.config.region
23
+ end
12
24
  end
@@ -68,5 +68,30 @@ describe MyAwsCLI do
68
68
  it {expect {subject}.to output(/--secret-access-key/).to_stdout}
69
69
  it {expect {subject}.to output(/--region/).to_stdout}
70
70
  it {expect {subject}.to output(/--profile/).to_stdout}
71
+ it {expect {subject}.to output(/--shared-credentials-path/).to_stdout}
72
+ end
73
+
74
+ context "when invoked #showregion from shell with `--region` option" do
75
+ subject do
76
+ MyAwsCLI.new.invoke :showregion, [], {region: "ap-northeast-1"}
77
+ end
78
+
79
+ it {expect {subject}.to output(%("ap-northeast-1"\n)).to_stdout}
80
+ end
81
+
82
+ context "when invoked #showkey from shell with `--shared-credentials-path` option" do
83
+ subject do
84
+ MyAwsCLI.new.invoke :showkey, [], {shared_credentials_path: "#{__dir__}/my_credentials"}
85
+ end
86
+
87
+ it {expect {subject}.to output(%("MYAWESOMEDEFAULTACCESSKEY"\n)).to_stdout}
88
+ end
89
+
90
+ context "when invoked #showkey from shell with `--shared-credentials-path` and `--profile` option" do
91
+ subject do
92
+ MyAwsCLI.new.invoke :showkey, [], {shared_credentials_path: "#{__dir__}/my_credentials", profile: "alternate"}
93
+ end
94
+
95
+ it {expect {subject}.to output(%("MYAWESOMEALTERNATEACCESSKEY"\n)).to_stdout}
71
96
  end
72
97
  end
@@ -0,0 +1,7 @@
1
+ [default]
2
+ aws_access_key_id = MYAWESOMEDEFAULTACCESSKEY
3
+ aws_secret_access_key = ChuckNorrisCanLaunchEC2InstanceWithoutAnyCredentials
4
+
5
+ [alternate]
6
+ aws_access_key_id = MYAWESOMEALTERNATEACCESSKEY
7
+ aws_secret_access_key = ChuckNorrisNeverLaunchedSmallerInstancesThan8xlarge
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - y13i
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,6 +113,7 @@ files:
113
113
  - spec/spec_helper.rb
114
114
  - spec/thor/aws/my_aws_cli.rb
115
115
  - spec/thor/aws/my_aws_cli_spec.rb
116
+ - spec/thor/aws/my_credentials
116
117
  - spec/thor/aws_spec.rb
117
118
  - thor-aws.gemspec
118
119
  homepage: https://github.com/y13i/thor-aws
@@ -143,4 +144,5 @@ test_files:
143
144
  - spec/spec_helper.rb
144
145
  - spec/thor/aws/my_aws_cli.rb
145
146
  - spec/thor/aws/my_aws_cli_spec.rb
147
+ - spec/thor/aws/my_credentials
146
148
  - spec/thor/aws_spec.rb