go-gorm / bigquery

BigQuery golang sql driver/GORM dialect
MIT License
41 stars 23 forks source link

Support using Credentials JSON to connect to BigQuery #22

Closed chexton closed 6 months ago

chexton commented 6 months ago

What did this pull request do?

Adds support for WithCredentialsJSON (see Google docs) instead of requiring a credentials file.

This helps provide a way to limit credentials living on disk/in long-lived files.

Expects a base64 encoded credentials file passed in as a URL query parameter.

User Case Description

We don't store credentials on disk but still want a way to explicitly pass them to the underlying Go driver for connecting to BigQuery.

chexton commented 6 months ago

Have tested successfully.

Example of usage, where encodedString is a base64 encoded JSON key for a GCP Service Account.

db, err := sql.Open("bigquery", "bigquery://PROJECT_ID/DATASET?credential_json=" + encodedString)
if err != nil {
  fmt.Println(err)
}
defer db.Close()