Skip to content

Commit f1e5b71

Browse files
Merge pull request #65 from 4dn-dcic/dmichaels-fix-local-check-execution-script-20240812
Fix to local_check_execution.py for newer SSO-based AWS credentials.
2 parents c2638eb + e4c8d91 commit f1e5b71

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ foursight-core
66
Change Log
77
----------
88

9+
5.6.1
10+
=====
11+
* Fix to foursight_core/scripts/local_check_execution.py for newer SSO-based AWS credentials,
12+
where AWS_ACCESS_KEY_ID/etc environment variables are not set.
13+
14+
915
5.6.0
1016
=====
1117
* Support for Python 3.12.

foursight_core/scripts/local_check_execution.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,27 +305,31 @@ def guess_env() -> Optional[str]:
305305
def sanity_check_aws_accessibility(verbose: bool = False) -> None:
306306
aws_account_number = None
307307
aws_account_alias = None
308-
if not (error := (not os.environ.get("AWS_SECRET_ACCESS_KEY") or not os.environ.get("AWS_ACCESS_KEY_ID"))):
308+
error = False
309+
try:
310+
if caller_identity := boto3.client("sts").get_caller_identity():
311+
aws_account_number = caller_identity.get("Account")
312+
if aws_account_aliases := boto3.client("iam").list_account_aliases():
313+
if aws_account_aliases := aws_account_aliases.get("AccountAliases"):
314+
aws_account_alias = aws_account_aliases[0]
315+
except Exception:
316+
error = True
317+
if verbose:
318+
access_key_id = None
309319
try:
310-
if caller_identity := boto3.client("sts").get_caller_identity():
311-
aws_account_number = caller_identity.get("Account")
312-
if aws_account_aliases := boto3.client("iam").list_account_aliases():
313-
if aws_account_aliases := aws_account_aliases.get("AccountAliases"):
314-
aws_account_alias = aws_account_aliases[0]
320+
boto_session = boto3.Session()
321+
credentials = boto_session.get_credentials()
322+
access_key_id = credentials.access_key
315323
except Exception:
316-
error = True
317-
if verbose:
324+
pass
318325
if not error:
319-
print(f"Using AWS access key ID: {os.environ.get('AWS_ACCESS_KEY_ID')} -> OK")
326+
print(f"Using AWS access key ID: {access_key_id} -> OK")
320327
if aws_account_alias:
321328
print(f"Using AWS account name (alias): {aws_account_alias}")
322329
if aws_account_number:
323330
print(f"Using AWS account (number): {aws_account_number}")
324331
if error:
325-
print(f"Cannot access AWS. Using AWS access key ID: "
326-
f"{os.environ.get('AWS_ACCESS_KEY_ID')} -> ERROR")
327-
exit_with_no_action(
328-
"You must have your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables setup properly.")
332+
exit_with_no_action(f"Cannot access AWS. Your AWS credentials do not appear to be setup property")
329333

330334

331335
def sanity_check_elasticsearch_accessibility(host: str, es_url: Optional[str] = None, timeout: int = 3) -> None:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "foursight-core"
3-
version = "5.6.0"
3+
version = "5.6.1"
44
description = "Serverless Chalice Application for Monitoring"
55
authors = ["4DN-DCIC Team <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)