-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Adding the option to export AWS credentials with a command #6808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e426499
exporter logic created
HugoCL 58adc7a
update in stdout
HugoCL 6ba9b60
rm testing variable
HugoCL 1d4335a
Updated the credentials data output
HugoCL 32de935
Merge pull request #1 from HugoCL/export-credentials-configure
HugoCL 6f46ca0
rm gitpod
HugoCL 02e5d1f
rm unused imports
HugoCL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| from awscli.customizations.configure.writer import ConfigFileWriter | ||
| from awscli.customizations.commands import BasicCommand | ||
| from awscli.customizations.utils import uni_print | ||
| import json | ||
|
|
||
|
|
||
| class ConfigureExportCommand(BasicCommand): | ||
| NAME = 'export-credentials' | ||
| DESCRIPTION = 'Exports the AWS credentials used with the command "aws configure" to a the config file.' | ||
| EXAMPLES = 'aws configure export-credentials' | ||
|
|
||
| def __init__(self, session): | ||
| super(ConfigureExportCommand, self).__init__(session) | ||
|
|
||
| def _run_main(self, parsed_args, parsed_globals): | ||
| self.export_credentials(self._session) | ||
| return 0 | ||
|
|
||
| def export_credentials(self, session): | ||
| """ | ||
| Exports the AWS credentials used with the command 'aws configure' to a file. | ||
| """ | ||
| credentials = session.get_credentials() | ||
| if credentials is None: | ||
| raise RuntimeError( | ||
| 'No credentials available. Try running "aws configure" first.') | ||
| try: | ||
| credentials_data = credentials.get_frozen_credentials() | ||
| dump = {'aws_access_key_id': credentials_data.access_key, | ||
| 'aws_secret_access_key': credentials_data.secret_key} | ||
| if credentials_data.token is not None: | ||
| dump['aws_session_token'] = credentials_data.token | ||
| uni_print(json.dumps(dump, indent=4)) | ||
| except: | ||
| raise RuntimeError( | ||
| 'Failed while trying to export credentials. Check your permissions and try again.') | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a new command, without backward compat concerns, may I suggest using the same shape as is emitted by
aws sts assume-role? it'd be one less special case for those wishing to consume the output{ "Credentials": { "AccessKeyId": "ASIA...", "SecretAccessKey": "sekrit...", "SessionToken": "bAsE64=", "Expiration": "2022-04-13T17:24:10.189000+00:00" } }where obviously
SessionTokenandExpirationwould be elided just like they are in your current outputThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mdaniel, I'll try to make the changes as suggested