Skip to content

Commit

Permalink
Add no export env var format
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesls committed Nov 15, 2022
1 parent 280c39c commit 3ce9534
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
29 changes: 21 additions & 8 deletions awscli/customizations/configure/exportcreds.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,37 @@ def display_credentials(self, credentials):
pass


class BashEnvVarFormatter(BaseCredentialFormatter):
class BaseEnvVarFormatter(BaseCredentialFormatter):

FORMAT = 'env'
_VAR_PREFIX = ''

def display_credentials(self, credentials):
prefix = self._VAR_PREFIX
output = (
f'export AWS_ACCESS_KEY_ID={credentials.access_key}\n'
f'export AWS_SECRET_ACCESS_KEY={credentials.secret_key}\n'
f'{prefix}AWS_ACCESS_KEY_ID={credentials.access_key}\n'
f'{prefix}AWS_SECRET_ACCESS_KEY={credentials.secret_key}\n'
)
if credentials.token is not None:
output += f'export AWS_SESSION_TOKEN={credentials.token}\n'
output += f'{prefix}AWS_SESSION_TOKEN={credentials.token}\n'
if credentials.expiry_time is not None:
output += (
f'export AWS_CREDENTIAL_EXPIRATION={credentials.expiry_time}\n'
f'{prefix}AWS_CREDENTIAL_EXPIRATION={credentials.expiry_time}\n'
)
self._stream.write(output)


class BashEnvVarFormatter(BaseEnvVarFormatter):

FORMAT = 'env'
_VAR_PREFIX = 'export '


class BashNoExportEnvFormatter(BaseEnvVarFormatter):

FORMAT = 'env-no-export'
_VAR_PREFIX = ''


class PowershellFormatter(BaseCredentialFormatter):

FORMAT = 'powershell'
Expand Down Expand Up @@ -134,8 +147,8 @@ def display_credentials(self, credentials):

SUPPORTED_FORMATS = {
format_cls.FORMAT: format_cls for format_cls in
[BashEnvVarFormatter, CredentialProcessFormatter, PowershellFormatter,
WindowsCmdFormatter]
[BashEnvVarFormatter, BashNoExportEnvFormatter, CredentialProcessFormatter,
PowershellFormatter, WindowsCmdFormatter]
}


Expand Down
9 changes: 9 additions & 0 deletions tests/unit/customizations/configure/test_exportcreds.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
convert_botocore_credentials,
ConfigureExportCredentialsCommand,
BashEnvVarFormatter,
BashNoExportEnvFormatter,
PowershellFormatter,
WindowsCmdFormatter,
CredentialProcessFormatter,
Expand Down Expand Up @@ -56,6 +57,14 @@ def __eq__(self, other):
'export AWS_SESSION_TOKEN=token\n'
'export AWS_CREDENTIAL_EXPIRATION=2023-01-01T00:00:00Z\n'),
)),
(BashNoExportEnvFormatter, (
('AWS_ACCESS_KEY_ID=access_key\n'
'AWS_SECRET_ACCESS_KEY=secret_key\n'),
('AWS_ACCESS_KEY_ID=access_key\n'
'AWS_SECRET_ACCESS_KEY=secret_key\n'
'AWS_SESSION_TOKEN=token\n'
'AWS_CREDENTIAL_EXPIRATION=2023-01-01T00:00:00Z\n'),
)),
(PowershellFormatter, (
('$Env:AWS_ACCESS_KEY_ID="access_key"\n'
'$Env:AWS_SECRET_ACCESS_KEY="secret_key"\n'),
Expand Down

0 comments on commit 3ce9534

Please sign in to comment.