Skip to content

Commit

Permalink
Authenticate results spreadsheet creation using a google service acco…
Browse files Browse the repository at this point in the history
…unt (#2497)
  • Loading branch information
shirmoran authored Oct 8, 2024
1 parent b9023df commit b2e825f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 96 deletions.
77 changes: 0 additions & 77 deletions cmd/certsuite/upload/results_spreadsheet/client.go

This file was deleted.

23 changes: 4 additions & 19 deletions cmd/certsuite/upload/results_spreadsheet/results_spreadsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/spf13/cobra"

"golang.org/x/oauth2/google"
"google.golang.org/api/drive/v3"
"google.golang.org/api/option"
"google.golang.org/api/sheets/v4"
Expand Down Expand Up @@ -75,29 +74,15 @@ func readCSV(fp string) ([][]string, error) {

func CreateSheetsAndDriveServices(credentials string) (sheetService *sheets.Service, driveService *drive.Service, err error) {
ctx := context.Background()
b, err := os.ReadFile(credentials)
if err != nil {
return nil, nil, fmt.Errorf("unable to read client secret file: %v", err)
}

// If modifying these scopes, delete your previously saved token.json.
config, err := google.ConfigFromJSON(b, sheets.SpreadsheetsScope, drive.DriveScope)
if err != nil {
return nil, nil, fmt.Errorf("unable to parse client secret file to config: %v", err)
}
client, err := getClient(config)
if err != nil {
return nil, nil, fmt.Errorf("unable to get client: %v", err)
}

sheetSrv, err := sheets.NewService(ctx, option.WithHTTPClient(client))
sheetSrv, err := sheets.NewService(ctx, option.WithCredentialsFile(credentials))
if err != nil {
return nil, nil, fmt.Errorf("unable to retrieve Sheets client: %v", err)
return nil, nil, fmt.Errorf("unable to retrieve Sheets service: %v", err)
}

driveSrv, err := drive.NewService(ctx, option.WithHTTPClient(client))
driveSrv, err := drive.NewService(ctx, option.WithCredentialsFile(credentials))
if err != nil {
return nil, nil, fmt.Errorf("unable to retrieve Drive client: %v", err)
return nil, nil, fmt.Errorf("unable to retrieve Drive service: %v", err)
}

return sheetSrv, driveSrv, nil
Expand Down

0 comments on commit b2e825f

Please sign in to comment.