From f16f69c6d8665e9c251ef680685baab7dbe5d55f Mon Sep 17 00:00:00 2001 From: Jake Skipper Date: Tue, 19 Dec 2023 21:31:47 +0000 Subject: [PATCH] Adjustment to fix linting error after stubs update --- runway/context/_base.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/runway/context/_base.py b/runway/context/_base.py index e319cbb24..cd286e325 100644 --- a/runway/context/_base.py +++ b/runway/context/_base.py @@ -163,13 +163,16 @@ def _inject_profile_credentials(self) -> None: # cov: ignore if self.current_aws_creds or not self.env.aws_profile: return - creds = ( - self.get_session(profile=self.env.aws_profile) - .get_credentials() - .get_frozen_credentials() - ) - - self.env.vars["AWS_ACCESS_KEY_ID"] = creds.access_key - self.env.vars["AWS_SECRET_ACCESS_KEY"] = creds.secret_key - if creds.token: - self.env.vars["AWS_SESSION_TOKEN"] = creds.token + try: + creds = self.get_session(profile=self.env.aws_profile).get_credentials() + if creds is not None: + frozen_creds = creds.get_frozen_credentials() + self.env.vars["AWS_ACCESS_KEY_ID"] = frozen_creds.access_key + self.env.vars["AWS_SECRET_ACCESS_KEY"] = frozen_creds.secret_key + if frozen_creds.token: + self.env.vars["AWS_SESSION_TOKEN"] = frozen_creds.token + else: + raise ValueError("Credentials could not be retrieved from the session.") + except Exception as e: + # Handle the exception as needed + self.logger.error("An error occurred: %s", e)