Skip to content

Commit

Permalink
Merge pull request #38 from TheJokersThief/squarespace/use-adc-as-fal…
Browse files Browse the repository at this point in the history
…lback

Use the ADC as a default fallback
  • Loading branch information
eoinmcafee00 authored Apr 5, 2023
2 parents ce1e3a9 + 790ce8b commit 4ec4dd6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ func run(c *cli.Context) error {
return err
}
} else {
return errors.New("Either one of token or json key must be specified")
client, err = gcsClientApplicationDefaultCredentials()
if err != nil {
return err
}
}

return plugin.Exec(client)
Expand All @@ -150,6 +153,7 @@ func gcsClientWithToken(token string) (*storage.Client, error) {
}
return client, nil
}

func gcsClientWithJSONKey(jsonKey string, credFile *os.File) (*storage.Client, error) {
if _, err := credFile.Write([]byte(jsonKey)); err != nil {
return nil, errors.Wrap(err, "failed to write gcs credentials to file")
Expand All @@ -165,3 +169,12 @@ func gcsClientWithJSONKey(jsonKey string, credFile *os.File) (*storage.Client, e
}
return client, nil
}

func gcsClientApplicationDefaultCredentials() (*storage.Client, error) {
ctx := context.Background()
client, err := storage.NewClient(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to initialize storage")
}
return client, nil
}

0 comments on commit 4ec4dd6

Please sign in to comment.