Skip to content

Commit

Permalink
Prevent showing Used role: None
Browse files Browse the repository at this point in the history
The `None` role is shown during the IC session creation as it is read
from the environment variable that is not set yet. The role is passed
depending on the context:
- the passed role is used while creating a new session
- the environment variable role is used while running the
  `describe-creds` command
  • Loading branch information
extsoft committed May 2, 2024
1 parent 1b355c8 commit 5f991a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .workflows/accept-work-after
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
git-elegant prune-repository
10 changes: 6 additions & 4 deletions aws-creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,21 @@ def _connect(ic: IdentityCenter, account_id: str, role: str) -> None:
print(f'export AWS_SECRET_ACCESS_KEY="{role_creds["secretAccessKey"]}"', file=sys.stdout)
print(f'export AWS_SESSION_TOKEN="{role_creds["sessionToken"]}"', file=sys.stdout)
print("AWS environment variables are exported!", file=sys.stderr)
_print_ic_information(account_name, account_id)
_print_ic_information(account_name, account_id, role)


def _print_ic_information(accunt_name: str, account_id: str) -> None:
def _print_ic_information(accunt_name: str, account_id: str, role_name: str) -> None:
print("Auth type: AWS IAM Identity Center", file=sys.stderr)
print(f"Account : {accunt_name} ({account_id})", file=sys.stderr) # noqa: E999
print("Used role: ", os.getenv("AWS_CREDS_ROLE_NAME"), file=sys.stderr)
print("Used role: ", role_name, file=sys.stderr)


def _describe_credentials() -> None:
sessiont_type = os.getenv("AWS_CREDS_SESSION_TYPE")
if sessiont_type == "ic":
_print_ic_information(os.getenv("AWS_CREDS_ACCOUNT_NAME"), os.getenv("AWS_CREDS_ACCOUNT_ID"))
_print_ic_information(
os.getenv("AWS_CREDS_ACCOUNT_NAME"), os.getenv("AWS_CREDS_ACCOUNT_ID"), os.getenv("AWS_CREDS_ROLE_NAME")
)
else:
print(f"Cannot find AWS credentials configured by '{_prog}'.", file=sys.stderr)

Expand Down

0 comments on commit 5f991a8

Please sign in to comment.