From fe4b81175849e17ab0dc60c202039709cd477ac9 Mon Sep 17 00:00:00 2001 From: Timotej Avsec Date: Thu, 14 Sep 2023 16:05:44 +0200 Subject: [PATCH] Remove port from endpoint if provided Signed-off-by: Timotej Avsec --- pkg/clients/mssql/mssql.go | 3 +++ pkg/clients/mysql/mysql.go | 1 + pkg/clients/postgresql/postgresql.go | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/pkg/clients/mssql/mssql.go b/pkg/clients/mssql/mssql.go index 89189140..0cd6563b 100644 --- a/pkg/clients/mssql/mssql.go +++ b/pkg/clients/mssql/mssql.go @@ -48,6 +48,9 @@ func New(creds map[string][]byte, database string) xsql.DB { endpoint := string(creds[xpv1.ResourceCredentialsSecretEndpointKey]) port := string(creds[xpv1.ResourceCredentialsSecretPortKey]) + // Remove port from endpoint if it is added to the endpoint + endpoint = strings.Split(endpoint, ":")[0] + host := endpoint if port != "" { host = fmt.Sprintf("%s:%s", endpoint, port) diff --git a/pkg/clients/mysql/mysql.go b/pkg/clients/mysql/mysql.go index fa88db40..5ecdf0d2 100644 --- a/pkg/clients/mysql/mysql.go +++ b/pkg/clients/mysql/mysql.go @@ -38,6 +38,7 @@ func New(creds map[string][]byte, tls *string) xsql.DB { defaultTLS := "preferred" tls = &defaultTLS } + endpoint = strings.Split(endpoint, ":")[0] dsn := DSN(username, password, endpoint, port, *tls) return mySQLDB{ diff --git a/pkg/clients/postgresql/postgresql.go b/pkg/clients/postgresql/postgresql.go index 270bb92c..5fd930db 100644 --- a/pkg/clients/postgresql/postgresql.go +++ b/pkg/clients/postgresql/postgresql.go @@ -5,6 +5,7 @@ import ( "database/sql" "errors" "net/url" + "strings" "github.com/crossplane-contrib/provider-sql/pkg/clients/xsql" "github.com/lib/pq" @@ -38,6 +39,9 @@ func New(creds map[string][]byte, database, sslmode string) xsql.DB { password := string(creds[xpv1.ResourceCredentialsSecretPasswordKey]) dsn := DSN(username, password, endpoint, port, database, sslmode) + // Remove port from endpoint if it is added to the endpoint + endpoint = strings.Split(endpoint, ":")[0] + return postgresDB{ dsn: dsn, endpoint: endpoint,