1
mirror of https://github.com/rclone/rclone synced 2024-12-19 09:05:56 +01:00

s3: implement backend set command to update running config

This commit is contained in:
Nick Craig-Wood 2023-07-15 18:56:58 +01:00
parent 5026a9171d
commit 2bcbed30bd

View File

@ -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
}