Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions awscli/customizations/configure/exportcreds.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ class WindowsCmdFormatter(BasePerLineFormatter):
_VAR_FORMAT = 'set {var_name}={var_value}'


class FishShellFormatter(BasePerLineFormatter):
FORMAT = 'fish'
DOCUMENTATION = (
'Display credentials as Fish shell environment variables: '
'``set -gx AWS_ACCESS_KEY_ID EXAMPLE``'
)
_VAR_FORMAT = 'set -gx {var_name} {var_value}'
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Fish shell formatter should quote the variable value to handle credentials that may contain special characters (spaces, quotes, etc.). Similar to PowerShell's approach, the format should be 'set -gx {var_name} "{var_value}"' to ensure values with spaces or special characters are properly handled. While AWS credential values rarely contain such characters, session tokens could potentially include them, and proper quoting ensures robustness.

Suggested change
_VAR_FORMAT = 'set -gx {var_name} {var_value}'
_VAR_FORMAT = 'set -gx {var_name} "{var_value}"'

Copilot uses AI. Check for mistakes.


class CredentialProcessFormatter(BaseCredentialFormatter):
FORMAT = 'process'
DOCUMENTATION = (
Expand Down Expand Up @@ -152,6 +161,7 @@ def display_credentials(self, credentials):
BashNoExportEnvFormatter,
PowershellFormatter,
WindowsCmdFormatter,
FishShellFormatter,
]
}

Expand Down
16 changes: 16 additions & 0 deletions tests/unit/customizations/configure/test_exportcreds.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ConfigureExportCredentialsCommand,
CredentialProcessFormatter,
Credentials,
FishShellFormatter,
PowershellFormatter,
WindowsCmdFormatter,
convert_botocore_credentials,
Expand Down Expand Up @@ -109,6 +110,21 @@ def __eq__(self, other):
),
),
),
(
FishShellFormatter,
(
(
'set -gx AWS_ACCESS_KEY_ID access_key\n'
'set -gx AWS_SECRET_ACCESS_KEY secret_key\n'
),
(
'set -gx AWS_ACCESS_KEY_ID access_key\n'
'set -gx AWS_SECRET_ACCESS_KEY secret_key\n'
'set -gx AWS_SESSION_TOKEN token\n'
'set -gx AWS_CREDENTIAL_EXPIRATION 2023-01-01T00:00:00Z\n'
Comment on lines +117 to +124
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected test output should include quotes around the values to match the corrected Fish shell format. The format should be 'set -gx AWS_ACCESS_KEY_ID "access_key"' instead of 'set -gx AWS_ACCESS_KEY_ID access_key' to properly handle values with special characters.

Suggested change
'set -gx AWS_ACCESS_KEY_ID access_key\n'
'set -gx AWS_SECRET_ACCESS_KEY secret_key\n'
),
(
'set -gx AWS_ACCESS_KEY_ID access_key\n'
'set -gx AWS_SECRET_ACCESS_KEY secret_key\n'
'set -gx AWS_SESSION_TOKEN token\n'
'set -gx AWS_CREDENTIAL_EXPIRATION 2023-01-01T00:00:00Z\n'
'set -gx AWS_ACCESS_KEY_ID "access_key"\n'
'set -gx AWS_SECRET_ACCESS_KEY "secret_key"\n'
),
(
'set -gx AWS_ACCESS_KEY_ID "access_key"\n'
'set -gx AWS_SECRET_ACCESS_KEY "secret_key"\n'
'set -gx AWS_SESSION_TOKEN "token"\n'
'set -gx AWS_CREDENTIAL_EXPIRATION "2023-01-01T00:00:00Z"\n'

Copilot uses AI. Check for mistakes.
),
),
),
(
CredentialProcessFormatter,
(
Expand Down
Loading