Drive ID needs to be set for shared drives

This commit is contained in:
Frederik Ring
2026-05-14 10:41:12 +02:00
parent 43c97c1bac
commit 564392d184
3 changed files with 10 additions and 2 deletions
+1
View File
@@ -98,6 +98,7 @@ type Config struct {
GoogleDriveImpersonateSubject string `split_words:"true"`
GoogleDriveEndpoint string `split_words:"true"`
GoogleDriveTokenURL string `split_words:"true"`
GoogleDriveTeamDriveID string `split_words:"true"`
Timezone string `envconfig:"TZ"`
source string
additionalEnvVars map[string]string
+1
View File
@@ -259,6 +259,7 @@ func (s *script) init() error {
ImpersonateSubject: s.c.GoogleDriveImpersonateSubject,
Endpoint: s.c.GoogleDriveEndpoint,
TokenURL: s.c.GoogleDriveTokenURL,
TeamDriveID: s.c.GoogleDriveTeamDriveID,
}
googleDriveBackend, err := googledrive.NewStorageBackend(googleDriveConfig, logFunc)
if err != nil {
+8 -2
View File
@@ -24,7 +24,8 @@ import (
type googleDriveStorage struct {
storage.StorageBackend
client *drive.Service
client *drive.Service
teamDriveID string
}
// Config allows to configure a Google Drive storage backend.
@@ -34,6 +35,7 @@ type Config struct {
ImpersonateSubject string
Endpoint string
TokenURL string
TeamDriveID string
}
// NewStorageBackend creates and initializes a new Google Drive storage backend.
@@ -77,7 +79,8 @@ func NewStorageBackend(opts Config, logFunc storage.Log) (storage.Backend, error
DestinationPath: opts.FolderID,
Log: logFunc,
},
client: srv,
client: srv,
teamDriveID: opts.TeamDriveID,
}, nil
}
@@ -134,6 +137,9 @@ func (b *googleDriveStorage) Prune(deadline time.Time, pruningPrefix string) (*s
pageToken := ""
for {
req := b.client.Files.List().Q(query).SupportsAllDrives(true).Fields("files(id, name, createdTime, parents)").PageToken(pageToken)
if b.teamDriveID != "" {
req = req.DriveId(b.teamDriveID).IncludeItemsFromAllDrives(true)
}
res, err := req.Do()
if err != nil {
return nil, errwrap.Wrap(err, "listing files")