[CMCSMACD-6133] Support search_path in postgres+rds-iam scheme#21
Conversation
Also, use "config" param when adding a search path to a regular postgres DSN because that is supported by both psql and the Go pq library, whereas search_path is only supported by the latter.
leslie-corbalt
left a comment
There was a problem hiding this comment.
I had a few comments.
There was a problem hiding this comment.
This comment is stale. Maybe:
// addSearchPathToURL returns a copy of rawURL with search_path set through
// the PostgreSQL options connection parameter. This produces a URL accepted by
// libpq/psql, unlike adding search_path as a direct query parameter.
// It returns an error if search_path is already present.
There was a problem hiding this comment.
I updated the comment. What do you think?
| @@ -143,7 +143,10 @@ func addSearchPathToURL(rawURL string, searchPath string) (string, error) { | |||
| if v := q.Get("search_path"); v != "" { | |||
There was a problem hiding this comment.
If search_path is present we want to fail.
For ?search_path=, q.Get("search_path") returns an empty string, so the check does not fire.
After options is set to search_path, we could get something we don't want
postgres://user:pass@host/db?options=-csearch_path%3Dmy_schema&search_path=
Better to check for search_path using a map. Ditto for q.Get("options")
if _, ok := q["search_path"]; ok {
return "", fmt.Errorf("search_path already set")
}
There was a problem hiding this comment.
Good point! Done
| }, nil | ||
| } | ||
|
|
||
| if searchPath := q.Get("search_path"); searchPath != "" { |
There was a problem hiding this comment.
If search_path is present, require exactly one non-empty value before applying it WithSchemaSearchPath
values, ok := q["search_path"]
Then you can check:
if !ok {
// not configured
}
if len(values) != 1 || values[0] == "" {
// invalid
}
There was a problem hiding this comment.
Did something like this but didn't check against empty string. Don't see any reason we need to disallow it at this level.
Also, use "config" param when adding a search path to a regular postgres DSN because that is supported by both psql and the Go pq library, whereas search_path is only supported by the latter.
Testing: successfully
cmd/rds-iam-to-dsnwith a search path to generate a DSN with a token and a search path that is valid for use withpsqlpgutils.WithSchemaSearchPathto add a search path and successfully connected withpgutils.MustConnectDBandpgutils.ToConnectorand executed a query.PR Checklist
Examples:
To provide feedback on this template, visit https://docs.google.com/document/d/1YfTv7Amyop5G_8w1c2GJ_Mu-70L0KkZHhm9f9umDi3U/edit