Fix(redshift): add missing db_user parameter for IAM auth by synthpieter · Pull Request #5687 · SQLMesh/sqlmesh
Problem
SQLMesh's Redshift connection configuration was missing the db_user parameter, which is required by the redshift_connector library when using IAM authentication.
When enabling iam (iam: True) in the connection config it throws, understandably so, an InterfaceError
redshift_connector.error.InterfaceError: Connection parameter db_user must be specified when using IAM authentication
However, it was not allowed to add this parameter to the config.
Error: Invalid 'redshift' connection config: Invalid field 'db_user': Extra inputs are not permitted Verify your config.yaml and environment variables.
So iam authentication was not really useable.
Solution
Added the db_user field to the RedshiftConnectionConfig class in three places:
- Documentation - Added parameter description in the docstring and docs
- Field Declaration - Added
db_user: t.Optional[str] = Noneto the class - Connection Kwargs - Added
"db_user"to the_connection_kwargs_keysproperty - Tests - Added db_user to corresponding test.
Usage
With this fix, you can now configure Redshift IAM authentication in config.yaml:
gateways: redshift: connection: type: redshift database: your_database host: your-cluster.region.redshift.amazonaws.com port: 5439 cluster_identifier: your-cluster iam: True db_user: your_db_username
Fixes #2146
Disclaimer
This is my first contribution to an open source project ever, so please let me know if this is the right way of doing things :)
I locally give the fix a spin and it seems to fix the problem!