Skip to content

Comments

Replace PostgresqlConnector with ConnectionStringProvider#18

Open
andrew-corbalt wants to merge 13 commits intomainfrom
acremins-rds-iam-dsn
Open

Replace PostgresqlConnector with ConnectionStringProvider#18
andrew-corbalt wants to merge 13 commits intomainfrom
acremins-rds-iam-dsn

Conversation

@andrew-corbalt
Copy link
Contributor

@andrew-corbalt andrew-corbalt commented Dec 23, 2025

PR Description

To simplify handling both RDS IAM auth and conventional password auth postgres connections, PostgresqlConnector is replaced with ConnectionStringProvider which adds the concept of a custom DSN postgres+rds-iam://<user>@<host>[:<port>]/<dbname> for IAM auth. Alternatively, a normal postgres DSN can be used with conventional password auth.

Tests:
Updated the ProfessorMAC app and microservices to use ConnectionStringProvider and verified function

PR Checklist

  • New automated tests have been written to the extent possible.
  • The code has been checked for structural/syntactic validity.
    • AMI/application: a build was performed
    • terraform changes: "terraform plan" checked on every affected environment
  • (If applicable) the code has been manually tested on our infrastructure.
    • AMI/application: deployed an a test or dev environment
    • terraform changes: applied to test or dev environment
    • script: run against test or dev environment
  • Likely failure points and new functionality have been identified and tested manually.
    Examples:
    • Application manually run in a way that triggers any new branches
    • AMI logged into and changes verified from login shell
  • Pull request description includes a description of all the manual steps performed to accomplish the above.

To provide feedback on this template, visit https://docs.google.com/document/d/1YfTv7Amyop5G_8w1c2GJ_Mu-70L0KkZHhm9f9umDi3U/edit

jonahb
jonahb previously requested changes Dec 29, 2025
Copy link

@jonahb jonahb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I like the new approach. I guess it'd also be worth thinking about whether we want to tweak things per Slack thread and how this change might fit into that.

Copy link
Contributor

@hundt-corbalt hundt-corbalt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@andrew-corbalt andrew-corbalt changed the title Add NewPostgresqlConnectorFromDSN() to pgutils Replace PostgresqlConnector with ConnectionStringProvider Feb 10, 2026
Copy link
Contributor

@hundt-corbalt hundt-corbalt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM! But PR description still refers to an older version of the code. Can you update that?

@andrew-corbalt
Copy link
Contributor Author

Code LGTM! But PR description still refers to an older version of the code. Can you update that?

done

@andrew-corbalt andrew-corbalt dismissed jonahb’s stale review February 11, 2026 19:01

Code has been rewritten since the requested change was submitted. Feel free to re-review the new version that was made with Chris' input!

Copy link
Contributor

@hundt-corbalt hundt-corbalt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

//
// IAM example 2 (cross-account):
//
// postgres+rds-iam://user@host:5432/dbname?assume_role_arn=...&assume_role_session_name=...
Copy link
Contributor

@leslie-corbalt leslie-corbalt Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace host:5432 with <rds-endpoint>?
to be consistent with the README in professor-mac repo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

//
// IAM example 1:
//
// postgres+rds-iam://user@host:5432/dbname
Copy link
Contributor

@leslie-corbalt leslie-corbalt Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace host:5432 with <rds-endpoint> to be consistent with professor-mac README?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

port = defaultPostgresPort
}

// Match libpq/psql defaulting: if dbname isn't specified, dbname defaults to username.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean: Match libpq/psql defaulting. Sounds cryptic to me.
Also, why set a default? Why not force the user to set this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the words after the ':' describe in more details what that means. if dbname isn't specified, dbname defaults to username. Is that confusing?

I mean we historically have relied on this all over the place. We have lots of connection strings that don't have /postgres at the end to specify the database, instead we rely on lib/psql behavior where if the username is 'postgres' then the database will be set to 'postgres' if you don't set it.


// ConnectDB opens a connection using the connector and verifies it with a ping
func ConnectDB(conn driver.Connector) (*sqlx.DB, error) {
sqlDB := sql.OpenDB(conn)
Copy link
Contributor

@leslie-corbalt leslie-corbalt Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is less code:
func ConnectDB(conn driver.Connector) (*sqlx.DB, error) {
db := sqlx.NewDb(sql.OpenDB(conn), "postgres")
if err := db.Ping(); err != nil {
db.Close()
return nil, err
}
return db, nil
}

You don't need the intermediate variable sqlDB.

},
return &rdsIAMConnectionStringProvider{
Region: awsCfg.Region,
RDSEndpoint: net.JoinHostPort(host, port),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you have Endpoint including port.
You mentioned that RDSEndpoint does not include port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants