mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-15 15:53:26 +00:00
Support GCD impersonation via modified service account file
This commit is contained in:
@@ -41,6 +41,7 @@ type GCDStorage struct {
|
|||||||
backoffs []int // desired backoff time in seconds for each thread
|
backoffs []int // desired backoff time in seconds for each thread
|
||||||
attempts []int // number of failed attempts since last success for each thread
|
attempts []int // number of failed attempts since last success for each thread
|
||||||
driveID string // the ID of the shared drive or 'root' (GCDUserDrive) if the user's drive
|
driveID string // the ID of the shared drive or 'root' (GCDUserDrive) if the user's drive
|
||||||
|
spaces string // 'appDataFolder' if scope is drive.appdata; 'drive' otherwise
|
||||||
|
|
||||||
createDirectoryLock sync.Mutex
|
createDirectoryLock sync.Mutex
|
||||||
isConnected bool
|
isConnected bool
|
||||||
@@ -199,7 +200,7 @@ func (storage *GCDStorage) listFiles(threadIndex int, parentID string, listFiles
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
for {
|
for {
|
||||||
q := storage.service.Files.List().Q(query).Fields("nextPageToken", "files(name, mimeType, id, size)").PageToken(startToken).PageSize(maxCount)
|
q := storage.service.Files.List().Q(query).Fields("nextPageToken", "files(name, mimeType, id, size)").PageToken(startToken).PageSize(maxCount).Spaces(storage.spaces)
|
||||||
if storage.driveID != GCDUserDrive {
|
if storage.driveID != GCDUserDrive {
|
||||||
q = q.DriveId(storage.driveID).IncludeItemsFromAllDrives(true).Corpora("drive").SupportsAllDrives(true)
|
q = q.DriveId(storage.driveID).IncludeItemsFromAllDrives(true).Corpora("drive").SupportsAllDrives(true)
|
||||||
}
|
}
|
||||||
@@ -231,7 +232,7 @@ func (storage *GCDStorage) listByName(threadIndex int, parentID string, name str
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
query := "name = '" + name + "' and '" + parentID + "' in parents and trashed = false "
|
query := "name = '" + name + "' and '" + parentID + "' in parents and trashed = false "
|
||||||
q := storage.service.Files.List().Q(query).Fields("files(name, mimeType, id, size)")
|
q := storage.service.Files.List().Q(query).Fields("files(name, mimeType, id, size)").Spaces(storage.spaces)
|
||||||
if storage.driveID != GCDUserDrive {
|
if storage.driveID != GCDUserDrive {
|
||||||
q = q.DriveId(storage.driveID).IncludeItemsFromAllDrives(true).Corpora("drive").SupportsAllDrives(true)
|
q = q.DriveId(storage.driveID).IncludeItemsFromAllDrives(true).Corpora("drive").SupportsAllDrives(true)
|
||||||
}
|
}
|
||||||
@@ -344,11 +345,23 @@ func CreateGCDStorage(tokenFile string, driveID string, storagePath string, thre
|
|||||||
|
|
||||||
var tokenSource oauth2.TokenSource
|
var tokenSource oauth2.TokenSource
|
||||||
|
|
||||||
|
scope := drive.DriveScope
|
||||||
|
|
||||||
if isServiceAccount {
|
if isServiceAccount {
|
||||||
config, err := google.JWTConfigFromJSON(description, drive.DriveScope)
|
|
||||||
|
if newScope, ok := object["scope"]; ok {
|
||||||
|
scope = newScope.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
config, err := google.JWTConfigFromJSON(description, scope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if subject, ok := object["subject"]; ok {
|
||||||
|
config.Subject = subject.(string)
|
||||||
|
}
|
||||||
|
|
||||||
tokenSource = config.TokenSource(ctx)
|
tokenSource = config.TokenSource(ctx)
|
||||||
} else {
|
} else {
|
||||||
gcdConfig := &GCDConfig{}
|
gcdConfig := &GCDConfig{}
|
||||||
@@ -398,6 +411,7 @@ func CreateGCDStorage(tokenFile string, driveID string, storagePath string, thre
|
|||||||
backoffs: make([]int, threads),
|
backoffs: make([]int, threads),
|
||||||
attempts: make([]int, threads),
|
attempts: make([]int, threads),
|
||||||
driveID: driveID,
|
driveID: driveID,
|
||||||
|
spaces: "drive",
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range storage.backoffs {
|
for i := range storage.backoffs {
|
||||||
@@ -405,7 +419,14 @@ func CreateGCDStorage(tokenFile string, driveID string, storagePath string, thre
|
|||||||
storage.attempts[i] = 0
|
storage.attempts[i] = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
storage.savePathID("", driveID)
|
|
||||||
|
if scope == drive.DriveAppdataScope {
|
||||||
|
storage.spaces = "appDataFolder"
|
||||||
|
storage.savePathID("", "appDataFolder")
|
||||||
|
} else {
|
||||||
|
storage.savePathID("", driveID)
|
||||||
|
}
|
||||||
|
|
||||||
storagePathID, err := storage.getIDFromPath(0, storagePath, true)
|
storagePathID, err := storage.getIDFromPath(0, storagePath, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -142,6 +142,10 @@ func loadStorage(localStoragePath string, threads int) (Storage, error) {
|
|||||||
storage, err := CreateGCDStorage(config["token_file"], config["drive"], config["storage_path"], threads)
|
storage, err := CreateGCDStorage(config["token_file"], config["drive"], config["storage_path"], threads)
|
||||||
storage.SetDefaultNestingLevels([]int{2, 3}, 2)
|
storage.SetDefaultNestingLevels([]int{2, 3}, 2)
|
||||||
return storage, err
|
return storage, err
|
||||||
|
} else if testStorageName == "gcd-impersonate" {
|
||||||
|
storage, err := CreateGCDStorage(config["token_file"], config["drive"], config["storage_path"], threads)
|
||||||
|
storage.SetDefaultNestingLevels([]int{2, 3}, 2)
|
||||||
|
return storage, err
|
||||||
} else if testStorageName == "one" {
|
} else if testStorageName == "one" {
|
||||||
storage, err := CreateOneDriveStorage(config["token_file"], false, config["storage_path"], threads)
|
storage, err := CreateOneDriveStorage(config["token_file"], false, config["storage_path"], threads)
|
||||||
storage.SetDefaultNestingLevels([]int{2, 3}, 2)
|
storage.SetDefaultNestingLevels([]int{2, 3}, 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user