From 60d59e260007aa7d7c03d9e34043b79e51bfc9fa Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Fri, 15 Jul 2022 10:01:06 +0200 Subject: [PATCH] jottacloud: do not store username in config when using standard auth Previously, with standard auth, the username would be stored in config - but only after entering the non-standard device/mountpoint sequence during config (a feature introduced with #5926). Regardless of that, rclone always requests the username from the api at startup (NewFS). In #6270 (commit 9dbed02329456c71d2052a6365041deda94bc020) this was changed to always store username in config (consistency), and then also use it to avoid the repeated customer info request in NewFs (performance). But, as reported in #6309, it did not work with legacy auth, where user enters username manually, if user entered an email address instead of the internal username required for api requests. This change was therefore recently reverted. The current commit takes another step back to not store the username in config during the non-standard device/mountpoint config sequence (consistentcy). The username will now only be stored in config when using legacy auth, where it is an input parameter. --- backend/jottacloud/jottacloud.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/jottacloud/jottacloud.go b/backend/jottacloud/jottacloud.go index 735b5181f..3bdc98ec6 100644 --- a/backend/jottacloud/jottacloud.go +++ b/backend/jottacloud/jottacloud.go @@ -284,7 +284,6 @@ sync or the backup section, for example, you must choose yes.`) if err != nil { return nil, err } - m.Set(configUsername, cust.Username) acc, err := getDriveInfo(ctx, jfsSrv, cust.Username) if err != nil { @@ -317,10 +316,14 @@ a new by entering a unique name.`, defaultDevice) return nil, err } jfsSrv := rest.NewClient(oAuthClient).SetRoot(jfsURL) + apiSrv := rest.NewClient(oAuthClient).SetRoot(apiURL) - username, _ := m.Get(configUsername) + cust, err := getCustomerInfo(ctx, apiSrv) + if err != nil { + return nil, err + } - acc, err := getDriveInfo(ctx, jfsSrv, username) + acc, err := getDriveInfo(ctx, jfsSrv, cust.Username) if err != nil { return nil, err } @@ -335,7 +338,7 @@ a new by entering a unique name.`, defaultDevice) var dev *api.JottaDevice if isNew { fs.Debugf(nil, "Creating new device: %s", device) - dev, err = createDevice(ctx, jfsSrv, path.Join(username, device)) + dev, err = createDevice(ctx, jfsSrv, path.Join(cust.Username, device)) if err != nil { return nil, err } @@ -343,7 +346,7 @@ a new by entering a unique name.`, defaultDevice) m.Set(configDevice, device) if !isNew { - dev, err = getDeviceInfo(ctx, jfsSrv, path.Join(username, device)) + dev, err = getDeviceInfo(ctx, jfsSrv, path.Join(cust.Username, device)) if err != nil { return nil, err } @@ -373,11 +376,16 @@ You may create a new by entering a unique name.`, device) return nil, err } jfsSrv := rest.NewClient(oAuthClient).SetRoot(jfsURL) + apiSrv := rest.NewClient(oAuthClient).SetRoot(apiURL) + + cust, err := getCustomerInfo(ctx, apiSrv) + if err != nil { + return nil, err + } - username, _ := m.Get(configUsername) device, _ := m.Get(configDevice) - dev, err := getDeviceInfo(ctx, jfsSrv, path.Join(username, device)) + dev, err := getDeviceInfo(ctx, jfsSrv, path.Join(cust.Username, device)) if err != nil { return nil, err } @@ -395,7 +403,7 @@ You may create a new by entering a unique name.`, device) return nil, fmt.Errorf("custom mountpoints not supported on built-in %s device: %w", defaultDevice, err) } fs.Debugf(nil, "Creating new mountpoint: %s", mountpoint) - _, err := createMountPoint(ctx, jfsSrv, path.Join(username, device, mountpoint)) + _, err := createMountPoint(ctx, jfsSrv, path.Join(cust.Username, device, mountpoint)) if err != nil { return nil, err }