protondrive: implement two-password mode (#7279)

This commit is contained in:
Chun-Hung Tseng 2023-09-09 04:54:46 +08:00 committed by GitHub
parent 071c3f28e5
commit ed755bf04f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 6 deletions

View File

@ -61,13 +61,23 @@ func init() {
NewFs: NewFs,
Options: []fs.Option{{
Name: "username",
Help: `The username of your proton drive account`,
Help: `The username of your proton account`,
Required: true,
}, {
Name: "password",
Help: "The password of your proton drive account.",
Help: "The password of your proton account.",
Required: true,
IsPassword: true,
}, {
Name: "mailboxPassword",
Help: `The mailbox password of your two-password proton account.
For more information regarding the mailbox password, please check the
following official knowledge base article:
https://proton.me/support/the-difference-between-the-mailbox-password-and-login-password
`,
IsPassword: true,
Advanced: true,
}, {
Name: "2fa",
Help: `The 2FA code
@ -149,9 +159,10 @@ then we might have a problem with caching the stale data.`,
// Options defines the configuration for this backend
type Options struct {
Username string `config:"username"`
Password string `config:"password"`
TwoFA string `config:"2fa"`
Username string `config:"username"`
Password string `config:"password"`
MailboxPassword string `config:"mailboxPassword"`
TwoFA string `config:"2fa"`
// advanced
Enc encoder.MultiEncoder `config:"encoding"`
@ -313,6 +324,7 @@ func newProtonDrive(ctx context.Context, f *Fs, opt *Options, m configmap.Mapper
config.UseReusableLogin = false
config.FirstLoginCredential.Username = opt.Username
config.FirstLoginCredential.Password = opt.Password
config.FirstLoginCredential.MailboxPassword = opt.MailboxPassword
config.FirstLoginCredential.TwoFA = opt.TwoFA
protonDrive, auth, err := protonDriveAPI.NewProtonDrive(ctx, config, authHandler, deAuthHandler)
if err != nil {
@ -344,6 +356,14 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
}
}
if opt.MailboxPassword != "" {
var err error
opt.MailboxPassword, err = obscure.Reveal(opt.MailboxPassword)
if err != nil {
return nil, fmt.Errorf("couldn't decrypt mailbox password: %w", err)
}
}
ci := fs.GetConfig(ctx)
root = strings.Trim(root, "/")

View File

@ -90,7 +90,7 @@ To copy a local directory to an Proton Drive directory called backup
### Modified time
Proton Drive Bridge does not support modification times yet.
Proton Drive Bridge does not support updating modification times yet.
### Restricted filename characters
@ -103,6 +103,10 @@ Proton Drive can not have two files with exactly the same name and path. If the
conflict occurs, depending on the advanced config, the file might or might not
be overwritten.
### [Mailbox password](https://proton.me/support/the-difference-between-the-mailbox-password-and-login-password)
Please set your mailbox password in the advanced config section.
### Caching
The cache is currently built for the case when the rclone is the only instance