Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

oauthutil: adds SharedOptions for OAuth backends

Tim Gallant30eb094f286c
diff --git a/backend/amazonclouddrive/amazonclouddrive.go b/backend/amazonclouddrive/amazonclouddrive.go
index 273f89535..ddaf55730 100644
--- a/backend/amazonclouddrive/amazonclouddrive.go
+++ b/backend/amazonclouddrive/amazonclouddrive.go
@@ -76,23 +76,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err)
}
},
- Options: []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,
- }, {
+ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: "checkpoint",
Help: "Checkpoint for internal polling (debug).",
Hide: fs.OptionHideBoth,
@@ -143,7 +127,7 @@ underlying S3 storage.`,
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
Default: (encoder.Base |
encoder.EncodeInvalidUtf8),
- }},
+ }}...),
})
}
diff --git a/backend/box/box.go b/backend/box/box.go
index 9903b4c30..7a9f34804 100644
--- a/backend/box/box.go
+++ b/backend/box/box.go
@@ -103,13 +103,7 @@ func init() {
}
}
},
- Options: []fs.Option{{
- Name: config.ConfigClientID,
- Help: "Box App Client Id.\nLeave blank normally.",
- }, {
- Name: config.ConfigClientSecret,
- Help: "Box App Client Secret\nLeave blank normally.",
- }, {
+ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: "root_folder_id",
Help: "Fill in for rclone to use a non root folder as its starting point.",
Default: "0",
@@ -155,7 +149,7 @@ func init() {
encoder.EncodeBackSlash |
encoder.EncodeRightSpace |
encoder.EncodeInvalidUtf8),
- }},
+ }}...),
})
}
diff --git a/backend/drive/drive.go b/backend/drive/drive.go
index 357506dd2..02efb3f50 100755
--- a/backend/drive/drive.go
+++ b/backend/drive/drive.go
@@ -193,13 +193,7 @@ func init() {
log.Fatalf("Failed to configure team drive: %v", err)
}
},
- Options: []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.",
- }, {
+ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: "scope",
Help: "Scope that rclone should use when requesting access from drive.",
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.
// Don't encode / as it's a valid name character in drive.
Default: encoder.EncodeInvalidUtf8,
- }},
+ }}...),
})
// register duplicate MIME types first
diff --git a/backend/dropbox/dropbox.go b/backend/dropbox/dropbox.go
index ad740bf2f..d9b0cd845 100755
--- a/backend/dropbox/dropbox.go
+++ b/backend/dropbox/dropbox.go
@@ -125,13 +125,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err)
}
},
- Options: []fs.Option{{
- Name: config.ConfigClientID,
- Help: "Dropbox App Client Id\nLeave blank normally.",
- }, {
- Name: config.ConfigClientSecret,
- Help: "Dropbox App Client Secret\nLeave blank normally.",
- }, {
+ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: "chunk_size",
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.EncodeRightSpace |
encoder.EncodeInvalidUtf8),
- }},
+ }}...),
})
}
diff --git a/backend/googlecloudstorage/googlecloudstorage.go b/backend/googlecloudstorage/googlecloudstorage.go
index 4b0481f5e..52eee6484 100644
--- a/backend/googlecloudstorage/googlecloudstorage.go
+++ b/backend/googlecloudstorage/googlecloudstorage.go
@@ -88,13 +88,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err)
}
},
- Options: []fs.Option{{
- Name: config.ConfigClientID,
- Help: "Google Application Client Id\nLeave blank normally.",
- }, {
- Name: config.ConfigClientSecret,
- Help: "Google Application Client Secret\nLeave blank normally.",
- }, {
+ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: "project_number",
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 |
encoder.EncodeCrLf |
encoder.EncodeInvalidUtf8),
- }},
+ }}...),
})
}
diff --git a/backend/googlephotos/googlephotos.go b/backend/googlephotos/googlephotos.go
index 2cbb1627d..a7674a2b5 100644
--- a/backend/googlephotos/googlephotos.go
+++ b/backend/googlephotos/googlephotos.go
@@ -21,7 +21,6 @@ import (
"github.com/pkg/errors"
"github.com/rclone/rclone/backend/googlephotos/api"
"github.com/rclone/rclone/fs"
- "github.com/rclone/rclone/fs/config"
"github.com/rclone/rclone/fs/config/configmap"
"github.com/rclone/rclone/fs/config/configstruct"
"github.com/rclone/rclone/fs/config/obscure"
@@ -110,13 +109,7 @@ func init() {
`)
},
- Options: []fs.Option{{
- Name: config.ConfigClientID,
- Help: "Google Application Client Id\nLeave blank normally.",
- }, {
- Name: config.ConfigClientSecret,
- Help: "Google Application Client Secret\nLeave blank normally.",
- }, {
+ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: "read_only",
Default: false,
Help: `Set to make the Google Photos backend read only.
@@ -139,7 +132,7 @@ you want to read the media.`,
Default: 2000,
Help: `Year limits the photos to be downloaded to those which are uploaded after the given year`,
Advanced: true,
- }},
+ }}...),
})
}
diff --git a/backend/hubic/hubic.go b/backend/hubic/hubic.go
index a558858de..daab254fa 100644
--- a/backend/hubic/hubic.go
+++ b/backend/hubic/hubic.go
@@ -20,7 +20,6 @@ import (
"github.com/pkg/errors"
"github.com/rclone/rclone/backend/swift"
"github.com/rclone/rclone/fs"
- "github.com/rclone/rclone/fs/config"
"github.com/rclone/rclone/fs/config/configmap"
"github.com/rclone/rclone/fs/config/configstruct"
"github.com/rclone/rclone/fs/config/obscure"
@@ -63,13 +62,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err)
}
},
- Options: append([]fs.Option{{
- Name: config.ConfigClientID,
- Help: "Hubic Client Id\nLeave blank normally.",
- }, {
- Name: config.ConfigClientSecret,
- Help: "Hubic Client Secret\nLeave blank normally.",
- }}, swift.SharedOptions...),
+ Options: append(oauthutil.SharedOptions, swift.SharedOptions...),
})
}
diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go
index d9543a4d2..752fb5e99 100755
--- a/backend/onedrive/onedrive.go
+++ b/backend/onedrive/onedrive.go
@@ -241,13 +241,7 @@ func init() {
m.Set(configDriveType, rootItem.ParentReference.DriveType)
config.SaveConfig()
},
- Options: []fs.Option{{
- Name: config.ConfigClientID,
- Help: "Microsoft App Client Id\nLeave blank normally.",
- }, {
- Name: config.ConfigClientSecret,
- Help: "Microsoft App Client Secret\nLeave blank normally.",
- }, {
+ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: "chunk_size",
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.EncodeWin |
encoder.EncodeInvalidUtf8),
- }},
+ }}...),
})
}
diff --git a/backend/pcloud/pcloud.go b/backend/pcloud/pcloud.go
index b020c1144..42a4e5b3e 100644
--- a/backend/pcloud/pcloud.go
+++ b/backend/pcloud/pcloud.go
@@ -103,13 +103,7 @@ func init() {
log.Fatalf("Failed to configure token: %v", err)
}
},
- Options: []fs.Option{{
- Name: config.ConfigClientID,
- Help: "Pcloud App Client Id\nLeave blank normally.",
- }, {
- Name: config.ConfigClientSecret,
- Help: "Pcloud App Client Secret\nLeave blank normally.",
- }, {
+ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigEncoding,
Help: config.ConfigEncodingHelp,
Advanced: true,
@@ -131,7 +125,7 @@ func init() {
This is normally set when rclone initially does the oauth connection.`,
Default: defaultHostname,
Advanced: true,
- }},
+ }}...),
})
}
diff --git a/backend/yandex/yandex.go b/backend/yandex/yandex.go
index 04d97f975..ab029232c 100644
--- a/backend/yandex/yandex.go
+++ b/backend/yandex/yandex.go
@@ -67,13 +67,7 @@ func init() {
return
}
},
- Options: []fs.Option{{
- Name: config.ConfigClientID,
- Help: "Yandex Client Id\nLeave blank normally.",
- }, {
- Name: config.ConfigClientSecret,
- Help: "Yandex Client Secret\nLeave blank normally.",
- }, {
+ Options: append(oauthutil.SharedOptions, []fs.Option{{
Name: config.ConfigEncoding,
Help: config.ConfigEncodingHelp,
Advanced: true,
@@ -81,7 +75,7 @@ func init() {
// it doesn't seem worth making an exception for this
Default: (encoder.Display |
encoder.EncodeInvalidUtf8),
- }},
+ }}...),
})
}
diff --git a/lib/oauthutil/oauthutil.go b/lib/oauthutil/oauthutil.go
index 2ea4f8a32..2b87b1b7d 100644
--- a/lib/oauthutil/oauthutil.go
+++ b/lib/oauthutil/oauthutil.go
@@ -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.
// This is the data you must store to persist authentication.
//