Skip to content

Commit

Permalink
Make GoogleCloudCredentials optional to support WorkloadIdentity (#433)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
  • Loading branch information
fjogeleit authored May 8, 2024
1 parent 836d6fe commit 842e372
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/helper/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ func (c *gcsClient) Upload(body *bytes.Buffer, key string) error {

// NewGCSClient creates a new GCS.client to send Results to GCS Bucket
func NewGCSClient(ctx context.Context, credentials, bucket string) GCPClient {
cred, err := google.CredentialsFromJSON(ctx, []byte(credentials), storage.ScopeReadWrite)
if err != nil {
zap.L().Error("error while creating GCS credentials", zap.Error(err))
return nil
options := make([]option.ClientOption, 0, 1)

if credentials != "" {
cred, err := google.CredentialsFromJSON(ctx, []byte(credentials), storage.ScopeReadWrite)
if err != nil {
zap.L().Error("error while creating GCS credentials", zap.Error(err))
return nil
}

options = append(options, option.WithCredentials(cred))
}

client, err := storage.NewClient(ctx, option.WithCredentials(cred))
client, err := storage.NewClient(ctx, options...)
if err != nil {
zap.L().Error("error while creating GCS client", zap.Error(err))
return nil
Expand Down

0 comments on commit 842e372

Please sign in to comment.