1
mirror of https://github.com/rclone/rclone synced 2025-03-30 15:56:10 +02:00

oauthutil: adds SharedOptions for OAuth backends

1. adds SharedOptions data structure to oauthutil
2. adds config.ConfigToken option to oauthutil.SharedOptions
3. updates the backends that have oauth functionality

Fixes 
This commit is contained in:
Tim Gallant 2020-08-01 16:32:21 -07:00 committed by Nick Craig-Wood
parent b401a727f7
commit 30eb094f28
11 changed files with 40 additions and 91 deletions
backend
amazonclouddrive
box
drive
dropbox
googlecloudstorage
googlephotos
hubic
onedrive
pcloud
yandex
lib/oauthutil

@ -76,23 +76,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err) log.Fatalf("Failed to configure token: %v", err)
} }
}, },
Options: []fs.Option{{ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigClientID,
Help: "Amazon Application Client ID.",
Required: true,
}, {
Name: config.ConfigClientSecret,
Help: "Amazon Application Client Secret.",
Required: true,
}, {
Name: config.ConfigAuthURL,
Help: "Auth server URL.\nLeave blank to use Amazon's.",
Advanced: true,
}, {
Name: config.ConfigTokenURL,
Help: "Token server url.\nleave blank to use Amazon's.",
Advanced: true,
}, {
Name: "checkpoint", Name: "checkpoint",
Help: "Checkpoint for internal polling (debug).", Help: "Checkpoint for internal polling (debug).",
Hide: fs.OptionHideBoth, Hide: fs.OptionHideBoth,
@ -143,7 +127,7 @@ underlying S3 storage.`,
// Encode invalid UTF-8 bytes as json doesn't handle them properly. // Encode invalid UTF-8 bytes as json doesn't handle them properly.
Default: (encoder.Base | Default: (encoder.Base |
encoder.EncodeInvalidUtf8), encoder.EncodeInvalidUtf8),
}}, }}...),
}) })
} }

@ -103,13 +103,7 @@ func init() {
} }
} }
}, },
Options: []fs.Option{{ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigClientID,
Help: "Box App Client Id.\nLeave blank normally.",
}, {
Name: config.ConfigClientSecret,
Help: "Box App Client Secret\nLeave blank normally.",
}, {
Name: "root_folder_id", Name: "root_folder_id",
Help: "Fill in for rclone to use a non root folder as its starting point.", Help: "Fill in for rclone to use a non root folder as its starting point.",
Default: "0", Default: "0",
@ -155,7 +149,7 @@ func init() {
encoder.EncodeBackSlash | encoder.EncodeBackSlash |
encoder.EncodeRightSpace | encoder.EncodeRightSpace |
encoder.EncodeInvalidUtf8), encoder.EncodeInvalidUtf8),
}}, }}...),
}) })
} }

@ -193,13 +193,7 @@ func init() {
log.Fatalf("Failed to configure team drive: %v", err) log.Fatalf("Failed to configure team drive: %v", err)
} }
}, },
Options: []fs.Option{{ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigClientID,
Help: "Google Application Client Id\nSetting your own is recommended.\nSee https://rclone.org/drive/#making-your-own-client-id for how to create your own.\nIf you leave this blank, it will use an internal key which is low performance.",
}, {
Name: config.ConfigClientSecret,
Help: "Google Application Client Secret\nSetting your own is recommended.",
}, {
Name: "scope", Name: "scope",
Help: "Scope that rclone should use when requesting access from drive.", Help: "Scope that rclone should use when requesting access from drive.",
Examples: []fs.OptionExample{{ Examples: []fs.OptionExample{{
@ -489,7 +483,7 @@ If this flag is set then rclone will ignore shortcut files completely.
// Encode invalid UTF-8 bytes as json doesn't handle them properly. // Encode invalid UTF-8 bytes as json doesn't handle them properly.
// Don't encode / as it's a valid name character in drive. // Don't encode / as it's a valid name character in drive.
Default: encoder.EncodeInvalidUtf8, Default: encoder.EncodeInvalidUtf8,
}}, }}...),
}) })
// register duplicate MIME types first // register duplicate MIME types first

@ -125,13 +125,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err) log.Fatalf("Failed to configure token: %v", err)
} }
}, },
Options: []fs.Option{{ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigClientID,
Help: "Dropbox App Client Id\nLeave blank normally.",
}, {
Name: config.ConfigClientSecret,
Help: "Dropbox App Client Secret\nLeave blank normally.",
}, {
Name: "chunk_size", Name: "chunk_size",
Help: fmt.Sprintf(`Upload chunk size. (< %v). Help: fmt.Sprintf(`Upload chunk size. (< %v).
@ -161,7 +155,7 @@ memory. It can be set smaller if you are tight on memory.`, maxChunkSize),
encoder.EncodeDel | encoder.EncodeDel |
encoder.EncodeRightSpace | encoder.EncodeRightSpace |
encoder.EncodeInvalidUtf8), encoder.EncodeInvalidUtf8),
}}, }}...),
}) })
} }

@ -88,13 +88,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err) log.Fatalf("Failed to configure token: %v", err)
} }
}, },
Options: []fs.Option{{ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigClientID,
Help: "Google Application Client Id\nLeave blank normally.",
}, {
Name: config.ConfigClientSecret,
Help: "Google Application Client Secret\nLeave blank normally.",
}, {
Name: "project_number", Name: "project_number",
Help: "Project number.\nOptional - needed only for list/create/delete buckets - see your developer console.", Help: "Project number.\nOptional - needed only for list/create/delete buckets - see your developer console.",
}, { }, {
@ -261,7 +255,7 @@ Docs: https://cloud.google.com/storage/docs/bucket-policy-only
Default: (encoder.Base | Default: (encoder.Base |
encoder.EncodeCrLf | encoder.EncodeCrLf |
encoder.EncodeInvalidUtf8), encoder.EncodeInvalidUtf8),
}}, }}...),
}) })
} }

@ -21,7 +21,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rclone/rclone/backend/googlephotos/api" "github.com/rclone/rclone/backend/googlephotos/api"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config"
"github.com/rclone/rclone/fs/config/configmap" "github.com/rclone/rclone/fs/config/configmap"
"github.com/rclone/rclone/fs/config/configstruct" "github.com/rclone/rclone/fs/config/configstruct"
"github.com/rclone/rclone/fs/config/obscure" "github.com/rclone/rclone/fs/config/obscure"
@ -110,13 +109,7 @@ func init() {
`) `)
}, },
Options: []fs.Option{{ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigClientID,
Help: "Google Application Client Id\nLeave blank normally.",
}, {
Name: config.ConfigClientSecret,
Help: "Google Application Client Secret\nLeave blank normally.",
}, {
Name: "read_only", Name: "read_only",
Default: false, Default: false,
Help: `Set to make the Google Photos backend read only. Help: `Set to make the Google Photos backend read only.
@ -139,7 +132,7 @@ you want to read the media.`,
Default: 2000, Default: 2000,
Help: `Year limits the photos to be downloaded to those which are uploaded after the given year`, Help: `Year limits the photos to be downloaded to those which are uploaded after the given year`,
Advanced: true, Advanced: true,
}}, }}...),
}) })
} }

@ -20,7 +20,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rclone/rclone/backend/swift" "github.com/rclone/rclone/backend/swift"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config"
"github.com/rclone/rclone/fs/config/configmap" "github.com/rclone/rclone/fs/config/configmap"
"github.com/rclone/rclone/fs/config/configstruct" "github.com/rclone/rclone/fs/config/configstruct"
"github.com/rclone/rclone/fs/config/obscure" "github.com/rclone/rclone/fs/config/obscure"
@ -63,13 +62,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err) log.Fatalf("Failed to configure token: %v", err)
} }
}, },
Options: append([]fs.Option{{ Options: append(oauthutil.SharedOptions, swift.SharedOptions...),
Name: config.ConfigClientID,
Help: "Hubic Client Id\nLeave blank normally.",
}, {
Name: config.ConfigClientSecret,
Help: "Hubic Client Secret\nLeave blank normally.",
}}, swift.SharedOptions...),
}) })
} }

@ -241,13 +241,7 @@ func init() {
m.Set(configDriveType, rootItem.ParentReference.DriveType) m.Set(configDriveType, rootItem.ParentReference.DriveType)
config.SaveConfig() config.SaveConfig()
}, },
Options: []fs.Option{{ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigClientID,
Help: "Microsoft App Client Id\nLeave blank normally.",
}, {
Name: config.ConfigClientSecret,
Help: "Microsoft App Client Secret\nLeave blank normally.",
}, {
Name: "chunk_size", Name: "chunk_size",
Help: `Chunk size to upload files with - must be multiple of 320k (327,680 bytes). Help: `Chunk size to upload files with - must be multiple of 320k (327,680 bytes).
@ -350,7 +344,7 @@ this flag there.
encoder.EncodeRightSpace | encoder.EncodeRightSpace |
encoder.EncodeWin | encoder.EncodeWin |
encoder.EncodeInvalidUtf8), encoder.EncodeInvalidUtf8),
}}, }}...),
}) })
} }

@ -103,13 +103,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err) log.Fatalf("Failed to configure token: %v", err)
} }
}, },
Options: []fs.Option{{ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigClientID,
Help: "Pcloud App Client Id\nLeave blank normally.",
}, {
Name: config.ConfigClientSecret,
Help: "Pcloud App Client Secret\nLeave blank normally.",
}, {
Name: config.ConfigEncoding, Name: config.ConfigEncoding,
Help: config.ConfigEncodingHelp, Help: config.ConfigEncodingHelp,
Advanced: true, Advanced: true,
@ -131,7 +125,7 @@ func init() {
This is normally set when rclone initially does the oauth connection.`, This is normally set when rclone initially does the oauth connection.`,
Default: defaultHostname, Default: defaultHostname,
Advanced: true, Advanced: true,
}}, }}...),
}) })
} }

@ -67,13 +67,7 @@ func init() {
return return
} }
}, },
Options: []fs.Option{{ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigClientID,
Help: "Yandex Client Id\nLeave blank normally.",
}, {
Name: config.ConfigClientSecret,
Help: "Yandex Client Secret\nLeave blank normally.",
}, {
Name: config.ConfigEncoding, Name: config.ConfigEncoding,
Help: config.ConfigEncodingHelp, Help: config.ConfigEncodingHelp,
Advanced: true, Advanced: true,
@ -81,7 +75,7 @@ func init() {
// it doesn't seem worth making an exception for this // it doesn't seem worth making an exception for this
Default: (encoder.Display | Default: (encoder.Display |
encoder.EncodeInvalidUtf8), encoder.EncodeInvalidUtf8),
}}, }}...),
}) })
} }

@ -71,6 +71,27 @@ All done. Please go back to rclone.
` `
) )
// SharedOptions are shared between backends the utilize an OAuth flow
var SharedOptions = []fs.Option{{
Name: config.ConfigClientID,
Help: "OAuth Client Id\nLeave blank normally.",
}, {
Name: config.ConfigClientSecret,
Help: "OAuth Client Secret\nLeave blank normally.",
}, {
Name: config.ConfigToken,
Help: "OAuth Access Token as a JSON blob.",
Advanced: true,
}, {
Name: config.ConfigAuthURL,
Help: "Auth server URL.\nLeave blank to use the provider defaults.",
Advanced: true,
}, {
Name: config.ConfigTokenURL,
Help: "Token server url.\nLeave blank to use the provider defaults.",
Advanced: true,
}}
// oldToken contains an end-user's tokens. // oldToken contains an end-user's tokens.
// This is the data you must store to persist authentication. // This is the data you must store to persist authentication.
// //