Skip to content

Commit

Permalink
feat: support Application Default Credentials in googlecloud (#18)
Browse files Browse the repository at this point in the history
* feat: support Application Default Credentials

* Update googlecloud.go

---------

Co-authored-by: Yang Luo <[email protected]>
  • Loading branch information
notdu and hsluoyz authored Aug 14, 2024
1 parent 8c2ae92 commit d9cc8ee
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions googlecloud/googlecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,19 @@ type Config struct {

// New initializes Google Cloud Storage
func New(config *Config) (*Client, error) {
ctx := context.Background()
credentials, err := google.CredentialsFromJSON(ctx, []byte(config.ServiceAccountJson), "https://www.googleapis.com/auth/cloud-platform")
var (
ctx = context.Background()
scope = "https://www.googleapis.com/auth/cloud-platform"

credentials *google.Credentials
err error
)

if config.ServiceAccountJson != "" {
credentials, err = google.CredentialsFromJSON(ctx, []byte(config.ServiceAccountJson), scope)
} else {
credentials, err = google.FindDefaultCredentials(ctx, scope)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d9cc8ee

Please sign in to comment.