Skip to content

Commit 564392d

Browse files
committed
Drive ID needs to be set for shared drives
1 parent 43c97c1 commit 564392d

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

cmd/backup/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type Config struct {
9898
GoogleDriveImpersonateSubject string `split_words:"true"`
9999
GoogleDriveEndpoint string `split_words:"true"`
100100
GoogleDriveTokenURL string `split_words:"true"`
101+
GoogleDriveTeamDriveID string `split_words:"true"`
101102
Timezone string `envconfig:"TZ"`
102103
source string
103104
additionalEnvVars map[string]string

cmd/backup/script.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func (s *script) init() error {
259259
ImpersonateSubject: s.c.GoogleDriveImpersonateSubject,
260260
Endpoint: s.c.GoogleDriveEndpoint,
261261
TokenURL: s.c.GoogleDriveTokenURL,
262+
TeamDriveID: s.c.GoogleDriveTeamDriveID,
262263
}
263264
googleDriveBackend, err := googledrive.NewStorageBackend(googleDriveConfig, logFunc)
264265
if err != nil {

internal/storage/googledrive/googledrive.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import (
2424

2525
type googleDriveStorage struct {
2626
storage.StorageBackend
27-
client *drive.Service
27+
client *drive.Service
28+
teamDriveID string
2829
}
2930

3031
// Config allows to configure a Google Drive storage backend.
@@ -34,6 +35,7 @@ type Config struct {
3435
ImpersonateSubject string
3536
Endpoint string
3637
TokenURL string
38+
TeamDriveID string
3739
}
3840

3941
// NewStorageBackend creates and initializes a new Google Drive storage backend.
@@ -77,7 +79,8 @@ func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error
7779
DestinationPath: opts.FolderID,
7880
Log: logFunc,
7981
},
80-
client: srv,
82+
client: srv,
83+
teamDriveID: opts.TeamDriveID,
8184
}, nil
8285
}
8386

@@ -134,6 +137,9 @@ func (b *googleDriveStorage) Prune(deadline time.Time, pruningPrefix string) (*s
134137
pageToken := ""
135138
for {
136139
req := b.client.Files.List().Q(query).SupportsAllDrives(true).Fields("files(id, name, createdTime, parents)").PageToken(pageToken)
140+
if b.teamDriveID != "" {
141+
req = req.DriveId(b.teamDriveID).IncludeItemsFromAllDrives(true)
142+
}
137143
res, err := req.Do()
138144
if err != nil {
139145
return nil, errwrap.Wrap(err, "listing files")

0 commit comments

Comments
 (0)