awskeyring 0.0.1 → 0.0.2

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: 45a2721acc4cc5f198c2bf55ee253dcb9f519093
4
- data.tar.gz: 6ea5cdc339047ba1e057a46a8733d90ea5af77da
3
+ metadata.gz: 1e7e03d81e3086c6acea16f7eb514d1d52066bb5
4
+ data.tar.gz: 7af0c1e501fd4f11e331f6abec07329c997e0a47
5
5
  SHA512:
6
- metadata.gz: 0ae669db134da8e9ba7ecff535bb3e3410e6f314358a818a925761e500f3eac220f63bd740ec72906c83040357dd324495c307550f30b91a4f7aab61834a4eee
7
- data.tar.gz: 6b005ea78e4fb94f21566edc1c702d75c8e5f2308b21f8bac6fd02329332e0dbd71394d301bf2852c6f82aa2df42dc7b7ffbb6229fdd21ca9a618e90f7a15f04
6
+ metadata.gz: d067652302c5c5e43e4975c392f880d373f61ca989c644a7c2fd473bd42c0723cbfc2cd041cc12c73a3add31752155ed8dd8bf15f71beb429e1b10f84edd81a4
7
+ data.tar.gz: 8f3434517adcbdf5185c315b1f33ae250d08dd56cb74e18c7d28397a3dd828fb6ce4209c28d9d6104f0085f34bb29c4f80c47e70d358e9e4cf54857f67bfb80a
data/.rubocop.yml CHANGED
@@ -1,13 +1,6 @@
1
- Metrics/AbcSize:
2
- Max: 31
3
-
4
1
  Metrics/LineLength:
5
2
  Max: 120
6
3
 
7
- Metrics/ClassLength:
8
- Exclude:
9
- - lib/awskeyring_command.rb
10
-
11
4
  Metrics/MethodLength:
12
5
  Max: 16
13
6
 
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ os: osx
2
3
  rvm:
3
- - 2.0.0
4
- before_install: gem install bundler -v 1.11.2
4
+ - 2.3.3
5
+ before_install: gem install bundler
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,24 +1,41 @@
1
- # Contributor Code of Conduct
1
+ # Contributor Covenant Code of Conduct
2
2
 
3
- As contributors and maintainers of this project, and in the interest of
4
- fostering an open and welcoming community, we pledge to respect all people who
5
- contribute through reporting issues, posting feature requests, updating
6
- documentation, submitting pull requests or patches, and other activities.
3
+ ## Our Pledge
7
4
 
8
- We are committed to making participation in this project a harassment-free
9
- experience for everyone, regardless of level of experience, gender, gender
10
- identity and expression, sexual orientation, disability, personal appearance,
11
- body size, race, ethnicity, age, religion, or nationality.
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ education, socio-economic status, nationality, personal appearance, race,
10
+ religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
12
22
 
13
23
  Examples of unacceptable behavior by participants include:
14
24
 
15
- * The use of sexualized language or imagery
16
- * Personal attacks
17
- * Trolling or insulting/derogatory comments
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
18
28
  * Public or private harassment
19
- * Publishing other's private information, such as physical or electronic
20
- addresses, without explicit permission
21
- * Other unethical or unprofessional conduct
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
22
39
 
23
40
  Project maintainers have the right and responsibility to remove, edit, or
24
41
  reject comments, commits, code, wiki edits, issues, and other contributions
@@ -26,24 +43,31 @@ that are not aligned to this Code of Conduct, or to ban temporarily or
26
43
  permanently any contributor for other behaviors that they deem inappropriate,
27
44
  threatening, offensive, or harmful.
28
45
 
29
- By adopting this Code of Conduct, project maintainers commit themselves to
30
- fairly and consistently applying these principles to every aspect of managing
31
- this project. Project maintainers who do not follow or enforce the Code of
32
- Conduct may be permanently removed from the project team.
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
33
54
 
34
- This code of conduct applies both within project spaces and in public spaces
35
- when an individual is representing the project or its community.
55
+ ## Enforcement
36
56
 
37
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
- reported by contacting a project maintainer at tristanmorgan@users.noreply.github.com. All
58
+ reported by contacting the project team at [tristan@vibrato.com.au]. All
39
59
  complaints will be reviewed and investigated and will result in a response that
40
- is deemed necessary and appropriate to the circumstances. Maintainers are
41
- obligated to maintain confidentiality with regard to the reporter of an
42
- incident.
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
43
69
 
44
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
- version 1.3.0, available at
46
- [http://contributor-covenant.org/version/1/3/0/][version]
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
47
72
 
48
- [homepage]: http://contributor-covenant.org
49
- [version]: http://contributor-covenant.org/version/1/3/0/
73
+ [homepage]: https://www.contributor-covenant.org
data/README.md CHANGED
@@ -1,7 +1,21 @@
1
1
  # Awskeyring
2
2
 
3
+ * [![Build Status](https://travis-ci.org/vibrato/awskeyring.svg?branch=master)](https://travis-ci.org/vibrato/awskeyring)
4
+ * [![Gem Version](https://badge.fury.io/rb/awskeyring.svg)](https://badge.fury.io/rb/awskeyring)
5
+ * [![license MIT](http://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
6
+ * [![All Downloads](http://ruby-gem-downloads-badge.herokuapp.com/awskeyring?type=total)](https://rubygems.org/gems/awskeyring)
7
+ * [![Version Downloads](http://ruby-gem-downloads-badge.herokuapp.com/awskeyring?label=downloads-current-version)](https://rubygems.org/gems/awskeyring)
8
+
3
9
  Awskeyring is a small tool to manage AWS account keys in the macOS Keychain.
4
10
 
11
+ ## Motivation
12
+
13
+ The motivation of this application is to provide a local secure store of AWS
14
+ credentials using specifically in the macOS Keychain, to have them easily accessed
15
+ from the Terminal, and to provide useful functions like assuming roles.
16
+ For Enterprise environments there are better suited tools to use
17
+ like [HashiCorp Vault](https://vaultproject.io/).
18
+
5
19
  ## Installation
6
20
 
7
21
  Install it with:
@@ -10,7 +24,7 @@ Install it with:
10
24
 
11
25
  ## Usage
12
26
 
13
- The CLI is using [Thor](http://whatisthor.com) with help provided interactivly.
27
+ The CLI is using [Thor](http://whatisthor.com) with help provided interactively.
14
28
 
15
29
  Commands:
16
30
  awskeyring --version, -v # Prints the version
@@ -28,22 +42,21 @@ The CLI is using [Thor](http://whatisthor.com) with help provided interactivly.
28
42
 
29
43
  and autocomplete that can be installed with:
30
44
 
31
- $ complete -C /usr/local/bin/aws-creds aws-creds
45
+ $ complete -C /usr/local/bin/awskeyring awskeyring
32
46
 
33
- To set your environment easily the following function helps:
47
+ To set your environment easily the following bash function helps:
34
48
 
35
49
  awsenv() { eval "$(awskeyring env $1)"; }
36
50
 
37
51
  ## Development
38
52
 
39
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec awskeyring` to use the gem in this directory, ignoring other installed copies of this gem.
53
+ After checking out the repo, run `bundle update` to install dependencies. Then, run `rake` to run the tests. Run `bundle exec awskeyring` to use the gem in this directory, ignoring other installed copies of this gem.
40
54
 
41
55
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
56
 
43
57
  ## Contributing
44
58
 
45
- Bug reports and pull requests are welcome on GitHub at https://github.com/tristanmorgan/awskeyring. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
-
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vibrato/awskeyring. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
60
 
48
61
  ## License
49
62
 
data/awskeyring.gemspec CHANGED
@@ -6,11 +6,11 @@ Gem::Specification.new do |spec|
6
6
  spec.name = 'awskeyring'
7
7
  spec.version = Awskeyring::VERSION
8
8
  spec.authors = ['Tristan Morgan']
9
- spec.email = ['tristanmorgan@users.noreply.github.com']
9
+ spec.email = ['tristan@vibrato.com.au']
10
10
 
11
- spec.summary = 'Manages AWS credentials in the OS X keychain'
12
- spec.description = 'Manages AWS credentials in the OS X keychain'
13
- spec.homepage = 'https://github.com/tristanmorgan/awskeyring'
11
+ spec.summary = 'Manages AWS credentials in the macOS keychain'
12
+ spec.description = 'Manages AWS credentials in the macOS keychain'
13
+ spec.homepage = 'https://github.com/vibrato/awskeyring'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -1,3 +1,3 @@
1
1
  module Awskeyring
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
data/lib/awskeyring.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  require 'keychain'
2
2
  require 'aws-sdk-iam'
3
3
 
4
- require 'awskeyring/version'
5
-
6
4
  # Aws Key-ring logical object,
7
5
  # gives you an interface to access keychains and items.
8
6
  module Awskeyring
@@ -76,15 +74,15 @@ module Awskeyring
76
74
  )
77
75
  end
78
76
 
79
- def self.add_pair(account:, key:, secret:, token:, expiry:, role:)
80
- all_items.create(label: "session-key #{account}",
81
- account: key,
82
- password: secret,
83
- comment: "#{ROLE_PREFIX}#{role}")
84
- all_items.create(label: "session-token #{account}",
85
- account: expiry,
86
- password: token,
87
- comment: "#{ROLE_PREFIX}#{role}")
77
+ def self.add_pair(params = {})
78
+ all_items.create(label: "session-key #{params[:account]}",
79
+ account: params[:key],
80
+ password: params[:secret],
81
+ comment: "#{ROLE_PREFIX}#{params[:role]}")
82
+ all_items.create(label: "session-token #{params[:account]}",
83
+ account: params[:expiry],
84
+ password: params[:token],
85
+ comment: "#{ROLE_PREFIX}#{params[:role]}")
88
86
  end
89
87
 
90
88
  def self.get_item(account)
@@ -6,9 +6,10 @@ require 'open-uri'
6
6
  require 'thor'
7
7
 
8
8
  require_relative 'awskeyring'
9
+ require 'awskeyring/version'
9
10
 
10
11
  # AWS Key-ring command line interface.
11
- class AwskeyringCommand < Thor
12
+ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
12
13
  map %w[--version -v] => :__version
13
14
  map ['ls'] => :list
14
15
  map ['lsr'] => :list_role
@@ -22,14 +23,13 @@ class AwskeyringCommand < Thor
22
23
 
23
24
  desc 'initialise', 'Initialises a new KEYCHAIN'
24
25
  method_option :keychain, type: :string, aliases: '-n', desc: 'Name of KEYCHAIN to initialise.'
25
- def initialise
26
+ def initialise # rubocop:disable Metrics/AbcSize
26
27
  unless Awskeyring.prefs.empty?
27
28
  puts "#{Awskeyring::PREFS_FILE} exists. no need to initialise."
28
29
  exit 1
29
30
  end
30
31
 
31
- keychain ||= options[:keychain]
32
- keychain ||= ask(message: "Name for new keychain (default: 'awskeyring')")
32
+ keychain = ask_missing(existing: options[:keychain], message: "Name for new keychain (default: 'awskeyring')")
33
33
  keychain = 'awskeyring' if keychain.empty?
34
34
 
35
35
  puts 'Creating a new Keychain, you will be prompted for a password for it.'
@@ -55,7 +55,7 @@ class AwskeyringCommand < Thor
55
55
 
56
56
  desc 'env ACCOUNT', 'Outputs bourne shell environment exports for an ACCOUNT'
57
57
  def env(account = nil)
58
- account ||= ask(message: 'account name')
58
+ account = ask_missing(existing: account, message: 'account name')
59
59
  cred, temp_cred = get_valid_item_pair(account: account)
60
60
  token = temp_cred.password unless temp_cred.nil?
61
61
  put_env_string(
@@ -71,13 +71,10 @@ class AwskeyringCommand < Thor
71
71
  method_option :secret, type: :string, aliases: '-s', desc: 'AWS account secret.'
72
72
  method_option :mfa, type: :string, aliases: '-m', desc: 'AWS virtual mfa arn.'
73
73
  def add(account = nil)
74
- account ||= ask(message: 'account name')
75
- key ||= options[:key]
76
- key ||= ask(message: 'access key id')
77
- secret ||= options[:secret]
78
- secret ||= ask(message: 'secret access key', secure: true)
79
- mfa ||= options[:mfa]
80
- mfa ||= ask(message: 'mfa arn', optional: true)
74
+ account = ask_missing(existing: account, message: 'account name')
75
+ key = ask_missing(existing: options[:key], message: 'access key id')
76
+ secret = ask_missing(existing: options[:secret], message: 'secret access key', secure: true)
77
+ mfa = ask_missing(existing: options[:mfa], message: 'mfa arn', optional: true)
81
78
 
82
79
  Awskeyring.add_item(
83
80
  account: account,
@@ -91,10 +88,9 @@ class AwskeyringCommand < Thor
91
88
  desc 'add-role ROLE', 'Adds a ROLE to the keyring'
92
89
  method_option :arn, type: :string, aliases: '-a', desc: 'AWS role arn.'
93
90
  def add_role(role = nil)
94
- role ||= ask(message: 'role name')
95
- arn ||= options[:arn]
96
- arn ||= ask(message: 'role arn')
97
- account ||= ask(message: 'account', optional: true)
91
+ role = ask_missing(existing: role, message: 'role name')
92
+ arn = ask_missing(existing: options[:arn], message: 'role arn')
93
+ account = ask_missing(existing: account, message: 'account', optional: true)
98
94
 
99
95
  Awskeyring.add_role(
100
96
  role: role,
@@ -105,7 +101,7 @@ class AwskeyringCommand < Thor
105
101
 
106
102
  desc 'remove ACCOUNT', 'Removes an ACCOUNT from the keyring'
107
103
  def remove(account = nil)
108
- account ||= ask(message: 'account name')
104
+ account = ask_missing(existing: account, message: 'account name')
109
105
  cred, temp_cred = get_valid_item_pair(account: account)
110
106
  Awskeyring.delete_pair(cred, temp_cred, "# Removing account #{account}")
111
107
  end
@@ -113,7 +109,7 @@ class AwskeyringCommand < Thor
113
109
  map 'remove-role' => :remove_role
114
110
  desc 'remove-role ROLE', 'Removes a ROLE from the keyring'
115
111
  def remove_role(role = nil)
116
- role ||= ask(message: 'role name')
112
+ role = ask_missing(existing: role, message: 'role name')
117
113
  item_role = Awskeyring.get_role(role)
118
114
  Awskeyring.delete_pair(item_role, nil, "# Removing role #{role}")
119
115
  end
@@ -122,8 +118,8 @@ class AwskeyringCommand < Thor
122
118
  method_option :role, type: :string, aliases: '-r', desc: 'The ROLE to assume.'
123
119
  method_option :code, type: :string, aliases: '-c', desc: 'Virtual mfa CODE.'
124
120
  method_option :duration, type: :string, aliases: '-d', desc: 'Session DURATION in seconds.'
125
- def token(account = nil, role = nil, code = nil)
126
- account ||= ask(message: 'account name')
121
+ def token(account = nil, role = nil, code = nil) # rubocop:disable all
122
+ account = ask_missing(existing: account, message: 'account name')
127
123
  role ||= options[:role]
128
124
  code ||= options[:code]
129
125
  duration = options[:duration]
@@ -184,8 +180,8 @@ class AwskeyringCommand < Thor
184
180
  end
185
181
 
186
182
  desc 'console ACCOUNT', 'Open the AWS Console for the ACCOUNT'
187
- def console(account = nil)
188
- account ||= ask(message: 'account name')
183
+ def console(account = nil) # rubocop:disable all
184
+ account = ask_missing(existing: account, message: 'account name')
189
185
  cred, temp_cred = get_valid_item_pair(account: account)
190
186
  token = temp_cred.password unless temp_cred.nil?
191
187
 
@@ -246,17 +242,19 @@ class AwskeyringCommand < Thor
246
242
  comp_len = comp_line.split.length
247
243
  comp_len += 1 if curr == ''
248
244
 
249
- case comp_len
245
+ comp_len = 2 if prev == 'help'
246
+ comp_len = 4 if prev == 'remove-role'
247
+ print_auto_resp(curr, comp_len)
248
+ end
249
+
250
+ private
251
+
252
+ def print_auto_resp(curr, len) # rubocop:disable Metrics/AbcSize
253
+ case len
250
254
  when 2
251
255
  puts list_commands.select { |elem| elem.start_with?(curr) }.join("\n")
252
256
  when 3
253
- if prev == 'help'
254
- puts list_commands.select { |elem| elem.start_with?(curr) }.join("\n")
255
- elsif prev == 'remove-role'
256
- puts Awskeyring.list_role_names.select { |elem| elem.start_with?(curr) }.join("\n")
257
- else
258
- puts Awskeyring.list_item_names.select { |elem| elem.start_with?(curr) }.join("\n")
259
- end
257
+ puts Awskeyring.list_item_names.select { |elem| elem.start_with?(curr) }.join("\n")
260
258
  when 4
261
259
  puts Awskeyring.list_role_names.select { |elem| elem.start_with?(curr) }.join("\n")
262
260
  else
@@ -264,8 +262,6 @@ class AwskeyringCommand < Thor
264
262
  end
265
263
  end
266
264
 
267
- private
268
-
269
265
  def list_commands
270
266
  self.class.all_commands.keys.map { |elem| elem.tr('_', '-') }
271
267
  end
@@ -302,6 +298,10 @@ class AwskeyringCommand < Thor
302
298
  end
303
299
  end
304
300
 
301
+ def ask_missing(existing:, message:, secure: false, optional: false)
302
+ existing || ask(message: message, secure: secure, optional: optional)
303
+ end
304
+
305
305
  def ask(message:, secure: false, optional: false)
306
306
  if secure
307
307
  HighLine.new.ask(message.rjust(20) + ': ') { |q| q.echo = '*' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awskeyring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Morgan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-25 00:00:00.000000000 Z
11
+ date: 2018-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-iam
@@ -122,9 +122,9 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description: Manages AWS credentials in the OS X keychain
125
+ description: Manages AWS credentials in the macOS keychain
126
126
  email:
127
- - tristanmorgan@users.noreply.github.com
127
+ - tristan@vibrato.com.au
128
128
  executables:
129
129
  - awskeyring
130
130
  extensions: []
@@ -144,7 +144,7 @@ files:
144
144
  - lib/awskeyring.rb
145
145
  - lib/awskeyring/version.rb
146
146
  - lib/awskeyring_command.rb
147
- homepage: https://github.com/tristanmorgan/awskeyring
147
+ homepage: https://github.com/vibrato/awskeyring
148
148
  licenses:
149
149
  - MIT
150
150
  metadata: {}
@@ -167,5 +167,5 @@ rubyforge_project:
167
167
  rubygems_version: 2.6.12
168
168
  signing_key:
169
169
  specification_version: 4
170
- summary: Manages AWS credentials in the OS X keychain
170
+ summary: Manages AWS credentials in the macOS keychain
171
171
  test_files: []