def _get_connection_attributes_from_catalog( connection: str, catalog_id: Optional[str], dbname: Optional[str], boto3_session: Optional[boto3.Session] ) -> ConnectionAttributes: details: Dict[str, Any] = get_connection(name=connection, catalog_id=catalog_id, boto3_session=boto3_session)[ "ConnectionProperties" ] if ";databaseName=" in details["JDBC_CONNECTION_URL"]: database_sep = ";databaseName=" else: database_sep = "/" port, database = details["JDBC_CONNECTION_URL"].split(":")[3].split(database_sep) ssl_context: Optional[ssl.SSLContext] = None if details.get("JDBC_ENFORCE_SSL") == "true": ssl_cert_path: Optional[str] = details.get("CUSTOM_JDBC_CERT") ssl_cadata: Optional[str] = None if ssl_cert_path: bucket_name, key_path = _utils.parse_path(ssl_cert_path) client_s3: boto3.client = _utils.client(service_name="s3", session=boto3_session) try: ssl_cadata = client_s3.get_object(Bucket=bucket_name, Key=key_path)["Body"].read().decode("utf-8") except client_s3.exception.NoSuchKey: raise exceptions.NoFilesFound( # pylint: disable=raise-missing-from f"No CA certificate found at {ssl_cert_path}." ) ssl_context = ssl.create_default_context(cadata=ssl_cadata) return ConnectionAttributes( kind=details["JDBC_CONNECTION_URL"].split(":")[1].lower(), user=details["USERNAME"], password=details["PASSWORD"], host=details["JDBC_CONNECTION_URL"].split(":")[2].replace("/", ""), port=int(port), database=dbname if dbname is not None else database, ssl_context=ssl_context, )
def _get_connection_attributes_from_catalog( connection: str, catalog_id: Optional[str], dbname: Optional[str], boto3_session: Optional[boto3.Session]) -> ConnectionAttributes: details: Dict[str, Any] = get_connection( name=connection, catalog_id=catalog_id, boto3_session=boto3_session)["ConnectionProperties"] port, database = details["JDBC_CONNECTION_URL"].split(":")[3].split("/") return ConnectionAttributes( kind=details["JDBC_CONNECTION_URL"].split(":")[1].lower(), user=details["USERNAME"], password=details["PASSWORD"], host=details["JDBC_CONNECTION_URL"].split(":")[2].replace("/", ""), port=int(port), database=dbname if dbname is not None else database, )
def get_connection_attributes( connection: str, catalog_id: Optional[str] = None, boto3_session: Optional[boto3.Session] = None, ) -> ConnectionAttributes: """Get Connection Attributes.""" details: Dict[str, Any] = get_connection( name=connection, catalog_id=catalog_id, boto3_session=boto3_session)["ConnectionProperties"] port, database = details["JDBC_CONNECTION_URL"].split(":")[3].split("/") return ConnectionAttributes( kind=details["JDBC_CONNECTION_URL"].split(":")[1].lower(), user=quote_plus(details["USERNAME"]), password=quote_plus(details["PASSWORD"]), host=details["JDBC_CONNECTION_URL"].split(":")[2].replace("/", ""), port=int(port), database=database, )