Skip to content

Commit

Permalink
snowpipe: fix nil pointer when switching to typed atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
rockwotj committed Oct 10, 2024
1 parent 393aced commit d6c0280
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions internal/impl/snowflake/streaming/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"errors"
"os"
"testing"

Expand All @@ -28,24 +29,27 @@ func msg(s string) *service.Message {
func TestSnowflake(t *testing.T) {
ctx := context.Background()
privateKeyFile, err := os.ReadFile("./resources/rsa_key.p8")
if errors.Is(err, os.ErrNotExist) {
t.Skip("no RSA private key, skipping snowflake test")
}
require.NoError(t, err)
block, _ := pem.Decode(privateKeyFile)
require.NoError(t, err)
parseResult, err := x509.ParsePKCS8PrivateKey(block.Bytes)
require.NoError(t, err)
client, err := streaming.NewSnowflakeServiceClient(ctx, streaming.ClientOptions{
Account: "RGHBUPG-TV88687",
User: "ROCKWOODREDPANDAAZ",
Account: "WQKFXQQ-WI77362",
User: "ROCKWOODREDPANDA",
Role: "ACCOUNTADMIN",
PrivateKey: parseResult.(*rsa.PrivateKey),
})
require.NoError(t, err)
defer client.Close()
channel, err := client.OpenChannel(ctx, streaming.ChannelOptions{
Name: "my_first_testing_channel",
DatabaseName: "AZURE_DB",
DatabaseName: "BABY_DATABASE",
SchemaName: "PUBLIC",
TableName: "AZURE_TABLE",
TableName: "TEST_TABLE",
})
require.NoError(t, err)
for i := 0; i < 1; i++ {
Expand Down
3 changes: 2 additions & 1 deletion internal/impl/snowflake/streaming/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ type restClient struct {
logger *service.Logger

authRefreshLoop *periodic.Periodic
cachedJWT typed.AtomicValue[string]
cachedJWT *typed.AtomicValue[string]
}

func newRestClient(account, user string, privateKey *rsa.PrivateKey, logger *service.Logger) (c *restClient, err error) {
Expand All @@ -277,6 +277,7 @@ func newRestClient(account, user string, privateKey *rsa.PrivateKey, logger *ser
privateKey: privateKey,
userAgent: userAgent,
logger: logger,
cachedJWT: typed.NewAtomicValue(""),
authRefreshLoop: periodic.New(
time.Hour-(2*time.Minute),
func() {
Expand Down

0 comments on commit d6c0280

Please sign in to comment.