From 30d8ab5f2fffa273f98ef05d97c44916bfeb35aa Mon Sep 17 00:00:00 2001 From: n4n5 <56606507+Its-Just-Nans@users.noreply.github.com> Date: Fri, 25 Jul 2025 12:19:07 +0200 Subject: [PATCH] rc: add config/unlock to unlock the config file --- fs/config/rc.go | 31 +++++++++++++++++++++++++++++++ fs/config/rc_test.go | 14 ++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/fs/config/rc.go b/fs/config/rc.go index c0c0a8dc7..07f309e76 100644 --- a/fs/config/rc.go +++ b/fs/config/rc.go @@ -9,6 +9,37 @@ import ( "github.com/rclone/rclone/fs/rc" ) +func init() { + rc.Add(rc.Call{ + Path: "config/unlock", + Fn: rcConfigPassword, + Title: "Unlock the config file.", + AuthRequired: true, + Help: ` +Unlocks the config file if it is locked. + +Parameters: + +- 'config_password' - password to unlock the config file + +A good idea is to disable AskPassword before making this call +`, + }) +} + +// Unlock the config file +// A good idea is to disable AskPassword before making this call +func rcConfigPassword(ctx context.Context, in rc.Params) (out rc.Params, err error) { + configPass, err := in.GetString("config_password") + if err != nil { + return nil, err + } + if SetConfigPassword(configPass) != nil { + return nil, errors.New("failed to set config password") + } + return nil, nil +} + func init() { rc.Add(rc.Call{ Path: "config/dump", diff --git a/fs/config/rc_test.go b/fs/config/rc_test.go index aeed3f513..68c127a03 100644 --- a/fs/config/rc_test.go +++ b/fs/config/rc_test.go @@ -188,3 +188,17 @@ func TestRcPaths(t *testing.T) { assert.Equal(t, config.GetCacheDir(), out["cache"]) assert.Equal(t, os.TempDir(), out["temp"]) } + +func TestRcConfigUnlock(t *testing.T) { + call := rc.Calls.Get("config/unlock") + assert.NotNil(t, call) + in := rc.Params{ + "config_password": "test", + } + out, err := call.Fn(context.Background(), in) + require.NoError(t, err) + + assert.Nil(t, err) + assert.Nil(t, out) + +}