Skip to content

Commit

Permalink
Merge pull request #69 from servian/no-accounts-yet
Browse files Browse the repository at this point in the history
Warn about missing accounts/roles
  • Loading branch information
tristanmorgan authored Aug 9, 2020
2 parents 73ab123 + 012c2dc commit 07ec48c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ en:
delexpired: '# Removing expired session credentials'
exec: '# COMMAND not provided'
missing: '# Config missing, run `%{bin} initialise` to recreate.'
missing_account: '# No accounts added, run `%{bin} add` to add.'
missing_role: '# No roles added, run `%{bin} add-role` to add.'
rotate: '# You have two access keys for account %{account}'
temporary: '# Using temporary session credentials.'
timeout: '# It is STRONGLY recommended to set your keychain to lock in 5 minutes or less.'
Expand Down
8 changes: 8 additions & 0 deletions lib/awskeyring_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def initialise
desc 'list', I18n.t('list.desc')
# list the accounts
def list
if Awskeyring.list_account_names.empty?
warn I18n.t('message.missing_account', bin: File.basename($PROGRAM_NAME))
exit 1
end
puts Awskeyring.list_account_names.join("\n")
end

Expand All @@ -80,6 +84,10 @@ def list
method_option 'detail', type: :boolean, aliases: '-d', desc: I18n.t('method_option.detail'), default: false
# List roles
def list_role
if Awskeyring.list_role_names.empty?
warn I18n.t('message.missing_role', bin: File.basename($PROGRAM_NAME))
exit 1
end
if options['detail']
puts Awskeyring.list_role_names_plus.join("\n")
else
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/awskeyring_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@
end
end

context 'when no accounts or roles are set' do
before do
allow(Awskeyring).to receive(:list_account_names).and_return([])
allow(Awskeyring).to receive(:list_role_names).and_return([])
allow(Awskeyring).to receive(:prefs).and_return('{"awskeyring": "awskeyringtest"}')
end

it 'tells you that you must add accounts' do
expect { described_class.start(%w[list]) }.to raise_error
.and output(/No accounts added, run `\w+ add` to add./).to_stderr
end

it 'tells you that you must add roles' do
expect { described_class.start(%w[list-role]) }.to raise_error
.and output(/No roles added, run `\w+ add-role` to add./).to_stderr
end
end

context 'when accounts and roles are set' do
before do
allow(Awskeyring).to receive(:list_account_names).and_return(%w[company personal servian])
Expand Down

0 comments on commit 07ec48c

Please sign in to comment.