From 2bcbed30bd07d3d4f5d5b18a0b807e635e786632 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 15 Jul 2023 18:56:58 +0100 Subject: [PATCH] s3: implement backend set command to update running config --- backend/s3/s3.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/backend/s3/s3.go b/backend/s3/s3.go index 02fe34d5f..e9fbead06 100644 --- a/backend/s3/s3.go +++ b/backend/s3/s3.go @@ -4504,6 +4504,26 @@ supplied. It may return "Enabled", "Suspended" or "Unversioned". Note that once versioning has been enabled the status can't be set back to "Unversioned". `, +}, { + Name: "set", + Short: "Set command for updating the config parameters.", + Long: `This set command can be used to update the config parameters +for a running s3 backend. + +Usage Examples: + + rclone backend set s3: [-o opt_name=opt_value] [-o opt_name2=opt_value2] + rclone rc backend/command command=set fs=s3: [-o opt_name=opt_value] [-o opt_name2=opt_value2] + rclone rc backend/command command=set fs=s3: -o session_token=X -o access_key_id=X -o secret_access_key=X + +The option keys are named as they are in the config file. + +This rebuilds the connection to the s3 backend when it is called with +the new parameters. Only new parameters need be passed as the values +will default to those currently in use. + +It doesn't return anything. +`, }} // Command the backend to run a named command @@ -4598,6 +4618,25 @@ func (f *Fs) Command(ctx context.Context, name string, arg []string, opt map[str return nil, f.CleanUpHidden(ctx) case "versioning": return f.setGetVersioning(ctx, arg...) + case "set": + newOpt := f.opt + err := configstruct.Set(configmap.Simple(opt), &newOpt) + if err != nil { + return nil, fmt.Errorf("reading config: %w", err) + } + c, ses, err := s3Connection(f.ctx, &newOpt, f.srv) + if err != nil { + return nil, fmt.Errorf("updating session: %w", err) + } + f.c = c + f.ses = ses + f.opt = newOpt + keys := []string{} + for k := range opt { + keys = append(keys, k) + } + fs.Logf(f, "Updated config values: %s", strings.Join(keys, ", ")) + return nil, nil default: return nil, fs.ErrorCommandNotFound }