aws_keychain 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Ryan J. Geyer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ = aws_keychain
2
+
3
+ Stores AWS Creds and can be used to spit those creds out into useful file formats for AWS CLI tools
4
+
5
+ {<img src="https://travis-ci.org/rgeyer/aws_keychain.png" />}[https://travis-ci.org/rgeyer/aws_keychain]
6
+
7
+ == Usage
8
+
9
+ Requires a JSON input file in the following format
10
+
11
+ {
12
+ "cred-name": {
13
+ "key": "AWS Access Key",
14
+ "secret": "AWS Access Key Secret
15
+ }
16
+ }
17
+
18
+ Each cred hash can contain additional information beyond "key" and "secret" but those two are required.
19
+
20
+ Check out aws_keychain --help for specifics
21
+
22
+ == Plugins
23
+
24
+ Currently the aws_keychain includes two plugins.
25
+
26
+ === IAM Plugin
27
+
28
+ The IAM plugin will output the key and secret in the format required for an IAM credential file if you're using the IAM Cli tools.
29
+
30
+ Example
31
+
32
+ aws_keychain --keychain=/path/to/my/keychain.json --action=iam-show --output=~/iamcreds --keyname=key1
33
+
34
+
35
+ The above example will create an IAM Credential file at ~/iamcreds with the AWS key and secret found in "key1" of "keychain.json"
36
+
37
+ === JSON Plugin
38
+
39
+ The JSON plugin will usually be used simply to view the key and secret, or to consume the JSON result with another commandline tool.
40
+
41
+ Example
42
+
43
+ aws_keychain --keychain=/path/to/my/keychain.json --action=json-show --keyname=key1
44
+
45
+
46
+ The above example will print JSON to STDOUT representing the key "key1" found in "keychain.json". This will include all values that are part of the hash in the keychain.json file. I.E. Possibly more than just "key" and "secret"
47
+
48
+ == Testing
49
+
50
+ Currently, aws_keychain is bundled with plugins (see "Plugins" above). The tests make the assumption that the json plugin is available when testing the aws_keychain binary. This may change later
51
+
52
+ == TODO
53
+
54
+ * Validation of keychain data
55
+ * Maybe some encryption or protection?
56
+ * Figure out a better plugin scheme which allows them to be distributed via rubygems.
57
+
58
+ == Copyright
59
+
60
+ Copyright (c) 2012 Ryan J. Geyer. See LICENSE.txt for further details.
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (c) 2012 Ryan J. Geyer
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.
23
+
24
+ require 'trollop'
25
+ require 'logger'
26
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'aws_keychain'))
27
+
28
+ opts = Trollop::options do
29
+ banner = "Stores AWS Creds and can be used to spit those creds out into useful file formats for AWS CLI tools"
30
+
31
+ opt :keychain, "A full or relative path to your keychain file", :type => :string, :default => "aws_keychain.json"
32
+ opt :keyname, "The name of a key to perform an action with", :type => :string
33
+ opt :action, "The name of the action to perform. See --list_actions for a list of available actions", :type => :string
34
+ opt :output, "A full or relative path to a target file for the output", :type => :string
35
+ opt :list_actions, "List the available actions to perform on a key"
36
+ opt :list_keys, "Lists all of the available credentials in the keychain"
37
+ opt :quiet, "Removes any ancillary output and provides only the output of the action"
38
+ end
39
+
40
+ class SilentLogger
41
+ def method_missing(sym, *args, &block)
42
+ # Do nothing..
43
+ end
44
+ end
45
+
46
+ log = opts[:quiet] ? SilentLogger.new() : Logger.new(STDOUT)
47
+
48
+ plugins = {}
49
+ actions = []
50
+ AwsKeychain::Plugin.constants.each do |plugin_class|
51
+ plugin_class = AwsKeychain::Plugin.const_get(plugin_class)
52
+ plugin = plugin_class.new(opts)
53
+ plugins[plugin.short_name] = plugin
54
+
55
+ plugin.actions.each do |action|
56
+ actions << "#{plugin.short_name}-#{action}"
57
+ end
58
+ end
59
+
60
+ if opts[:list_actions]
61
+ log.info "All available actions listed below"
62
+ puts actions
63
+ end
64
+
65
+ # This stuff requires a valid keychain file
66
+ if opts[:action] || opts[:list_keys]
67
+ keychain = AwsKeychain::Keychain.new(:keychain_file => opts[:keychain])
68
+
69
+ if opts[:action]
70
+ matches = /^([\w]*)-(.*)$/.match(opts[:action])
71
+ unless actions.include?(opts[:action]) && matches && matches.length == 3
72
+ log.fatal "The action #{opts[:action]} is invalid, try one of the following #{actions}"
73
+ exit 1
74
+ end
75
+
76
+ # TODO: Validate that the key exists
77
+ key = keychain[opts[:keyname]]
78
+
79
+ dyn_method = plugins[matches[1]].method(matches[2])
80
+ dyn_method.call(key) do |content|
81
+ if opts[:output]
82
+ File.open(opts[:output], 'w') do |file|
83
+ log.info("Writing the output of (#{opts[:action]}) to #{opts[:output]}")
84
+ file.write(content)
85
+ end
86
+ else
87
+ log.info("Action (#{opts[:action]}) produced the following output.")
88
+ puts content
89
+ end
90
+ end
91
+ end
92
+
93
+ if opts[:list_keys]
94
+ log.info "All available keys in the keychain listed below"
95
+ puts keychain.list
96
+ end
97
+ end
@@ -0,0 +1,24 @@
1
+ # Copyright (c) 2012 Ryan J. Geyer
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require File.expand_path(File.join(File.dirname(__FILE__), 'keychain'))
23
+ glob_path = File.expand_path(File.join(File.dirname(__FILE__), 'plugins')) + '/**/*.rb'
24
+ Dir.glob(glob_path, &method(:require))
@@ -0,0 +1,61 @@
1
+ # Copyright (c) 2012 Ryan J. Geyer
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'json'
23
+
24
+ module AwsKeychain
25
+ class Keychain
26
+
27
+ attr_accessor :keychain
28
+
29
+ # Initializes a new keychain from the specified keychain file
30
+ #
31
+ # @param [Hash] options A hash of options for the class where the keys are one of
32
+ # :keychain_file relative or absolute path to a json file containing the keychain data
33
+ # :keychain_data a hash containing the keychain data where keys are the name of the credential
34
+ # and values are a hash with any keys ("key" and "secret" are required keys)
35
+ def initialize(options={})
36
+ unless options.has_key?(:keychain_file) || options.has_key?(:keychain_data)
37
+ raise ArgumentError, 'Either a keychain_file or keychain_data is required to create a new keychain class'
38
+ end
39
+
40
+ @keychain = options[:keychain_data] || JSON.parse(IO.read(options[:keychain_file]))
41
+
42
+ # TODO: Validate that the hash is correct.
43
+ end
44
+
45
+ # Lists the names of all keys in the keychain
46
+ #
47
+ # @return [Array] The names of all keys in the keychain
48
+ def list
49
+ @keychain.keys
50
+ end
51
+
52
+ # Array operator override to access keys by their name
53
+ #
54
+ # @param [String] key The string name of the key to return
55
+ # @return [Hash] The desired hash
56
+ def [](key)
57
+ @keychain[key]
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2012 Ryan J. Geyer
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module AwsKeychain
23
+ module Plugin
24
+ class Iam
25
+ def initialize(options={})
26
+
27
+ end
28
+
29
+ def actions
30
+ ["show"]
31
+ end
32
+
33
+ def short_name
34
+ "iam"
35
+ end
36
+
37
+ def show(key, &block)
38
+ yield <<EOF
39
+ AWSAccessKeyId=#{key['key']}
40
+ AWSSecretKey=#{key['secret']}
41
+ EOF
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2012 Ryan J. Geyer
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'json'
23
+
24
+ module AwsKeychain
25
+ module Plugin
26
+ class Json
27
+ def initialize(options={})
28
+
29
+ end
30
+
31
+ def actions
32
+ ["show"]
33
+ end
34
+
35
+ def short_name
36
+ "json"
37
+ end
38
+
39
+ def show(key, &block)
40
+ yield JSON.pretty_generate(key)
41
+ end
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws_keychain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan J. Geyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: trollop
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.16'
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: '1.16'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.7'
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: '1.7'
46
+ description: Stores AWS Creds and can be used to spit those creds out into useful
47
+ file formats for AWS CLI tools
48
+ email: me@ryangeyer.com
49
+ executables:
50
+ - aws_keychain
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/aws_keychain.rb
55
+ - lib/keychain.rb
56
+ - lib/plugins/iam/aws_keychain_plugin_iam.rb
57
+ - lib/plugins/json/aws_keychain_plugin_json.rb
58
+ - bin/aws_keychain
59
+ - LICENSE.txt
60
+ - README.rdoc
61
+ homepage: https://github.com/rgeyer/aws_keychain
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ segments:
75
+ - 0
76
+ hash: 2110839313982916612
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ segments:
84
+ - 0
85
+ hash: 2110839313982916612
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.23
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Stores AWS Creds and can be used to spit those creds out into useful file
92
+ formats for AWS CLI tools
93
+ test_files: []