-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Per @hjr3 moving this over from pg-connection-string's repo.
This is perhaps a little "too cute", but for applications/libraries that use Amazon's RDS for their postgres db, RDS/CloudFormation can auto-manage the database user/password as secrets in the AWS Secrets Manager.
See here, which is not terribly succinct, but basically CloudFormation auto-secrets a secret, and "attaches" it to the PG instance, so that applications can (assuming they're granted access) look up the secret to get the connection info.
Helpfully, the secret has both user/pass as well as connection information, i.e. it's basically all the connection info an application needs, encoded in JSON that looks like:
{
"host":"whateverrds.amazon.com",
"port":5432,
"username":"...",
"password":"...",
"dbname":"..."
}(Without newlines, just formatted for the issue.)
This value is typically passed to the application as an environment (i.e. read securely by the instance/container when it boots up), similar to how PG connection info is normally passed, but now as this JSON key/value pairs instead of the OG postgres:// connection string.
For my library, I'd like to easily support "runs with existing postgres://... connections" as well as "just pass the RDS connection JSON thingy", and have both just work.
Which I can handle manually, but it seems neat if parse(...) itself would recognize the ^ format (i.e. if the first char of the string is a { then assume "this is RDS-style JSON") and return the appropriate ConnectionInfo.
Granted, this adds some RDS-specific behavior to node-postgres/pg-connection-string, and fwiw I don't know why they didn't just use a postgres://... connection string instead of this JSON value 🤷, but given how widespread RDS is, it seems potentially worth the ROI to implement this "pretend/great JSON is a connection string" once here, and have all node-postgres / RDS / RDS-managed-secret users be able to use it.
I can work on a PR if this sounds okay.