-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1825476 Implement programmatic access token (PAT)
- Loading branch information
1 parent
e926883
commit b4261df
Showing
16 changed files
with
634 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
include ../../gosnowflake.mak | ||
CMD_TARGET=pat | ||
|
||
## Install | ||
install: cinstall | ||
|
||
## Run | ||
run: crun | ||
|
||
## Lint | ||
lint: clint | ||
|
||
## Format source codes | ||
fmt: cfmt | ||
|
||
.PHONY: install run lint fmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// you have to configure PAT on your user | ||
|
||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"flag" | ||
"fmt" | ||
sf "github.com/snowflakedb/gosnowflake" | ||
"log" | ||
) | ||
|
||
func main() { | ||
if !flag.Parsed() { | ||
flag.Parse() | ||
} | ||
|
||
cfg, err := sf.GetConfigFromEnv([]*sf.ConfigParam{ | ||
{Name: "Account", EnvName: "SNOWFLAKE_TEST_ACCOUNT", FailOnMissing: true}, | ||
{Name: "User", EnvName: "SNOWFLAKE_TEST_USER", FailOnMissing: true}, | ||
{Name: "Token", EnvName: "SNOWFLAKE_TEST_PAT", FailOnMissing: true}, | ||
{Name: "Host", EnvName: "SNOWFLAKE_TEST_HOST", FailOnMissing: false}, | ||
{Name: "Port", EnvName: "SNOWFLAKE_TEST_PORT", FailOnMissing: false}, | ||
{Name: "Protocol", EnvName: "SNOWFLAKE_TEST_PROTOCOL", FailOnMissing: false}, | ||
}) | ||
cfg.Authenticator = sf.AuthTypePat | ||
if err != nil { | ||
log.Fatalf("cannot build config. %v", err) | ||
} | ||
|
||
connector := sf.NewConnector(sf.SnowflakeDriver{}, *cfg) | ||
db := sql.OpenDB(connector) | ||
defer db.Close() | ||
|
||
query := "SELECT 1" | ||
rows, err := db.Query(query) | ||
if err != nil { | ||
log.Fatalf("failed to run a query. %v, err: %v", query, err) | ||
} | ||
defer rows.Close() | ||
var v int | ||
if !rows.Next() { | ||
log.Fatalf("no rows returned") | ||
} | ||
if err = rows.Scan(&v); err != nil { | ||
log.Fatalf("failed to scan rows. %v", err) | ||
} | ||
if v != 1 { | ||
log.Fatalf("unexpected result, expected 1, got %v", v) | ||
} | ||
fmt.Printf("Congrats! You have successfully run %v with Snowflake DB!\n", query) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1041,6 +1041,25 @@ func TestParseDSN(t *testing.T) { | |
ocspMode: ocspModeFailOpen, | ||
err: nil, | ||
}, | ||
{ | ||
dsn: "u:[email protected]:9876?account=a&protocol=http&authenticator=PROGRAMMATIC_ACCESS_TOKEN&disableSamlURLCheck=false&token=t", | ||
config: &Config{ | ||
Account: "a", User: "u", Password: "p", | ||
Authenticator: AuthTypePat, | ||
Protocol: "http", Host: "a.snowflake.local", Port: 9876, | ||
OCSPFailOpen: OCSPFailOpenTrue, | ||
ValidateDefaultParameters: ConfigBoolTrue, | ||
ClientTimeout: defaultClientTimeout, | ||
JWTClientTimeout: defaultJWTClientTimeout, | ||
ExternalBrowserTimeout: defaultExternalBrowserTimeout, | ||
CloudStorageTimeout: defaultCloudStorageTimeout, | ||
IncludeRetryReason: ConfigBoolTrue, | ||
DisableSamlURLCheck: ConfigBoolFalse, | ||
Token: "t", | ||
}, | ||
ocspMode: ocspModeFailOpen, | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, at := range []AuthType{AuthTypeExternalBrowser, AuthTypeOAuth} { | ||
|
@@ -1213,7 +1232,8 @@ func TestParseDSN(t *testing.T) { | |
if test.config.DisableSamlURLCheck != cfg.DisableSamlURLCheck { | ||
t.Fatalf("%v: Failed to match DisableSamlURLCheck. expected: %v, got: %v", i, test.config.DisableSamlURLCheck, cfg.DisableSamlURLCheck) | ||
} | ||
assertEqualF(t, cfg.ClientConfigFile, test.config.ClientConfigFile, "client config file") | ||
assertEqualE(t, cfg.Token, test.config.Token, "token") | ||
assertEqualE(t, cfg.ClientConfigFile, test.config.ClientConfigFile, "client config file") | ||
case test.err != nil: | ||
driverErrE, okE := test.err.(*SnowflakeError) | ||
driverErrG, okG := err.(*SnowflakeError) | ||
|
@@ -1465,6 +1485,17 @@ func TestDSN(t *testing.T) { | |
}, | ||
dsn: "u:[email protected]:443?authenticator=externalbrowser&clientStoreTemporaryCredential=false&ocspFailOpen=true&validateDefaultParameters=true", | ||
}, | ||
{ | ||
cfg: &Config{ | ||
User: "u", | ||
Password: "p", | ||
Account: "a", | ||
Token: "t", | ||
Authenticator: AuthTypePat, | ||
ClientStoreTemporaryCredential: ConfigBoolFalse, | ||
}, | ||
dsn: "u:[email protected]:443?authenticator=programmatic_access_token&clientStoreTemporaryCredential=false&ocspFailOpen=true&token=t&validateDefaultParameters=true", | ||
}, | ||
{ | ||
cfg: &Config{ | ||
User: "u", | ||
|
Oops, something went wrong.