From c3a8ef38413fd915d787dba946ef956d61e316be Mon Sep 17 00:00:00 2001 From: "Vincent.PAUWELS" Date: Mon, 20 Nov 2023 18:36:15 +0100 Subject: [PATCH] keep use_interactive_session_role_for_api_calls but change the default value to True --- dbt/adapters/glue/credentials.py | 2 +- dbt/adapters/glue/impl.py | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/dbt/adapters/glue/credentials.py b/dbt/adapters/glue/credentials.py index fb55e92e..0ada1166 100644 --- a/dbt/adapters/glue/credentials.py +++ b/dbt/adapters/glue/credentials.py @@ -29,7 +29,7 @@ class GlueCredentials(Credentials): seed_mode: Optional[str] = "overwrite" default_arguments: Optional[str] = None iceberg_glue_commit_lock_table: Optional[str] = "myGlueLockTable" - use_interactive_session_role_for_api_calls: bool = False + use_interactive_session_role_for_api_calls: bool = True lf_tags: Optional[str] = None glue_session_id: Optional[str] = None glue_session_reuse: Optional[bool] = False diff --git a/dbt/adapters/glue/impl.py b/dbt/adapters/glue/impl.py index f0db5356..caf77dbe 100644 --- a/dbt/adapters/glue/impl.py +++ b/dbt/adapters/glue/impl.py @@ -78,20 +78,23 @@ def convert_datetime_type(cls, agate_table, col_idx): def get_connection(self): connection: GlueConnectionManager = self.connections.get_thread_connection() glueSession: GlueConnection = connection.handle + if glueSession.credentials.role_arn is not None: + if glueSession.credentials.use_interactive_session_role_for_api_calls is True: + sts_client = boto3.client('sts') + assumed_role_object = sts_client.assume_role( + RoleArn=glueSession.credentials.role_arn, + RoleSessionName="dbt" + ) + credentials = assumed_role_object['Credentials'] + glue_client = boto3.client("glue", region_name=glueSession.credentials.region, + aws_access_key_id=credentials['AccessKeyId'], + aws_secret_access_key=credentials['SecretAccessKey'], + aws_session_token=credentials['SessionToken']) + return glueSession, glue_client - sts_client = boto3.client('sts') - assumed_role_object = sts_client.assume_role( - RoleArn=glueSession.credentials.role_arn, - RoleSessionName="dbt" - ) - credentials = assumed_role_object['Credentials'] - - client = boto3.client("glue", region_name=glueSession.credentials.region, - aws_access_key_id=credentials['AccessKeyId'], - aws_secret_access_key=credentials['SecretAccessKey'], - aws_session_token=credentials['SessionToken']) + glue_client = boto3.client("glue", region_name=glueSession.credentials.region) - return glueSession, client + return glueSession, glue_client def list_schemas(self, database: str) -> List[str]: session, client = self.get_connection()