Skip to content

Commit

Permalink
Remove port from endpoint if provided
Browse files Browse the repository at this point in the history
Signed-off-by: Timotej Avsec <[email protected]>
  • Loading branch information
tavsec committed Sep 14, 2023
1 parent d71567a commit fe4b811
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/clients/mssql/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/clients/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 4 additions & 0 deletions pkg/clients/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"net/url"
"strings"

"github.com/crossplane-contrib/provider-sql/pkg/clients/xsql"
"github.com/lib/pq"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fe4b811

Please sign in to comment.