Skip to content

Commit 96d17d8

Browse files
author
Chris Hundt
committed
Support search_path in postgres+rds-iam scheme
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.
1 parent 9a1ff04 commit 96d17d8

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

pgutils/connector.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ func addSearchPathToURL(rawURL string, searchPath string) (string, error) {
143143
if v := q.Get("search_path"); v != "" {
144144
return "", fmt.Errorf("search_path already set to %q", v)
145145
}
146-
q.Set("search_path", searchPath)
146+
if v := q.Get("options"); v != "" {
147+
return "", fmt.Errorf("options already set to %q", v)
148+
}
149+
q.Set("options", fmt.Sprintf("-csearch_path=%s", searchPath))
147150
u.RawQuery = q.Encode()
148151
return u.String(), nil
149152
}
@@ -247,6 +250,7 @@ func newIAMConnectionStringProviderFromURL(ctx context.Context, u *url.URL, onTo
247250
supportedParams := map[string]struct{}{
248251
"assume_role_arn": {},
249252
"assume_role_session_name": {},
253+
"search_path": {},
250254
}
251255
for k := range q {
252256
if _, ok := supportedParams[k]; !ok {
@@ -278,7 +282,7 @@ func newIAMConnectionStringProviderFromURL(ctx context.Context, u *url.URL, onTo
278282
creds = aws.NewCredentialsCache(assumeProvider)
279283
}
280284

281-
return &rdsIAMConnectionStringProvider{
285+
var p ConnectionStringProvider = &rdsIAMConnectionStringProvider{
282286
Region: awsCfg.Region,
283287
RDSEndpoint: net.JoinHostPort(host, port),
284288
User: user,
@@ -287,5 +291,11 @@ func newIAMConnectionStringProviderFromURL(ctx context.Context, u *url.URL, onTo
287291
AssumeRoleARN: assumeRoleARN,
288292
AssumeRoleSessionName: sessionName,
289293
OnTokenSign: onTokenSign,
290-
}, nil
294+
}
295+
296+
if searchPath := q.Get("search_path"); searchPath != "" {
297+
p = WithSchemaSearchPath(p, searchPath)
298+
}
299+
300+
return p, nil
291301
}

0 commit comments

Comments
 (0)