Skip to content

Commit

Permalink
materialize-snowflake: percent encode username + password input
Browse files Browse the repository at this point in the history
The user/password encoding that `uri.User.String()` uses is actually slightly
different than `url.QueryEscape()`, and the latter is what is needed to handle
inputs with special characters to build a compatible Snowflake DSN.
  • Loading branch information
williamhbaker committed Sep 20, 2024
1 parent ae5e4da commit e2edd27
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
will:some%2Bcomplex%[email protected]:443?GO_QUERY_RESULT_FORMAT=json&MULTI_STATEMENT_COUNT=0&application=mytenant_EstuaryFlow&client_session_keep_alive=true&database=mydb&schema=myschema

This file was deleted.

This file was deleted.

7 changes: 4 additions & 3 deletions materialize-snowflake/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ func (c *config) toURI(tenant string) (string, error) {
}

// Authentication
var user string
if c.Credentials.AuthType == UserPass {
uri.User = url.UserPassword(c.Credentials.User, c.Credentials.Password)
user = url.QueryEscape(c.Credentials.User) + ":" + url.QueryEscape(c.Credentials.Password)
} else if c.Credentials.AuthType == JWT {
// We run this as part of validate to ensure that there is no error, so
// this is not expected to error here.
Expand All @@ -83,12 +84,12 @@ func (c *config) toURI(tenant string) (string, error) {
queryParams.Add("privateKey", privateKeyString)
queryParams.Add("authenticator", strings.ToLower(sf.AuthTypeJwt.String()))
}
uri.User = url.User(c.Credentials.User)
user = url.QueryEscape(c.Credentials.User)
} else {
return "", fmt.Errorf("unknown auth type: %s", c.Credentials.AuthType)
}

dsn := uri.User.String() + "@" + uri.Hostname() + ":" + uri.Port() + "?" + queryParams.Encode()
dsn := user + "@" + uri.Hostname() + ":" + uri.Port() + "?" + queryParams.Encode()
return dsn, nil
}

Expand Down
4 changes: 2 additions & 2 deletions materialize-snowflake/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (

func TestConfigURI(t *testing.T) {
for name, cfg := range map[string]config{
"v2 User & Password Authentication": {
"User & Password Authentication": {
Host: "orgname-accountname.snowflakecomputing.com",
Database: "mydb",
Schema: "myschema",
Credentials: credentialConfig{
UserPass,
"will",
"password",
"some+complex/password",
"non-existant-jwt",
},
},
Expand Down

0 comments on commit e2edd27

Please sign in to comment.