Compare commits
1 commit
tcl/master
...
fix-3010-i
Author | SHA1 | Date | |
---|---|---|---|
|
5a8a6fbd3d |
2 changed files with 11 additions and 56 deletions
|
@ -128,29 +128,6 @@ var (
|
||||||
_linkTemplates map[string]*template.Template // available link types
|
_linkTemplates map[string]*template.Template // available link types
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse the scopes option returning a slice of scopes
|
|
||||||
func driveScopes(scopesString string) (scopes []string) {
|
|
||||||
if scopesString == "" {
|
|
||||||
scopesString = defaultScope
|
|
||||||
}
|
|
||||||
for _, scope := range strings.Split(scopesString, ",") {
|
|
||||||
scope = strings.TrimSpace(scope)
|
|
||||||
scopes = append(scopes, scopePrefix+scope)
|
|
||||||
}
|
|
||||||
return scopes
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if one of the scopes was "drive.appfolder"
|
|
||||||
func driveScopesContainsAppFolder(scopes []string) bool {
|
|
||||||
for _, scope := range scopes {
|
|
||||||
if scope == scopePrefix+"drive.appfolder" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(&fs.RegInfo{
|
fs.Register(&fs.RegInfo{
|
||||||
|
@ -165,14 +142,18 @@ func init() {
|
||||||
fs.Errorf(nil, "Couldn't parse config into struct: %v", err)
|
fs.Errorf(nil, "Couldn't parse config into struct: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in the scopes
|
// Fill in the scopes
|
||||||
driveConfig.Scopes = driveScopes(opt.Scope)
|
if opt.Scope == "" {
|
||||||
// Set the root_folder_id if using drive.appfolder
|
opt.Scope = defaultScope
|
||||||
if driveScopesContainsAppFolder(driveConfig.Scopes) {
|
}
|
||||||
m.Set("root_folder_id", "appDataFolder")
|
driveConfig.Scopes = nil
|
||||||
|
for _, scope := range strings.Split(opt.Scope, ",") {
|
||||||
|
driveConfig.Scopes = append(driveConfig.Scopes, scopePrefix+strings.TrimSpace(scope))
|
||||||
|
// Set the root_folder_id if using drive.appfolder
|
||||||
|
if scope == "drive.appfolder" {
|
||||||
|
m.Set("root_folder_id", "appDataFolder")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt.ServiceAccountFile == "" {
|
if opt.ServiceAccountFile == "" {
|
||||||
err = oauthutil.Config("drive", name, m, driveConfig)
|
err = oauthutil.Config("drive", name, m, driveConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -794,8 +775,7 @@ func newPacer(opt *Options) *fs.Pacer {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getServiceAccountClient(opt *Options, credentialsData []byte) (*http.Client, error) {
|
func getServiceAccountClient(opt *Options, credentialsData []byte) (*http.Client, error) {
|
||||||
scopes := driveScopes(opt.Scope)
|
conf, err := google.JWTConfigFromJSON(credentialsData, driveConfig.Scopes...)
|
||||||
conf, err := google.JWTConfigFromJSON(credentialsData, scopes...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error processing credentials")
|
return nil, errors.Wrap(err, "error processing credentials")
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,31 +22,6 @@ import (
|
||||||
"google.golang.org/api/drive/v3"
|
"google.golang.org/api/drive/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDriveScopes(t *testing.T) {
|
|
||||||
for _, test := range []struct {
|
|
||||||
in string
|
|
||||||
want []string
|
|
||||||
wantFlag bool
|
|
||||||
}{
|
|
||||||
{"", []string{
|
|
||||||
"https://www.googleapis.com/auth/drive",
|
|
||||||
}, false},
|
|
||||||
{" drive.file , drive.readonly", []string{
|
|
||||||
"https://www.googleapis.com/auth/drive.file",
|
|
||||||
"https://www.googleapis.com/auth/drive.readonly",
|
|
||||||
}, false},
|
|
||||||
{" drive.file , drive.appfolder", []string{
|
|
||||||
"https://www.googleapis.com/auth/drive.file",
|
|
||||||
"https://www.googleapis.com/auth/drive.appfolder",
|
|
||||||
}, true},
|
|
||||||
} {
|
|
||||||
got := driveScopes(test.in)
|
|
||||||
assert.Equal(t, test.want, got, test.in)
|
|
||||||
gotFlag := driveScopesContainsAppFolder(got)
|
|
||||||
assert.Equal(t, test.wantFlag, gotFlag, test.in)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var additionalMimeTypes = map[string]string{
|
var additionalMimeTypes = map[string]string{
|
||||||
"application/vnd.ms-excel.sheet.macroenabled.12": ".xlsm",
|
"application/vnd.ms-excel.sheet.macroenabled.12": ".xlsm",
|
||||||
|
|
Loading…
Add table
Reference in a new issue