Skip to content

Commit

Permalink
logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyanshu-Patel committed Oct 10, 2024
1 parent 3824b3c commit 36d5763
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions soda/redshift/soda/data_sources/redshift_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

logger = logging.getLogger(__name__)

logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler(),
]
)

logger = logging.getLogger(__name__)

class RedshiftDataSource(DataSource):
TYPE = "redshift"
Expand Down Expand Up @@ -55,8 +64,10 @@ def __get_cluster_credentials(self, aws_credentials: AwsCredentials):
resolved_aws_credentials = aws_credentials.resolve_role(
role_session_name="soda_redshift_get_cluster_credentials"
)
logger.debug(f"Resolved AWS Credentials: {resolved_aws_credentials}")

region_name = resolved_aws_credentials.region_name or "us-west-2"
logger.debug(f"Region Name: {region_name}")

client = boto3.client(
"redshift",
Expand All @@ -65,13 +76,28 @@ def __get_cluster_credentials(self, aws_credentials: AwsCredentials):
aws_secret_access_key=resolved_aws_credentials.secret_access_key,
aws_session_token=resolved_aws_credentials.session_token,
)
logger.debug("Boto3 Redshift client initialized.")

cluster_name = "bi-edw-db"
username = self.dbuser if self.dbuser else self.username
db_name = self.dbname if self.dbname else self.database
cluster_creds = client.get_cluster_credentials(
DbUser=username, DbName=db_name, ClusterIdentifier=cluster_name, AutoCreate=False, DurationSeconds=3600
)

logger.debug(f"Using cluster name: {cluster_name}")
logger.debug(f"Using DbUser: {username}")
logger.debug(f"Using DbName: {db_name}")

try:
cluster_creds = client.get_cluster_credentials(
DbUser=username,
DbName=db_name,
ClusterIdentifier=cluster_name,
AutoCreate=False,
DurationSeconds=3600
)
logger.debug(f"Cluster Credentials Retrieved: {cluster_creds}")
except botocore.exceptions.ClientError as error:
logger.error(f"Error retrieving cluster credentials: {error}")
raise

return cluster_creds["DbUser"], cluster_creds["DbPassword"]

Expand Down

0 comments on commit 36d5763

Please sign in to comment.