Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
enable BigQuery Default Credentials [nt]
Browse files Browse the repository at this point in the history
  • Loading branch information
flarco committed Nov 30, 2023
1 parent d34d66b commit 7215e34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions database/database_bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"math/big"
"os"
"path"
Expand Down Expand Up @@ -90,6 +89,7 @@ func (conn *BigQueryConn) Init() error {
func (conn *BigQueryConn) getNewClient(timeOut ...int) (client *bigquery.Client, err error) {
var authOption option.ClientOption
var credJsonBody string
var useDefault bool

to := 15
if len(timeOut) > 0 {
Expand All @@ -101,7 +101,7 @@ func (conn *BigQueryConn) getNewClient(timeOut ...int) (client *bigquery.Client,
authOption = option.WithCredentialsJSON([]byte(val))
} else if val := conn.GetProp("GC_KEY_FILE"); val != "" {
authOption = option.WithCredentialsFile(val)
b, err := ioutil.ReadFile(val)
b, err := os.ReadFile(val)
if err != nil {
return client, g.Error(err, "could not read google cloud key file")
}
Expand All @@ -110,14 +110,13 @@ func (conn *BigQueryConn) getNewClient(timeOut ...int) (client *bigquery.Client,
authOption = option.WithAPIKey(val)
} else if val := conn.GetProp("GOOGLE_APPLICATION_CREDENTIALS"); val != "" {
authOption = option.WithCredentialsFile(val)
b, err := ioutil.ReadFile(val)
b, err := os.ReadFile(val)
if err != nil {
return client, g.Error(err, "could not read google cloud key file")
}
credJsonBody = string(b)
} else {
err = g.Error("no Google credentials provided")
return
useDefault = true
}

if conn.ProjectID == "" && credJsonBody != "" {
Expand All @@ -128,6 +127,11 @@ func (conn *BigQueryConn) getNewClient(timeOut ...int) (client *bigquery.Client,

ctx, cancel := context.WithTimeout(conn.BaseConn.Context().Ctx, time.Duration(to)*time.Second)
defer cancel()

if useDefault {
g.Debug("no BigQuery Google credentials provided, using Application Default Credentials")
return bigquery.NewClient(ctx, conn.ProjectID)
}
return bigquery.NewClient(ctx, conn.ProjectID, authOption)
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/check_parquet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pyarrow.parquet as pq

file = pq.ParquetFile("filesys/test/test_write/parquet.test")
file = pq.ParquetFile("filesys/test/test1/parquet/test1.1.parquet")

print(f'num_row_groups: {file.num_row_groups}')
print(f'metadata: {file.metadata}')
Expand Down

0 comments on commit 7215e34

Please sign in to comment.