Skip to content

Commit

Permalink
fix: connection string with iam auth (#3563)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine authored Nov 28, 2024
1 parent 533cb8d commit 5e55167
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/dsn/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 5e55167

Please sign in to comment.