awskeyring 0.7.1 → 0.8.0

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: 1ebe6ee9bb5814b1566494d8be14c6b789b86721
4
- data.tar.gz: 59be7211203c6a51d309b92c66ea83d83ee6b046
3
+ metadata.gz: 3ad1f180eac2ee0404c4c8d96eb0206d4e1812de
4
+ data.tar.gz: 431a1d18c5547c6ab5f6c7f8c3b3a15ab2ca2467
5
5
  SHA512:
6
- metadata.gz: e2d948135aac4bc9b5e1b13899060934ed8333fe991587de39a50d0becb16f45c3fa53c0674e844ad6212e404f91354e0cb43dd7dbc3d3d7f3c81c2e025e436c
7
- data.tar.gz: 83844924a2145ef993f60afba15130b7f1526611419b9854ddd9e30a3295f837471ec1d4a942e361d4482347fa0b0054cb60db9baa818cc5b8e44c4ad357433c
6
+ metadata.gz: dc88bb7611ca1fe6c391e21a099a964726e87093b78278c19f972909f22a259b97af373927917df6b5a4f61d67362265dc1033914b4ddf61d30d018d7d51268f
7
+ data.tar.gz: 83132abd48684e6b58593781494a7ff43ec9c061e467a3efdbf5b68d2b066d1626999681620dc51323e7bc9e11fd5f1b4bf2d6f06b8a6c225683f859de6aa647
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.8.0](https://github.com/vibrato/awskeyring/tree/v0.8.0) (2018-12-19)
4
+ [Full Changelog](https://github.com/vibrato/awskeyring/compare/v0.7.2...v0.8.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Provide input feedback for secret fields. [\#41](https://github.com/vibrato/awskeyring/pull/41) ([tristanmorgan](https://github.com/tristanmorgan))
9
+
10
+ **Fixed bugs:**
11
+
12
+ - Cannot enter secret access key when adding new accounts in 0.7.0 [\#36](https://github.com/vibrato/awskeyring/issues/36)
13
+
14
+ ## [v0.7.2](https://github.com/vibrato/awskeyring/tree/v0.7.2) (2018-12-17)
15
+ [Full Changelog](https://github.com/vibrato/awskeyring/compare/v0.7.1...v0.7.2)
16
+
17
+ **Fixed bugs:**
18
+
19
+ - Validate that account doesn't already exists. [\#40](https://github.com/vibrato/awskeyring/pull/40) ([tristanmorgan](https://github.com/tristanmorgan))
20
+ - Check for COMMAND param to exec. [\#38](https://github.com/vibrato/awskeyring/pull/38) ([tristanmorgan](https://github.com/tristanmorgan))
21
+
3
22
  ## [v0.7.1](https://github.com/vibrato/awskeyring/tree/v0.7.1) (2018-12-03)
4
23
  [Full Changelog](https://github.com/vibrato/awskeyring/compare/v0.7.0...v0.7.1)
5
24
 
data/i18n/en.yml CHANGED
@@ -68,6 +68,7 @@ en:
68
68
  delrole: '# Removing role %{role}'
69
69
  deltoken: '# Removing token for account %{account}'
70
70
  delexpired: '# Removing expired session credentials'
71
+ exec: '# COMMAND not provided'
71
72
  missing: '# Config missing, run `%{bin} initialise` to recreate.'
72
73
  rotate: '# You have two access keys for account %{account}'
73
74
  temporary: '# Using temporary session credentials.'
data/lib/awskeyring.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'keychain'
3
+ require 'awskeyring/validate'
3
4
 
4
5
  # Awskeyring Module,
5
6
  # gives you an interface to access keychains and items.
@@ -284,8 +285,19 @@ module Awskeyring # rubocop:disable Metrics/ModuleLength
284
285
  #
285
286
  # @param [String] account_name the associated account name.
286
287
  def self.account_exists(account_name)
288
+ Awskeyring::Validate.account_name(account_name)
287
289
  raise 'Account does not exist' unless list_account_names.include?(account_name)
288
290
 
289
291
  account_name
290
292
  end
293
+
294
+ # Validate account does not exists
295
+ #
296
+ # @param [String] account_name the associated account name.
297
+ def self.account_not_exists(account_name)
298
+ Awskeyring::Validate.account_name(account_name)
299
+ raise 'Account already exists' if list_account_names.include?(account_name)
300
+
301
+ account_name
302
+ end
291
303
  end
@@ -0,0 +1,37 @@
1
+ require 'io/console'
2
+
3
+ # Awskeyring Module,
4
+ module Awskeyring
5
+ # Input methods for Awskeyring
6
+ module Input
7
+ # Read a secret in without echoing the characters
8
+ #
9
+ # @param [String] prompt text to prompt user with.
10
+ def self.read_secret(prompt)
11
+ $stdout.print(prompt)
12
+ hide_input
13
+ end
14
+
15
+ private_class_method def self.hide_input # rubocop:disable Metrics/MethodLength
16
+ password = ''
17
+ loop do
18
+ character = $stdin.getch
19
+ break unless character
20
+
21
+ if ["\n", "\r"].include? character
22
+ puts ''
23
+ break
24
+ elsif ["\b", "\u007f"].include? character
25
+ password.chop!
26
+ print "\b\e[P"
27
+ elsif character == "\u0003"
28
+ exit 1
29
+ else
30
+ print '*'
31
+ password << character
32
+ end
33
+ end
34
+ password
35
+ end
36
+ end
37
+ end
@@ -1,4 +1,4 @@
1
1
  module Awskeyring
2
2
  # The Gems version number
3
- VERSION = '0.7.1'.freeze
3
+ VERSION = '0.8.0'.freeze
4
4
  end
@@ -3,6 +3,7 @@ require 'thor'
3
3
 
4
4
  require 'awskeyring'
5
5
  require 'awskeyring/awsapi'
6
+ require 'awskeyring/input'
6
7
  require 'awskeyring/validate'
7
8
  require 'awskeyring/version'
8
9
 
@@ -70,12 +71,7 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
70
71
  existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_exists)
71
72
  )
72
73
  cred = age_check_and_get(account: account, no_token: options['no-token'])
73
- put_env_string(
74
- account: cred[:account],
75
- key: cred[:key],
76
- secret: cred[:secret],
77
- token: cred[:token]
78
- )
74
+ put_env_string(cred)
79
75
  end
80
76
 
81
77
  desc 'json ACCOUNT', I18n.t('json.desc')
@@ -99,15 +95,20 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
99
95
  method_option 'no-token', type: :boolean, aliases: '-n', desc: I18n.t('method_option.notoken'), default: false
100
96
  # execute an external command with env set
101
97
  def exec(account, *command)
98
+ if command.empty?
99
+ warn I18n.t('message.exec')
100
+ exit 1
101
+ end
102
102
  cred = age_check_and_get(account: account, no_token: options['no-token'])
103
- env_vars = env_vars(
104
- account: cred[:account],
105
- key: cred[:key],
106
- secret: cred[:secret],
107
- token: cred[:token]
108
- )
109
- pid = Process.spawn(env_vars, command.join(' '))
110
- Process.wait pid
103
+ env_vars = env_vars(cred)
104
+ begin
105
+ pid = Process.spawn(env_vars, command.join(' '))
106
+ Process.wait pid
107
+ $CHILD_STATUS
108
+ rescue Errno::ENOENT => err
109
+ warn err.to_s
110
+ exit 1
111
+ end
111
112
  end
112
113
 
113
114
  desc 'add ACCOUNT', I18n.t('add.desc')
@@ -118,7 +119,7 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
118
119
  # Add an Account
119
120
  def add(account = nil) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
120
121
  account = ask_check(
121
- existing: account, message: I18n.t('message.account'), validator: Awskeyring::Validate.method(:account_name)
122
+ existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:account_not_exists)
122
123
  )
123
124
  key = ask_check(
124
125
  existing: options[:key], message: I18n.t('message.key'), validator: Awskeyring::Validate.method(:access_key)
@@ -418,27 +419,27 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
418
419
  self.class.all_commands[command].options.values.map(&:switch_name)
419
420
  end
420
421
 
421
- def env_vars(account:, key:, secret:, token:)
422
+ def env_vars(cred)
422
423
  env_var = {}
423
424
  env_var['AWS_DEFAULT_REGION'] = 'us-east-1' unless Awskeyring::Awsapi.region
424
- env_var['AWS_ACCOUNT_NAME'] = account
425
- env_var['AWS_ACCESS_KEY_ID'] = key
426
- env_var['AWS_ACCESS_KEY'] = key
427
- env_var['AWS_SECRET_ACCESS_KEY'] = secret
428
- env_var['AWS_SECRET_KEY'] = secret
429
- if token
430
- env_var['AWS_SECURITY_TOKEN'] = token
431
- env_var['AWS_SESSION_TOKEN'] = token
425
+ env_var['AWS_ACCOUNT_NAME'] = cred[:account]
426
+ env_var['AWS_ACCESS_KEY_ID'] = cred[:key]
427
+ env_var['AWS_ACCESS_KEY'] = cred[:key]
428
+ env_var['AWS_SECRET_ACCESS_KEY'] = cred[:secret]
429
+ env_var['AWS_SECRET_KEY'] = cred[:secret]
430
+ if cred[:token]
431
+ env_var['AWS_SECURITY_TOKEN'] = cred[:token]
432
+ env_var['AWS_SESSION_TOKEN'] = cred[:token]
432
433
  end
433
434
  env_var
434
435
  end
435
436
 
436
- def put_env_string(account:, key:, secret:, token:)
437
- env_var = env_vars(account: account, key: key, secret: secret, token: token)
437
+ def put_env_string(cred)
438
+ env_var = env_vars(cred)
438
439
  env_var.each { |var, value| puts "export #{var}=\"#{value}\"" }
439
440
 
440
- puts 'unset AWS_SECURITY_TOKEN' unless token
441
- puts 'unset AWS_SESSION_TOKEN' unless token
441
+ puts 'unset AWS_SECURITY_TOKEN' unless cred[:token]
442
+ puts 'unset AWS_SESSION_TOKEN' unless cred[:token]
442
443
  end
443
444
 
444
445
  def ask_check(existing:, message:, secure: false, optional: false, validator: nil)
@@ -461,7 +462,7 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
461
462
 
462
463
  def ask(message:, secure: false, optional: false)
463
464
  if secure
464
- Thor::LineEditor.readline(message.rjust(20) + ': ', echo: false).strip
465
+ Awskeyring::Input.read_secret(message.rjust(20) + ': ')
465
466
  elsif optional
466
467
  Thor::LineEditor.readline((message + ' (optional)').rjust(20) + ': ')
467
468
  else
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.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Morgan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-03 00:00:00.000000000 Z
11
+ date: 2018-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-iam
@@ -85,6 +85,7 @@ files:
85
85
  - i18n/en.yml
86
86
  - lib/awskeyring.rb
87
87
  - lib/awskeyring/awsapi.rb
88
+ - lib/awskeyring/input.rb
88
89
  - lib/awskeyring/validate.rb
89
90
  - lib/awskeyring/version.rb
90
91
  - lib/awskeyring_command.rb