Skip to content

Commit cf805a8

Browse files
committed
addressing code review comments
1 parent b1f2180 commit cf805a8

File tree

7 files changed

+17
-8
lines changed

7 files changed

+17
-8
lines changed

aws_advanced_python_wrapper/federated_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class FederatedAuthPlugin(Plugin):
5757
_rds_utils: RdsUtils = RdsUtils()
5858
_token_cache: Dict[str, TokenInfo] = {}
5959

60-
def __init__(self, plugin_service: PluginService,
60+
def __init__(self,
61+
plugin_service: PluginService,
6162
credentials_provider_factory: CredentialsProviderFactory,
6263
token_utils: TokenUtils,
6364
session: Optional[Session] = None):

aws_advanced_python_wrapper/okta_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class OktaAuthPlugin(Plugin):
5353
_rds_utils: RdsUtils = RdsUtils()
5454
_token_cache: Dict[str, TokenInfo] = {}
5555

56-
def __init__(self, plugin_service: PluginService,
56+
def __init__(self,
57+
plugin_service: PluginService,
5758
credentials_provider_factory: CredentialsProviderFactory,
5859
token_utils: TokenUtils,
5960
session: Optional[Session] = None):

aws_advanced_python_wrapper/resources/aws_advanced_python_wrapper_messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ IamAuthPlugin.UnhandledException=[IamAuthPlugin] Unhandled exception: {}
151151
IamAuthPlugin.UseCachedIamToken=[IamAuthPlugin] Used cached IAM token = {}
152152
IamAuthPlugin.InvalidHost=[IamAuthPlugin] Invalid IAM host {}. The IAM host must be a valid RDS or Aurora endpoint.
153153
IamAuthPlugin.IsNoneOrEmpty=[IamAuthPlugin] Property "{}" is None or empty.
154-
IamAuthUtils.GeneratedNewAuthToken=Generated new authentication token = {}
155154

156155
LimitlessPlugin.FailedToConnectToHost=[LimitlessPlugin] Failed to connect to host {}.
157156
LimitlessPlugin.UnsupportedDialectOrDatabase=[LimitlessPlugin] Unsupported dialect '{}' encountered. Please ensure the connection parameters are correct, and refer to the documentation to ensure that the connecting database is compatible with the Limitless Connection Plugin.
@@ -316,6 +315,8 @@ RoundRobinHostSelector.ClusterInfoNone=[RoundRobinHostSelector] The round robin
316315
RoundRobinHostSelector.RoundRobinInvalidDefaultWeight=[RoundRobinHostSelector] The provided default weight value is not valid. Weight values must be an integer greater than or equal to 1.
317316
RoundRobinHostSelector.RoundRobinInvalidHostWeightPairs= [RoundRobinHostSelector] The provided host weight pairs have not been configured correctly. Please ensure the provided host weight pairs is a comma separated list of pairs, each pair in the format of <host>:<weight>. Weight values must be an integer greater than or equal to the default weight value of 1. Weight pair: '{}'
318317

318+
TokenUtils.GeneratedNewAuthTokenLength=Generated new authentication token length = {}
319+
319320
WeightedRandomHostSelector.WeightedRandomInvalidHostWeightPairs= [WeightedRandomHostSelector] The provided host weight pairs have not been configured correctly. Please ensure the provided host weight pairs is a comma separated list of pairs, each pair in the format of <host>:<weight>. Weight values must be an integer greater than or equal to the default weight value of 1. Weight pair: '{}'
320321
WeightedRandomHostSelector.WeightedRandomInvalidDefaultWeight=[WeightedRandomHostSelector] The provided default weight value is not valid. Weight values must be an integer greater than or equal to 1.
321322

aws_advanced_python_wrapper/utils/dsql_token_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def generate_authentication_token(
4141
credentials: Optional[Dict[str, str]] = None,
4242
client_session: Optional[Session] = None) -> str:
4343
telemetry_factory = plugin_service.get_telemetry_factory()
44-
context = telemetry_factory.open_telemetry_context("fetch authentication token", TelemetryTraceLevel.NESTED)
44+
context = telemetry_factory.open_telemetry_context("fetch DSQL authentication token", TelemetryTraceLevel.NESTED)
4545

4646
try:
4747
session = client_session if client_session else boto3.Session()
@@ -64,7 +64,8 @@ def generate_authentication_token(
6464
else:
6565
token = client.generate_db_connect_auth_token(host_name, region)
6666

67-
logger.debug("IamAuthUtils.GeneratedNewAuthToken", token)
67+
logger.debug("TokenUtils.GeneratedNewAuthTokenLength", len(token) if token else 0)
68+
client.close()
6869
return token
6970
except Exception as ex:
7071
context.set_success(False)

aws_advanced_python_wrapper/utils/rds_token_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def generate_authentication_token(
6969

7070
client.close()
7171

72-
logger.debug("IamAuthUtils.GeneratedNewAuthToken", token)
72+
logger.debug("TokenUtils.GeneratedNewAuthTokenLength", len(token) if token else 0)
7373
return token
7474
except Exception as ex:
7575
context.set_success(False)

docs/using-the-python-driver/using-plugins/UsingTheDSQLIamAuthenticationPlugin.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ AWS Identity and Access Management (IAM) grants users access control across all
99
> [!WARNING]\
1010
> To preserve compatibility with customers using the community driver, IAM Authentication requires the AWS SDK for Python; [Boto3](https://pypi.org/project/boto3/). Boto3 is a runtime dependency and must be resolved. It can be installed via pip like so: `pip install boto3`.
1111
12-
The IAM Authentication plugin requires authentication via AWS Credentials. These credentials can be defined in `~/.aws/credentials` or set as environment variables. All users must set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. Users who are using temporary security credentials will also need to additionally set `AWS_SESSION_TOKEN`.
12+
The DSQL IAM Authentication plugin requires authentication via AWS Credentials. These credentials can be defined in `~/.aws/credentials` or set as environment variables. All users must set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. Users who are using temporary security credentials will also need to additionally set `AWS_SESSION_TOKEN`.
1313

1414
To enable the AWS Aurora DSQL IAM Authentication Plugin, add the plugin code `iam_dsql` to the [`plugins`](../UsingThePythonDriver.md#connection-plugin-manager-parameters) parameter.
1515

@@ -20,6 +20,8 @@ To enable the AWS Aurora DSQL IAM Authentication Plugin, add the plugin code `ia
2020
The AWS Python Driver supports Amazon AWS Identity and Access Management (IAM) authentication. When using AWS IAM database authentication, the host URL must be a valid AWS Aurora DSQL endpoint, and not a custom domain or an IP address.
2121
<br>i.e. `cluster-identifier.dsql.us-east-1.on.aws`
2222

23+
Connections established by the `iamDsql` plugin are beholden to the [Cluster quotas and database limits in Amazon Aurora DSQL](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/CHAP_quotas.html). In particular, applications need to consider the maximum transaction duration, and maximum connection duration limits. Ensure connections are returned to the pool regularly, and not retained for long periods.
24+
2325

2426
## How do I use IAM with the AWS Python Driver?
2527
1. Configure IAM roles for the cluster according to [Using database roles and IAM authentication](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/using-database-and-iam-roles.html).
@@ -28,7 +30,7 @@ The AWS Python Driver supports Amazon AWS Identity and Access Management (IAM) a
2830
| Parameter | Value | Required | Description | Example Value |
2931
|--------------------|:-------:|:--------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|
3032
| `iam_host` | String | No | This property will override the default hostname that is used to generate the IAM token. The default hostname is derived from the connection string. This parameter is required when users are connecting with custom endpoints. | `cluster-identifier.dsql.us-east-1.on.aws` |
31-
| `iam_region` | String | No | This property will override the default region that is used to generate the IAM token. The default region is parsed from the connection string. | `us-east-2` |
33+
| `iam_region` | String | No | This property will override the default region that is used to generate the IAM token. The default region is parsed from the connection string where possible. Some connection string formats may not be supported, and the `iam_region` must be provided in these cases. | `us-east-2` |
3234
| `iam_expiration` | Integer | No | This property determines how long an IAM token is kept in the driver cache before a new one is generated. The default expiration time is set to 14 minutes and 30 seconds. Note that IAM database authentication tokens have a lifetime of 15 minutes. | `600` |
3335

3436
## Sample code

docs/using-the-python-driver/using-plugins/UsingTheIamAuthenticationPlugin.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ The IAM Authentication plugin requires authentication via AWS Credentials. These
1111

1212
To enable the IAM Authentication Connection Plugin, add the plugin code `iam` to the [`plugins`](../UsingThePythonDriver.md#connection-plugin-manager-parameters) parameter.
1313

14+
> [!WARNING]\
15+
> The `iam` plugin must NOT be specified when using the `iam_dsql` plugin.
16+
1417
## AWS IAM Database Authentication
1518
The AWS Python Driver supports Amazon AWS Identity and Access Management (IAM) authentication. When using AWS IAM database authentication, the host URL must be a valid Amazon endpoint, and not a custom domain or an IP address.
1619
<br>i.e. `db-identifier.cluster-XYZ.us-east-2.rds.amazonaws.com`

0 commit comments

Comments
 (0)