Skip to content

Commit

Permalink
Merge branch 'master' into SNOW-1825476-pat
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pfus authored Feb 25, 2025
2 parents c4cf34e + 11bb91f commit 48a99d9
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 70 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
fail-fast: false
matrix:
cloud: [ 'AWS', 'AZURE', 'GCP' ]
go: [ '1.21', '1.22', '1.23' ]
go: [ '1.22', '1.23', '1.24' ]
name: ${{ matrix.cloud }} Go ${{ matrix.go }} on Ubuntu
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
fail-fast: false
matrix:
cloud: [ 'AWS', 'AZURE', 'GCP' ]
go: [ '1.21', '1.22', '1.23' ]
go: [ '1.22', '1.23', '1.24' ]
name: ${{ matrix.cloud }} Go ${{ matrix.go }} on Mac
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
fail-fast: false
matrix:
cloud: [ 'AWS', 'AZURE', 'GCP' ]
go: [ '1.21', '1.22', '1.23' ]
go: [ '1.22', '1.23', '1.24' ]
name: ${{ matrix.cloud }} Go ${{ matrix.go }} on Windows
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ timestamps {
string(name: 'branch', value: 'main'),
string(name: 'client_git_commit', value: scmInfo.GIT_COMMIT),
string(name: 'client_git_branch', value: scmInfo.GIT_BRANCH),
string(name: 'TARGET_DOCKER_TEST_IMAGE', value: 'go-centos7-go1.21'),
string(name: 'TARGET_DOCKER_TEST_IMAGE', value: 'go-chainguard-go1_24'),
string(name: 'parent_job', value: env.JOB_NAME),
string(name: 'parent_build_number', value: env.BUILD_NUMBER)
]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_setup: test_teardown
python3 ci/scripts/hang_webserver.py 12345 &

test_teardown:
kill -9 $$(ps -ewf | grep hang_webserver | grep -v grep | awk '{print $$2}') || true
kill -9 $$(ps -ef | grep hang_webserver | grep -v grep | awk '{print $$1}') || true

test: deps test_setup
./ci/scripts/execute_tests.sh
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The following software packages are required to use the Go Snowflake Driver.

## Go

The latest driver requires the [Go language](https://golang.org/) 1.20 or higher. The supported operating systems are Linux, Mac OS, and Windows, but you may run the driver on other platforms if the Go language works correctly on those platforms.
The latest driver requires the [Go language](https://golang.org/) 1.22 or higher. The supported operating systems are Linux, Mac OS, and Windows, but you may run the driver on other platforms if the Go language works correctly on those platforms.


# Installation
Expand Down
7 changes: 5 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ func prepareJWTToken(config *Config) (string, error) {
if config.PrivateKey == nil {
return "", errors.New("trying to use keypair authentication, but PrivateKey was not provided in the driver config")
}
logger.Debug("preparing JWT for keypair authentication")
pubBytes, err := x509.MarshalPKIXPublicKey(config.PrivateKey.Public())
if err != nil {
return "", err
Expand All @@ -510,20 +511,22 @@ func prepareJWTToken(config *Config) (string, error) {
userName := strings.ToUpper(config.User)

issueAtTime := time.Now().UTC()
token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{
jwtClaims := jwt.MapClaims{
"iss": fmt.Sprintf("%s.%s.%s", accountName, userName, "SHA256:"+base64.StdEncoding.EncodeToString(hash[:])),
"sub": fmt.Sprintf("%s.%s", accountName, userName),
"iat": issueAtTime.Unix(),
"nbf": time.Date(2015, 10, 10, 12, 0, 0, 0, time.UTC).Unix(),
"exp": issueAtTime.Add(config.JWTExpireTimeout).Unix(),
})
}
token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwtClaims)

tokenString, err := token.SignedString(config.PrivateKey)

if err != nil {
return "", err
}

logger.Debugf("successfully generated JWT with following claims: %v", jwtClaims)
return tokenString, err
}

Expand Down
4 changes: 2 additions & 2 deletions ci/_init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/usr/bin/env -e

export PLATFORM=$(echo $(uname) | tr '[:upper:]' '[:lower:]')
# Use the internal Docker Registry
Expand All @@ -10,6 +10,6 @@ export DRIVER_NAME=go

TEST_IMAGE_VERSION=1
declare -A TEST_IMAGE_NAMES=(
[$DRIVER_NAME-centos7-go1.21]=$DOCKER_REGISTRY_NAME/client-$DRIVER_NAME-centos7-go1.21-test:$TEST_IMAGE_VERSION
[$DRIVER_NAME-chainguard-go1_24]=$DOCKER_REGISTRY_NAME/client-$DRIVER_NAME-chainguard-go1.24-test:$TEST_IMAGE_VERSION
)
export TEST_IMAGE_NAMES
17 changes: 17 additions & 0 deletions ci/image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM artifactory.int.snowflakecomputing.com/development-chainguard-virtual/snowflake.com/go:1.24.0-dev

USER root

RUN apk update && apk add python3 python3-dev jq aws-cli gosu py3-pip
RUN python3 -m ensurepip
RUN pip install -U snowflake-connector-python

# workspace
RUN mkdir -p /home/user && \
chmod 777 /home/user
WORKDIR /mnt/host

# entry point
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
43 changes: 0 additions & 43 deletions ci/image/Dockerfile.go-centos7-go1.21-test

This file was deleted.

4 changes: 2 additions & 2 deletions ci/image/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/usr/bin/env bash -e
#
# Build Docker images
#
Expand All @@ -9,7 +9,7 @@ source $THIS_DIR/../_init.sh
for name in "${!TEST_IMAGE_NAMES[@]}"; do
docker build \
--platform linux/amd64 \
--file $THIS_DIR/Dockerfile.$name-test \
--file $THIS_DIR/Dockerfile \
--label snowflake \
--label $DRIVER_NAME \
--tag ${TEST_IMAGE_NAMES[$name]} .
Expand Down
9 changes: 6 additions & 3 deletions ci/image/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/bin/bash -x
#!/bin/bash -ex
# Add local user
# Either use the LOCAL_USER_ID if passed in at runtime or
# fallback

USER_ID=${LOCAL_USER_ID:-9001}

echo "Starting with UID : $USER_ID"
useradd --shell /bin/bash -u $USER_ID -o -c "" -m user
adduser -s /bin/bash -u $USER_ID -h /home/user -D user
export HOME=/home/user
mkdir -p /home/user/.cache
chown user:user /home/user/.cache

exec gosu user "$@"

exec /usr/local/bin/gosu user "$@"
2 changes: 1 addition & 1 deletion ci/image/update.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#!/usr/bin/env bash -e
#
# Build Docker images
#
Expand Down
2 changes: 1 addition & 1 deletion ci/scripts/execute_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cd $TOPDIR
if [[ -n "$JENKINS_HOME" ]]; then
export WORKSPACE=${WORKSPACE:-/mnt/workspace}
go install github.com/jstemmer/go-junit-report/v2@latest
go test $GO_TEST_PARAMS -timeout 90m -race -v . | go-junit-report -iocopy -out $WORKSPACE/junit-go.xml
go test $GO_TEST_PARAMS -timeout 90m -race -v . | /home/user/go/bin/go-junit-report -iocopy -out $WORKSPACE/junit-go.xml
else
go test $GO_TEST_PARAMS -timeout 90m -race -coverprofile=coverage.txt -covermode=atomic -v .
fi
15 changes: 15 additions & 0 deletions converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2480,3 +2480,18 @@ func TestIsArrayOfStructs(t *testing.T) {
})
}
}

func TestSqlNull(t *testing.T) {
runDBTest(t, func(dbt *DBTest) {
rows := dbt.mustQuery("SELECT 1, NULL UNION SELECT 2, 'test' ORDER BY 1")
defer rows.Close()
var rowID int
var nullStr sql.Null[string]
assertTrueF(t, rows.Next())
assertNilF(t, rows.Scan(&rowID, &nullStr))
assertEqualE(t, nullStr, sql.Null[string]{Valid: false})
assertTrueF(t, rows.Next())
assertNilF(t, rows.Scan(&rowID, &nullStr))
assertEqualE(t, nullStr, sql.Null[string]{Valid: true, V: "test"})
})
}
11 changes: 3 additions & 8 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package gosnowflake

import (
"cmp"
"context"
"crypto/rsa"
"database/sql"
Expand Down Expand Up @@ -52,10 +53,7 @@ const (
func init() {
// get environment variables
env := func(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
return cmp.Or(os.Getenv(key), defaultValue)
}
username = env("SNOWFLAKE_TEST_USER", "testuser")
pass = env("SNOWFLAKE_TEST_PASSWORD", "testpassword")
Expand Down Expand Up @@ -107,10 +105,7 @@ func createDSN(timezone string) {
// setup creates a test schema so that all tests can run in the same schema
func setup() (string, error) {
env := func(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
return cmp.Or(os.Getenv(key), defaultValue)
}

orgSchemaname := schemaname
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/snowflakedb/gosnowflake

go 1.21
go 1.22

require (
github.com/99designs/keyring v1.2.2
Expand Down
2 changes: 1 addition & 1 deletion structured_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
type ObjectType struct {
}

var structuredObjectWriterType = reflect.TypeOf((*StructuredObjectWriter)(nil)).Elem()
var structuredObjectWriterType = reflect.TypeFor[StructuredObjectWriter]()

// StructuredObject is a representation of structured object for reading.
type StructuredObject interface {
Expand Down

0 comments on commit 48a99d9

Please sign in to comment.