Replace the service-account key file with application-default credentials

This commit is contained in:
Ian Gulliver
2026-08-19 22:27:46 -07:00
parent 0e934e02cd
commit fa86f5913c
8 changed files with 0 additions and 17 deletions
-2
View File
@@ -24,7 +24,6 @@ import (
"google.golang.org/api/drive/v3" "google.golang.org/api/drive/v3"
"google.golang.org/api/option" "google.golang.org/api/option"
"heliosian/internal/data"
) )
const ( const (
@@ -54,7 +53,6 @@ type Store struct {
func New() (*Store, error) { func New() (*Store, error) {
service, err := drive.NewService(context.Background(), service, err := drive.NewService(context.Background(),
option.WithCredentialsFile(data.KeyFile),
option.WithScopes(drive.DriveScope)) option.WithScopes(drive.DriveScope))
if err != nil { if err != nil {
return nil, err return nil, err
-3
View File
@@ -9,8 +9,6 @@ import (
"google.golang.org/api/sheets/v4" "google.golang.org/api/sheets/v4"
) )
const KeyFile = "creds/service-account.json"
type Sheet struct { type Sheet struct {
service *sheets.Service service *sheets.Service
spreadsheets map[string]string spreadsheets map[string]string
@@ -18,7 +16,6 @@ type Sheet struct {
func NewSheet(spreadsheets map[string]string) (*Sheet, error) { func NewSheet(spreadsheets map[string]string) (*Sheet, error) {
service, err := sheets.NewService(context.Background(), service, err := sheets.NewService(context.Background(),
option.WithCredentialsFile(KeyFile),
option.WithScopes(sheets.SpreadsheetsScope)) option.WithScopes(sheets.SpreadsheetsScope))
if err != nil { if err != nil {
return nil, err return nil, err
-2
View File
@@ -7,7 +7,6 @@ import (
"log" "log"
"strings" "strings"
"heliosian/internal/data"
"google.golang.org/api/option" "google.golang.org/api/option"
"google.golang.org/api/sheets/v4" "google.golang.org/api/sheets/v4"
) )
@@ -45,7 +44,6 @@ func main() {
log.Fatal("[ERROR] -sheet <spreadsheet id> is required") log.Fatal("[ERROR] -sheet <spreadsheet id> is required")
} }
svc, err := sheets.NewService(context.Background(), svc, err := sheets.NewService(context.Background(),
option.WithCredentialsFile(data.KeyFile),
option.WithScopes(sheets.SpreadsheetsScope)) option.WithScopes(sheets.SpreadsheetsScope))
if err != nil { if err != nil {
log.Fatalf("[ERROR] create sheets client: %v", err) log.Fatalf("[ERROR] create sheets client: %v", err)
-2
View File
@@ -10,7 +10,6 @@ import (
"os" "os"
"strings" "strings"
"heliosian/internal/data"
"google.golang.org/api/option" "google.golang.org/api/option"
"google.golang.org/api/sheets/v4" "google.golang.org/api/sheets/v4"
) )
@@ -24,7 +23,6 @@ func main() {
log.Fatal("[ERROR] -sheet, -tab, and -out are required") log.Fatal("[ERROR] -sheet, -tab, and -out are required")
} }
svc, err := sheets.NewService(context.Background(), svc, err := sheets.NewService(context.Background(),
option.WithCredentialsFile(data.KeyFile),
option.WithScopes(sheets.SpreadsheetsReadonlyScope)) option.WithScopes(sheets.SpreadsheetsReadonlyScope))
if err != nil { if err != nil {
log.Fatalf("[ERROR] create sheets client: %v", err) log.Fatalf("[ERROR] create sheets client: %v", err)
-2
View File
@@ -6,14 +6,12 @@ import (
"fmt" "fmt"
"log" "log"
"heliosian/internal/data"
"google.golang.org/api/drive/v3" "google.golang.org/api/drive/v3"
"google.golang.org/api/option" "google.golang.org/api/option"
) )
func main() { func main() {
svc, err := drive.NewService(context.Background(), svc, err := drive.NewService(context.Background(),
option.WithCredentialsFile(data.KeyFile),
option.WithScopes(drive.DriveReadonlyScope)) option.WithScopes(drive.DriveReadonlyScope))
if err != nil { if err != nil {
log.Fatalf("[ERROR] create drive client: %v", err) log.Fatalf("[ERROR] create drive client: %v", err)
-2
View File
@@ -8,14 +8,12 @@ import (
"log" "log"
"time" "time"
"heliosian/internal/data"
"google.golang.org/api/drive/v3" "google.golang.org/api/drive/v3"
"google.golang.org/api/option" "google.golang.org/api/option"
) )
func main() { func main() {
svc, err := drive.NewService(context.Background(), svc, err := drive.NewService(context.Background(),
option.WithCredentialsFile(data.KeyFile),
option.WithScopes(drive.DriveScope)) option.WithScopes(drive.DriveScope))
if err != nil { if err != nil {
log.Fatalf("[ERROR] drive client: %v", err) log.Fatalf("[ERROR] drive client: %v", err)
-2
View File
@@ -8,7 +8,6 @@ import (
"log" "log"
"strings" "strings"
"heliosian/internal/data"
"google.golang.org/api/option" "google.golang.org/api/option"
"google.golang.org/api/sheets/v4" "google.golang.org/api/sheets/v4"
) )
@@ -25,7 +24,6 @@ func main() {
log.Fatal("[ERROR] -sheet <spreadsheet id> is required") log.Fatal("[ERROR] -sheet <spreadsheet id> is required")
} }
svc, err := sheets.NewService(context.Background(), svc, err := sheets.NewService(context.Background(),
option.WithCredentialsFile(data.KeyFile),
option.WithScopes(sheets.SpreadsheetsReadonlyScope)) option.WithScopes(sheets.SpreadsheetsReadonlyScope))
if err != nil { if err != nil {
log.Fatalf("[ERROR] create sheets client: %v", err) log.Fatalf("[ERROR] create sheets client: %v", err)
-2
View File
@@ -10,7 +10,6 @@ import (
"os" "os"
"strings" "strings"
"heliosian/internal/data"
"google.golang.org/api/option" "google.golang.org/api/option"
"google.golang.org/api/sheets/v4" "google.golang.org/api/sheets/v4"
) )
@@ -39,7 +38,6 @@ func main() {
log.Fatalf("[ERROR] %s has no data rows", *in) log.Fatalf("[ERROR] %s has no data rows", *in)
} }
svc, err := sheets.NewService(context.Background(), svc, err := sheets.NewService(context.Background(),
option.WithCredentialsFile(data.KeyFile),
option.WithScopes(sheets.SpreadsheetsScope)) option.WithScopes(sheets.SpreadsheetsScope))
if err != nil { if err != nil {
log.Fatalf("[ERROR] create sheets client: %v", err) log.Fatalf("[ERROR] create sheets client: %v", err)