aws-pws 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a03403acc20edb9fa60ed98d22012063ee4388c4
4
+ data.tar.gz: 0ff585a5b11ad8e63c265f3a297623fdc3b80ab4
5
+ SHA512:
6
+ metadata.gz: 2918eb82e8836ee47481be0aeb4f5617b1236c6d853362492c9983bd52c94e55291545f94ec74dc95b588176de1458479ea2bc69766f90578d38b637cef344d1
7
+ data.tar.gz: fa074e4dd4fa9684147f21756e0cc34ec27b8ed360976f460ec11ee5ca121a0fffccabb16deea3fb8a25bf0fedaf75fff5b41d7a33b9eaf952a9015a173c294e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aws-pws.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Aptible, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # aws-pws
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/aws-pws.png)](https://rubygems.org/gems/aws-pws)
4
+ [![Build Status](https://travis-ci.org/fancyremarker/aws-pws.png?branch=master)](https://travis-ci.org/fancyremarker/aws-pws)
5
+
6
+ A password-protected CredentialProvider for AWS, built on [pws](https://github.com/janlelis/pws) and largely copied from [aws-keychain-util](https://github.com/zwily/aws-keychain-util), with an accompanying command line helper.
7
+
8
+ ## Installation
9
+
10
+ Add the following line to your application's Gemfile.
11
+
12
+ gem 'aws-pws'
13
+
14
+ And then run `bundle install`.
15
+
16
+ ## Usage
17
+
18
+ ## Installation
19
+
20
+ To install:
21
+
22
+ gem install aws-pws
23
+
24
+ ## Usage
25
+
26
+ To create your keychain:
27
+
28
+ $ aws-pws init
29
+
30
+ To add an item to your aws keychain:
31
+
32
+ $ aws-pws add
33
+
34
+ This will prompt for a friendly name, the Access Key ID, and the Secret Access Key.
35
+
36
+ To list items in the keychain:
37
+
38
+ $ aws-pws ls
39
+
40
+ To show some saved credentials:
41
+
42
+ $ aws-pws cat <name>
43
+
44
+ To emit the environment variable `export` commands that you can source into your shell:
45
+
46
+ $ aws-pws env <name>
47
+
48
+ To always load the given environment in your shell, add the following to
49
+ your .bashrc or .zshrc
50
+
51
+ source `aws-pws env <name>`
52
+
53
+ To automatically grab AWS credentials from your keychain when using the aws-sdk gem, add the following code:
54
+
55
+ AWS.config(credential_provider: AWS::PWS::CredentialProvider.new(name))
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork the project.
60
+ 1. Commit your changes, with specs.
61
+ 1. Ensure that your code passes specs (`rake`).
62
+ 1. Create a new pull request on GitHub.
63
+
64
+ ## Copyright and License
65
+
66
+ MIT License, see [LICENSE](LICENSE.md) for details.
67
+
68
+ Copyright (c) 2014 Frank Macreery and contributors.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'aptible/tasks'
4
+ Aptible::Tasks.load_tasks
data/aws-pws.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'English'
6
+ require 'aws/pws/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'aws-pws'
10
+ spec.version = AWS::PWS::VERSION
11
+ spec.authors = ['Frank Macreery']
12
+ spec.email = ['frank@macreery.com']
13
+ spec.description = 'A password-protected CredentialProvider for AWS'
14
+ spec.summary = 'A password-protected CredentialProvider for AWS'
15
+ spec.homepage = 'https://github.com/fancyremarker/aws-pws'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($RS)
19
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(/^spec\//)
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'pws'
24
+ spec.add_dependency 'aws-sdk'
25
+
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'aptible-tasks'
28
+ spec.add_development_dependency 'rake'
29
+ end
data/bin/aws-pws ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'aws/pws'
4
+
5
+ command = ARGV.shift
6
+
7
+ case command
8
+ when 'init'
9
+ pws = AWS::PWS::Client.new
10
+ pws.cli.add('AWS_ACCESS_KEY_ID')
11
+ pws.cli.add('AWS_SECRET_ACCESS_KEY')
12
+
13
+ when 'cat'
14
+ pws = AWS::PWS::StealthClient.new
15
+ puts "AWS_ACCESS_KEY_ID=#{pws.read('AWS_ACCESS_KEY_ID')}"
16
+ puts "AWS_SECRET_ACCESS_KEY=#{pws.read('AWS_SECRET_ACCESS_KEY')}"
17
+
18
+ when 'reset'
19
+ pws = AWS::PWS::Client.new
20
+ pws.cli.remove('AWS_ACCESS_KEY_ID')
21
+ pws.cli.remove('AWS_SECRET_ACCESS_KEY')
22
+
23
+ when 'env'
24
+ pws = AWS::PWS::StealthClient.new
25
+ access_key_id = pws.read('AWS_ACCESS_KEY_ID')
26
+ secret_access_key = pws.read('AWS_SECRET_ACCESS_KEY')
27
+
28
+ puts "export AWS_ACCESS_KEY_ID=\"#{access_key_id}\""
29
+ puts "export AWS_ACCESS_KEY=\"#{access_key_id}\""
30
+ puts "export AWS_SECRET_ACCESS_KEY=\"#{secret_access_key}\""
31
+ puts "export AWS_SECRET_KEY=\"#{secret_access_key}\""
32
+
33
+ else
34
+ puts "Usage: #{$PROGRAM_NAME} <command>"
35
+ puts ' Commands: init, cat, env, reset'
36
+ end
@@ -0,0 +1,19 @@
1
+ require 'pws'
2
+
3
+ module AWS
4
+ module PWS
5
+ class Client
6
+ attr_accessor :raw_data, :cli
7
+
8
+ def initialize
9
+ @cli ||= ::PWS.new({})
10
+ @raw_data = @cli.instance_variable_get(:@data)
11
+ end
12
+
13
+ def read(key)
14
+ return unless raw_data[key]
15
+ raw_data[key][:password]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'aws/pws'
2
+ require 'aws-sdk'
3
+
4
+ module AWS
5
+ module PWS
6
+ class CredentialProvider
7
+ include AWS::Core::CredentialProviders::Provider
8
+
9
+ attr_reader :client
10
+
11
+ def initialize
12
+ @client = AWS::PWS::Client.new
13
+ end
14
+
15
+ # rubocop:disable AccessorMethodName
16
+ def get_credentials
17
+ {
18
+ access_key_id: client.read('AWS_ACCESS_KEY_ID'),
19
+ secret_access_key: client.read('AWS_SECRET_ACCESS_KEY')
20
+ }
21
+ end
22
+ # rubocop:enable AccessorMethodName
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ module AWS
2
+ module PWS
3
+ module Silencer
4
+ # Override Paint method to avoid polluting `env` and `cat` output
5
+ def pa(*)
6
+ end
7
+
8
+ # Disable printing in PWS#read_safe:
9
+ # https://github.com/janlelis/pws/blob/master/lib/pws.rb#L230
10
+ def print(*)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'client'
2
+
3
+ module AWS
4
+ module PWS
5
+ class StealthClient < Client
6
+ def initialize
7
+ ::PWS.include(AWS::PWS::Silencer)
8
+
9
+ STDERR.print 'Enter PWS password: '
10
+ system 'stty -echo'
11
+ @cli = ::PWS.new(password: gets.chomp)
12
+ system 'stty echo'
13
+ STDERR.puts
14
+
15
+ super
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module AWS
2
+ module PWS
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
data/lib/aws/pws.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'aws/pws/version'
2
+ require 'aws/pws/client'
3
+ require 'aws/pws/stealth_client'
4
+ require 'aws/pws/silencer'
5
+
6
+ module AWS
7
+ module PWS
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ # Load shared spec files
5
+ Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each do |file|
6
+ require file
7
+ end
8
+
9
+ # Require library up front
10
+ require 'aws/pws'
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-pws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frank Macreery
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pws
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aptible-tasks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A password-protected CredentialProvider for AWS
84
+ email:
85
+ - frank@macreery.com
86
+ executables:
87
+ - aws-pws
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.md
96
+ - README.md
97
+ - Rakefile
98
+ - aws-pws.gemspec
99
+ - bin/aws-pws
100
+ - lib/aws/pws.rb
101
+ - lib/aws/pws/client.rb
102
+ - lib/aws/pws/credential_provider.rb
103
+ - lib/aws/pws/silencer.rb
104
+ - lib/aws/pws/stealth_client.rb
105
+ - lib/aws/pws/version.rb
106
+ - spec/spec_helper.rb
107
+ homepage: https://github.com/fancyremarker/aws-pws
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A password-protected CredentialProvider for AWS
131
+ test_files:
132
+ - spec/spec_helper.rb