From 5e55167108a9757ccb740492bb6c42b85445e9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juho=20M=C3=A4kinen?= Date: Thu, 28 Nov 2024 17:46:15 +1100 Subject: [PATCH] fix: connection string with iam auth (#3563) --- internal/dsn/dsn.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/dsn/dsn.go b/internal/dsn/dsn.go index 854ccf91e..ba7e3ad84 100644 --- a/internal/dsn/dsn.go +++ b/internal/dsn/dsn.go @@ -3,6 +3,7 @@ package dsn import ( "context" "fmt" + "net" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/feature/rds/auth" @@ -63,7 +64,11 @@ func ResolvePostgresDSN(ctx context.Context, connector schema.DatabaseConnector) if err != nil { return "", fmt.Errorf("failed to create authentication token: %w", err) } - return fmt.Sprintf("postgres://%s:%s@%s/%s", c.Username, authenticationToken, c.Endpoint, c.Database), nil + host, port, err := net.SplitHostPort(c.Endpoint) + if err != nil { + return "", fmt.Errorf("failed to split host and port: %w", err) + } + return fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", host, port, c.Database, c.Username, authenticationToken), nil default: return "", fmt.Errorf("unexpected database connector type: %T", connector) }