aws-keychain-util 0.0.1

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.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aws-keychain-util.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Zach Wily
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,56 @@
1
+ # AWS Keychain Util
2
+
3
+ This gem provides a small command line utility that helps
4
+ manage AWS credentials in an OS X keychain, keeping them out
5
+ of your dotfiles.
6
+
7
+ This will create a keychain for you which automatically locks
8
+ after 5 minutes and on sleep, for some extra security for your
9
+ precious AWS secrets.
10
+
11
+ Once you've added your credentials, you can start a shell with
12
+ the credentials in the environment.
13
+
14
+ ## Installation
15
+
16
+ To install:
17
+
18
+ gem install aws-keychain-util
19
+
20
+ ## Usage
21
+
22
+ To create your keychain:
23
+
24
+ $ aws-creds init
25
+
26
+ Here you can choose a name for your new keychain, or use the
27
+ default 'aws'.
28
+
29
+ To add an item to your aws keychain:
30
+
31
+ $ aws-creds add
32
+
33
+ This will prompt for a friendly name, the access key id,
34
+ and the secret access key.
35
+
36
+ To list items in the keychain:
37
+
38
+ $ aws-creds ls
39
+
40
+ To show some saved credentials:
41
+
42
+ $ aws-creds cat <name>
43
+
44
+ To start a shell with `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
45
+ set in the environment:
46
+
47
+ $ aws-creds shell <name>
48
+
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aws-keychain-util/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "aws-keychain-util"
8
+ gem.version = Aws::Keychain::Util::VERSION
9
+ gem.authors = ["Zach Wily"]
10
+ gem.email = ["zach@zwily.com"]
11
+ gem.description = %q{Helps manage a keychain of AWS credentials on OS X.}
12
+ gem.summary = %q{Helps manage a keychain of AWS credentials on OS X.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency('ruby-keychain')
21
+ gem.add_dependency('highline')
22
+ end
data/bin/aws-creds ADDED
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'highline'
5
+ require 'keychain'
6
+ require 'json'
7
+
8
+ def ask(question)
9
+ HighLine.new.ask(question)
10
+ end
11
+
12
+ def ask_secure(question)
13
+ HighLine.new.ask(question) { |q| q.echo = '*' }
14
+ end
15
+
16
+ PREFS_FILE = File.expand_path "~/.aws-keychain-util"
17
+
18
+ def load_keychain
19
+ unless File.exist? PREFS_FILE
20
+ puts "You have not set up aws-creds yet. To do so, run:"
21
+ puts " #{$0} init"
22
+ exit 1
23
+ end
24
+
25
+ prefs = JSON.parse(File.read(PREFS_FILE))
26
+ Keychain.open(prefs['aws_keychain_name'])
27
+ end
28
+
29
+ def get_item(name)
30
+ load_keychain.generic_passwords.where(:label => name).first
31
+ end
32
+
33
+ def get_name_from_args_for_command(command)
34
+ if ARGV.length < 1
35
+ puts "Usage: #{$0} #{command} <name>"
36
+ exit 1
37
+ end
38
+ ARGV.shift
39
+ end
40
+
41
+ def get_item_from_args_for_command(command)
42
+ name = get_name_from_args_for_command(command)
43
+ item = get_item(name)
44
+ unless item
45
+ puts "Could not find item with name #{name}"
46
+ exit 1
47
+ end
48
+ item
49
+ end
50
+
51
+ command = ARGV.shift
52
+
53
+ case command
54
+ when 'init'
55
+ if File.exist? PREFS_FILE
56
+ puts "#{PREFS_FILE} already exists. Please remove it to run init again."
57
+ exit 1
58
+ end
59
+
60
+ name = ask("Name for AWS keychain (default: 'aws'): ")
61
+ name = "aws" if keychain == ""
62
+
63
+ puts "The OS will now ask you for a password to protect your keychain. Choose wisely."
64
+ keychain = Keychain.create(name)
65
+ keychain.lock_interval = 300
66
+ keychain.lock_on_sleep = true
67
+
68
+ $prefs = { 'aws_keychain_name' => name }
69
+ File.new(PREFS_FILE, "w").write JSON.dump($prefs)
70
+
71
+ puts "Your AWS keychain has been created and configured to auto-lock after"
72
+ puts "5 minutes, and when sleeping. You can change those options in"
73
+ puts "Keychain Access."
74
+ puts
75
+ puts "You can now add accounts to the keychain with:"
76
+ puts " #{$0} add"
77
+
78
+ when 'ls'
79
+ keychain = load_keychain
80
+ keychain.generic_passwords.all.sort {|a,b|
81
+ a.attributes[:label] <=> b.attributes[:label]
82
+ }.each do |item|
83
+ puts " #{item.attributes[:label]}"
84
+ end
85
+
86
+ when 'add'
87
+ keychain = load_keychain
88
+ name = ask(" account name: ")
89
+ account = ask(" access key id: ")
90
+ password = ask_secure(" secret_access_key: ")
91
+
92
+ item = keychain.generic_passwords.create(
93
+ :label => name,
94
+ :account => account,
95
+ :password => password
96
+ )
97
+
98
+ when 'cat'
99
+ item = get_item_from_args_for_command('cat')
100
+ puts "AWS_ACCESS_KEY_ID=#{item.attributes[:account]}"
101
+ puts "AWS_SECRET_ACCESS_KEY=#{item.password}"
102
+
103
+ when 'rm'
104
+ item = get_item_from_args_for_command('rm')
105
+ item.delete
106
+
107
+ when 'shell'
108
+ if ENV['AWS_CREDS_NAME']
109
+ puts "Already in aws-creds shell (AWS_CREDS_NAME is #{ENV['AWS_CREDS_NAME']})"
110
+ exit 1
111
+ end
112
+
113
+ item = get_item_from_args_for_command('shell')
114
+ aws_env = {}
115
+ aws_env['AWS_ACCESS_KEY_ID'] = item.attributes[:account]
116
+ aws_env['AWS_SECRET_ACCESS_KEY'] = item.password
117
+ aws_env['AWS_CREDS_NAME'] = item.attributes[:label]
118
+ aws_env['RPROMPT'] = "(aws #{item.attributes[:label]})" # zsh only
119
+
120
+ exec(aws_env, ENV['SHELL'])
121
+
122
+ else
123
+ puts "Usage: #{$0} <command> <arguments>"
124
+ puts " Commands: init, ls, add, cat, rm, shell"
125
+ end
126
+
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-keychain-util
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zach Wily
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ruby-keychain
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: highline
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Helps manage a keychain of AWS credentials on OS X.
47
+ email:
48
+ - zach@zwily.com
49
+ executables:
50
+ - aws-creds
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - aws-keychain-util.gemspec
60
+ - bin/aws-creds
61
+ homepage: ''
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.23
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Helps manage a keychain of AWS credentials on OS X.
85
+ test_files: []
86
+ has_rdoc: