@@ -3,6 +3,7 @@ package bigquery
33import (
44 "context"
55 _ "embed" // used to print the embedded assets
6+ "encoding/base64"
67 "encoding/json"
78 "html/template"
89 "strings"
@@ -30,7 +31,9 @@ var summary string
3031
3132// Config holds the set of configuration for the bigquery extractor
3233type Config struct {
33- ProjectID string `mapstructure:"project_id" validate:"required"`
34+ ProjectID string `mapstructure:"project_id" validate:"required"`
35+ // ServiceAccountBase64 takes precedence over ServiceAccountJSON field
36+ ServiceAccountBase64 string `mapstructure:"service_account_base64"`
3437 ServiceAccountJSON string `mapstructure:"service_account_json"`
3538 MaxPageSize int `mapstructure:"max_page_size"`
3639 TablePattern string `mapstructure:"table_pattern"`
@@ -50,6 +53,9 @@ project_id: google-project-id
5053table_pattern: gofood.fact_
5154max_page_size: 100
5255include_column_profile: true
56+ # Only one of service_account_base64 / service_account_json is needed.
57+ # If both are present, service_account_base64 takes precedence
58+ service_account_base64: ____base64_encoded_service_account____
5359service_account_json: |-
5460 {
5561 "type": "service_account",
@@ -144,11 +150,20 @@ func (e *Extractor) Extract(ctx context.Context, emit plugins.Emit) (err error)
144150
145151// Create big query client
146152func (e * Extractor ) createClient (ctx context.Context ) (* bigquery.Client , error ) {
147- if e .config .ServiceAccountJSON == "" {
153+ if e .config .ServiceAccountBase64 == "" && e . config . ServiceAccountJSON == "" {
148154 e .logger .Info ("credentials are not specified, creating bigquery client using default credentials..." )
149155 return bigquery .NewClient (ctx , e .config .ProjectID )
150156 }
151157
158+ if e .config .ServiceAccountBase64 != "" {
159+ serviceAccountJSON , err := base64 .StdEncoding .DecodeString (e .config .ServiceAccountBase64 )
160+ if err != nil || len (serviceAccountJSON ) == 0 {
161+ return nil , errors .Wrap (err , "failed to decode base64 service account" )
162+ }
163+ // overwrite ServiceAccountJSON with credentials from ServiceAccountBase64 value
164+ e .config .ServiceAccountJSON = string (serviceAccountJSON )
165+ }
166+
152167 return bigquery .NewClient (ctx , e .config .ProjectID , option .WithCredentialsJSON ([]byte (e .config .ServiceAccountJSON )))
153168}
154169
0 commit comments