awskeyring 1.8.3 → 1.8.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ea94b3d72f37d363e05a9d5cbcb7833a4039368b4ebe8f32a0d24b29bdb0e7b
4
- data.tar.gz: 358d4bab4128a8e0defa2a1736c4e05820f2ec11e58e4c0c4d29489da94d892e
3
+ metadata.gz: 1d6214486cc6877ca62ed23c40f01636f0f5bd726f7d7fdd9dd7f310ec87da84
4
+ data.tar.gz: fede3a531c42bab12951bb316e8f4c0f9c3d383f60121c4993359013422fb6b4
5
5
  SHA512:
6
- metadata.gz: 402911d7d34d2f496c245dab3629ed55da0c21d4bd821829258db7221b54aac69fdaee8871984aae308cbe25576e2e6de493b362c8ef22bfc75987e8b0129ec0
7
- data.tar.gz: 8dd73f4b26dfcf6173b1d8e8b3db16747110cc49a2bc120df425c789ff7025a93959becb526467393bd33eb832febb66c5fb86f00b1d61eebcd7091b126fbde0
6
+ metadata.gz: f23bed2643e3ab8f288ff690f20f540b8486a9aca792ff362696bf867009d36d874391f13b936cc1808a9908f1f16617d2fe81073e08c6620f0997835e653cb3
7
+ data.tar.gz: a9732e12755c7465545bdcd59a982f446a33e42988de10158a4db977c4d8fc5a8a391d6c55c67b835fb6af749dd3e77dfef1d335b04fa6683a6df1ce0a36d227
data/README.md CHANGED
@@ -91,7 +91,7 @@ There are also short forms of most commands if you prefer:
91
91
 
92
92
  To set your environment easily the following bash function helps:
93
93
 
94
- awsenv() { eval "$(awskeyring env $@)"; }
94
+ awsenv() { eval "$(awskeyring env ${@:-$AWS_ACCOUNT_NAME})"; }
95
95
 
96
96
  ## Development
97
97
 
data/Rakefile CHANGED
@@ -55,7 +55,7 @@ task :ronn do
55
55
  end
56
56
 
57
57
  YARD::Rake::YardocTask.new do |t|
58
- t.options = ['--fail-on-warning', '--no-progress']
58
+ t.options = ['--fail-on-warning', '--no-progress', '--files', '*.md']
59
59
  t.stats_options = ['--list-undoc']
60
60
  end
61
61
 
data/i18n/en.yml CHANGED
@@ -33,7 +33,6 @@ en:
33
33
  noremote: 'Do not validate with remote api.'
34
34
  path: 'The service PATH to open.'
35
35
  browser: 'Specify an alternative browser.'
36
- role: 'The ROLE to assume.'
37
36
  secret: 'AWS account secret.'
38
37
  unset: 'Unset environment variables.'
39
38
  message:
@@ -6,7 +6,7 @@ require 'json'
6
6
  # Version const and query of latest.
7
7
  module Awskeyring
8
8
  # The Gem's version number
9
- VERSION = '1.8.3'
9
+ VERSION = '1.8.4'
10
10
  # The Gem's homepage
11
11
  HOMEPAGE = 'https://github.com/servian/awskeyring'
12
12
 
@@ -17,17 +17,13 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
17
17
 
18
18
  map %w[--version -v] => :__version
19
19
  map %w[--help -h] => :help
20
- map 'init' => :initialise
21
20
  map 'adr' => :add_role
22
- map 'con' => :console
21
+ map 'assume-role' => :token
23
22
  map 'ls' => :list
24
23
  map 'lsr' => :list_role
25
24
  map 'rm' => :remove
26
25
  map 'rmr' => :remove_role
27
26
  map 'rmt' => :remove_token
28
- map 'rot' => :rotate
29
- map 'tok' => :token
30
- map 'up' => :update
31
27
  default_command :default
32
28
 
33
29
  # default to returning an error on failure.
@@ -91,9 +87,8 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
91
87
  puts Awskeyring.list_account_names.join("\n")
92
88
  end
93
89
 
94
- map 'list-role' => :list_role
95
90
  desc 'list-role', I18n.t('list_role_desc')
96
- method_option 'detail', type: :boolean, aliases: '-d', desc: I18n.t('method_option.detail'), default: false
91
+ method_option :detail, type: :boolean, aliases: '-d', desc: I18n.t('method_option.detail'), default: false
97
92
  # List roles
98
93
  def list_role
99
94
  if Awskeyring.list_role_names.empty?
@@ -109,7 +104,7 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
109
104
 
110
105
  desc 'env ACCOUNT', I18n.t('env_desc')
111
106
  method_option 'no-token', type: :boolean, aliases: '-n', desc: I18n.t('method_option.notoken'), default: false
112
- method_option 'unset', type: :boolean, aliases: '-u', desc: I18n.t('method_option.unset'), default: false
107
+ method_option :unset, type: :boolean, aliases: '-u', desc: I18n.t('method_option.unset'), default: false
113
108
  # Print Env vars
114
109
  def env(account = nil)
115
110
  if options[:unset]
@@ -258,7 +253,6 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
258
253
  puts I18n.t('message.upaccount', account: account)
259
254
  end
260
255
 
261
- map 'add-role' => :add_role
262
256
  desc 'add-role ROLE', I18n.t('add_role_desc')
263
257
  method_option :arn, type: :string, aliases: '-a', desc: I18n.t('method_option.arn')
264
258
  # Add a role
@@ -291,15 +285,14 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
291
285
 
292
286
  desc 'remove-token ACCOUNT', I18n.t('remove_token_desc')
293
287
  # remove a session token
294
- def remove_token(account = nil)
295
- account = ask_check(
296
- existing: account, message: I18n.t('message.account'), validator: Awskeyring.method(:token_exists),
288
+ def remove_token(token = nil)
289
+ token = ask_check(
290
+ existing: token, message: I18n.t('message.account'), validator: Awskeyring.method(:token_exists),
297
291
  limited_to: Awskeyring.list_token_names
298
292
  )
299
- Awskeyring.delete_token(account: account, message: I18n.t('message.deltoken', account: account))
293
+ Awskeyring.delete_token(account: token, message: I18n.t('message.deltoken', account: token))
300
294
  end
301
295
 
302
- map 'remove-role' => :remove_role
303
296
  desc 'remove-role ROLE', I18n.t('remove_role_desc')
304
297
  # remove a role
305
298
  def remove_role(role = nil)
@@ -343,7 +336,6 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
343
336
  end
344
337
 
345
338
  desc 'token ACCOUNT [ROLE] [MFA]', I18n.t('token_desc')
346
- method_option :role, type: :string, aliases: '-r', desc: I18n.t('method_option.role')
347
339
  method_option :code, type: :string, aliases: '-c', desc: I18n.t('method_option.code')
348
340
  method_option :duration, type: :string, aliases: '-d', desc: I18n.t('method_option.duration')
349
341
  # generate a sessiopn token
@@ -354,7 +346,6 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
354
346
  validator: Awskeyring.method(:account_exists),
355
347
  limited_to: Awskeyring.list_account_names
356
348
  )
357
- role ||= options[:role]
358
349
  if role
359
350
  role = ask_check(
360
351
  existing: role, message: I18n.t('message.role'), validator: Awskeyring.method(:role_exists),
@@ -441,14 +432,18 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
441
432
  # autocomplete
442
433
  def autocomplete(curr, prev)
443
434
  comp_line = ENV['COMP_LINE']
444
- unless comp_line
435
+ comp_point_str = ENV['COMP_POINT']
436
+ unless comp_line && comp_point_str
445
437
  exec_name = File.basename($PROGRAM_NAME)
446
438
  warn I18n.t('message.awskeyring', path: $PROGRAM_NAME, bin: exec_name)
447
439
  exit 1
448
440
  end
449
441
 
450
- curr, comp_len, sub_cmd = comp_type(comp_line: comp_line, curr: curr, prev: prev)
451
- print_auto_resp(curr, comp_len, sub_cmd)
442
+ comp_lines = comp_line[0..(comp_point_str.to_i)].split
443
+
444
+ comp_type, sub_cmd = comp_type(comp_lines: comp_lines, prev: prev)
445
+ list = fetch_auto_resp(comp_type, sub_cmd)
446
+ puts list.select { |elem| elem.start_with?(curr) }.sort!.join("\n")
452
447
  end
453
448
 
454
449
  private
@@ -463,59 +458,63 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
463
458
  cred
464
459
  end
465
460
 
466
- def comp_type(comp_line:, curr:, prev:)
467
- comp_len = comp_line.split.index(prev)
468
- sub_cmd = sub_command(comp_line.split)
469
-
470
- comp_len = 3 if curr.start_with?('-')
461
+ def comp_type(comp_lines:, prev:)
462
+ sub_cmd = sub_command(comp_lines)
463
+ comp_idx = comp_lines.rindex(prev)
471
464
 
472
465
  case prev
473
- when 'help', File.basename($PROGRAM_NAME)
474
- comp_len = 0
475
- when 'remove-role', '-r', 'rmr'
476
- comp_len = 2
477
466
  when '--path', '-p'
478
- comp_len = 40
479
- when 'remove-token', 'rmt'
480
- comp_len = 50
467
+ comp_type = :path_type
481
468
  when '--browser', '-b'
482
- comp_len = 60
469
+ comp_type = :browser_type
470
+ else
471
+ comp_type = :command
472
+ comp_type = param_type(comp_idx, sub_cmd) unless sub_cmd.empty?
483
473
  end
484
474
 
485
- [curr, comp_len, sub_cmd]
475
+ [comp_type, sub_cmd]
476
+ end
477
+
478
+ def param_type(comp_idx, sub_cmd)
479
+ param_list = method(sub_cmd).parameters
480
+ if comp_idx.zero?
481
+ :command
482
+ elsif comp_idx > param_list.length
483
+ :flag
484
+ else
485
+ param_list[comp_idx - 1][1]
486
+ end
486
487
  end
487
488
 
488
489
  def sub_command(comp_lines)
489
- return nil if comp_lines.nil? || comp_lines.length < 2
490
+ return '' if comp_lines.nil? || comp_lines.length < 2
491
+
492
+ sub_cmd = comp_lines[1].tr('-', '_')
490
493
 
491
- sub_cmd = comp_lines[1]
494
+ sub_cmds = self.class.all_commands.keys.select { |elem| elem.start_with?(sub_cmd) }
492
495
 
493
- return sub_cmd if self.class.all_commands.keys.index(sub_cmd)
496
+ return sub_cmds.first if sub_cmds.length == 1
494
497
 
495
498
  self.class.map[sub_cmd].to_s
496
499
  end
497
500
 
498
- def print_auto_resp(curr, len, sub_cmd) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
499
- list = []
500
- case len
501
- when 0
502
- list = list_commands
503
- when 1
504
- list = Awskeyring.list_account_names
505
- when 2
506
- list = Awskeyring.list_role_names
507
- when 3..10
508
- list = list_arguments(command: sub_cmd)
509
- when 40
510
- list = Awskeyring.list_console_path
511
- when 50
512
- list = Awskeyring.list_token_names
513
- when 60
514
- list = Awskeyring.list_browsers
501
+ def fetch_auto_resp(comp_type, sub_cmd)
502
+ case comp_type
503
+ when :command
504
+ list_commands
505
+ when :account
506
+ Awskeyring.list_account_names
507
+ when :role
508
+ Awskeyring.list_role_names
509
+ when :path_type
510
+ Awskeyring.list_console_path
511
+ when :token
512
+ Awskeyring.list_token_names
513
+ when :browser_type
514
+ Awskeyring.list_browsers
515
515
  else
516
- exit 1
516
+ list_arguments(command: sub_cmd)
517
517
  end
518
- puts list.select { |elem| elem.start_with?(curr) }.sort!.join("\n")
519
518
  end
520
519
 
521
520
  def list_commands
@@ -524,9 +523,11 @@ class AwskeyringCommand < Thor # rubocop:disable Metrics/ClassLength
524
523
  end
525
524
 
526
525
  def list_arguments(command:)
527
- exit 1 if command.empty?
528
- self.class.all_commands[command].options.values.map(&:aliases).flatten! +
529
- self.class.all_commands[command].options.values.map(&:switch_name)
526
+ options = self.class.all_commands[command].options.values
527
+ exit 1 if options.empty?
528
+
529
+ options.map(&:aliases).flatten! +
530
+ options.map(&:switch_name)
530
531
  end
531
532
 
532
533
  def put_env_string(cred)
data/man/awskeyring.5 CHANGED
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "AWSKEYRING" "5" "April 2021" "" ""
4
+ .TH "AWSKEYRING" "5" "May 2021" "" ""
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBAwskeyring\fR \- is a small tool to manage AWS account keys in the macOS Keychain
@@ -197,9 +197,6 @@ Create an STS Token from a ROLE or an MFA code
197
197
  .br
198
198
  .
199
199
  .IP
200
- \-r, \-\-role=ROLE: The ROLE to assume\.
201
- .
202
- .br
203
200
  \-c, \-\-code=CODE: Virtual mfa CODE\.
204
201
  .
205
202
  .br
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: 1.8.3
4
+ version: 1.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Morgan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-26 00:00:00.000000000 Z
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-iam
@@ -93,8 +93,8 @@ licenses:
93
93
  metadata:
94
94
  bug_tracker_uri: https://github.com/servian/awskeyring/issues
95
95
  changelog_uri: https://github.com/servian/awskeyring/blob/main/CHANGELOG.md
96
- documentation_uri: https://rubydoc.info/gems/awskeyring/1.8.3
97
- source_code_uri: https://github.com/servian/awskeyring/tree/v1.8.3
96
+ documentation_uri: https://rubydoc.info/gems/awskeyring/1.8.4
97
+ source_code_uri: https://github.com/servian/awskeyring/tree/v1.8.4
98
98
  wiki_uri: https://github.com/servian/awskeyring/wiki
99
99
  post_install_message:
100
100
  rdoc_options: []