Replace deprecated google.CredentialsFromJSON with option.WithAuthCredentialsFile

Signed-off-by: Ganesh Vernekar <ganesh.vernekar@reddit.com>
This commit is contained in:
Ganesh Vernekar 2026-02-10 13:03:14 -08:00
parent 847e474bf4
commit 0ede19e2ee

View file

@ -19,7 +19,6 @@ import (
"context"
"fmt"
"net/http"
"os"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
@ -42,15 +41,7 @@ func NewRoundTripper(cfg *Config, next http.RoundTripper) (http.RoundTripper, er
option.WithScopes(scopes),
}
if cfg.CredentialsFile != "" {
credBytes, err := os.ReadFile(cfg.CredentialsFile)
if err != nil {
return nil, fmt.Errorf("error reading Google credentials file: %w", err)
}
creds, err := google.CredentialsFromJSON(ctx, credBytes, scopes)
if err != nil {
return nil, fmt.Errorf("error parsing Google credentials file: %w", err)
}
opts = append(opts, option.WithCredentials(creds))
opts = append(opts, option.WithAuthCredentialsFile(option.ServiceAccount, cfg.CredentialsFile))
} else {
creds, err := google.FindDefaultCredentials(ctx, scopes)
if err != nil {