"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
rc: implement options/blocks,get,set and register options
Nick Craig-Woodb972dcb0aebb
diff --git a/cmd/serve/ftp/ftpflags/ftpflags.go b/cmd/serve/ftp/ftpflags/ftpflags.goindex 3c606fcc2..5cb227600 100644--- a/cmd/serve/ftp/ftpflags/ftpflags.go+++ b/cmd/serve/ftp/ftpflags/ftpflags.go@@ -3,6 +3,7 @@ package ftpflagsimport ("github.com/ncw/rclone/cmd/serve/ftp/ftpopt""github.com/ncw/rclone/fs/config/flags"+ "github.com/ncw/rclone/fs/rc""github.com/spf13/pflag")@@ -13,6 +14,7 @@ var (// AddFlagsPrefix adds flags for the ftpoptfunc AddFlagsPrefix(flagSet *pflag.FlagSet, prefix string, Opt *ftpopt.Options) {+ rc.AddOption("ftp", &Opt)flags.StringVarP(flagSet, &Opt.ListenAddr, prefix+"addr", "", Opt.ListenAddr, "IPaddress:Port or :Port to bind server to.")flags.StringVarP(flagSet, &Opt.PassivePorts, prefix+"passive-port", "", Opt.PassivePorts, "Passive port range to use.")flags.StringVarP(flagSet, &Opt.BasicUser, prefix+"user", "", Opt.BasicUser, "User name for authentication.")diff --git a/cmd/serve/httplib/httpflags/httpflags.go b/cmd/serve/httplib/httpflags/httpflags.goindex 312f14afb..9e04312b5 100644--- a/cmd/serve/httplib/httpflags/httpflags.go+++ b/cmd/serve/httplib/httpflags/httpflags.go@@ -3,6 +3,7 @@ package httpflagsimport ("github.com/ncw/rclone/cmd/serve/httplib""github.com/ncw/rclone/fs/config/flags"+ "github.com/ncw/rclone/fs/rc""github.com/spf13/pflag")@@ -13,6 +14,7 @@ var (// AddFlagsPrefix adds flags for the httplibfunc AddFlagsPrefix(flagSet *pflag.FlagSet, prefix string, Opt *httplib.Options) {+ rc.AddOption(prefix+"http", &Opt)flags.StringVarP(flagSet, &Opt.ListenAddr, prefix+"addr", "", Opt.ListenAddr, "IPaddress:Port or :Port to bind server to.")flags.DurationVarP(flagSet, &Opt.ServerReadTimeout, prefix+"server-read-timeout", "", Opt.ServerReadTimeout, "Timeout for server reading data")flags.DurationVarP(flagSet, &Opt.ServerWriteTimeout, prefix+"server-write-timeout", "", Opt.ServerWriteTimeout, "Timeout for server writing data")diff --git a/fs/config/configflags/configflags.go b/fs/config/configflags/configflags.goindex 45a01d547..39ab61d1f 100644--- a/fs/config/configflags/configflags.go+++ b/fs/config/configflags/configflags.go@@ -12,6 +12,7 @@ import ("github.com/ncw/rclone/fs""github.com/ncw/rclone/fs/config""github.com/ncw/rclone/fs/config/flags"+ "github.com/ncw/rclone/fs/rc""github.com/spf13/pflag")@@ -31,6 +32,7 @@ var (// AddFlags adds the non filing system specific flags to the commandfunc AddFlags(flagSet *pflag.FlagSet) {+ rc.AddOption("main", fs.Config)// NB defaults which aren't the zero for the type should be set in fs/config.go NewConfigflags.CountVarP(flagSet, &verbose, "verbose", "v", "Print lots more stuff (repeat for more)")flags.BoolVarP(flagSet, &quiet, "quiet", "q", false, "Print as little stuff as possible")diff --git a/fs/filter/filterflags/filterflags.go b/fs/filter/filterflags/filterflags.goindex 871202bc7..572531034 100644--- a/fs/filter/filterflags/filterflags.go+++ b/fs/filter/filterflags/filterflags.go@@ -4,6 +4,7 @@ package filterflagsimport ("github.com/ncw/rclone/fs/config/flags""github.com/ncw/rclone/fs/filter"+ "github.com/ncw/rclone/fs/rc""github.com/spf13/pflag")@@ -14,6 +15,7 @@ var (// AddFlags adds the non filing system specific flags to the commandfunc AddFlags(flagSet *pflag.FlagSet) {+ rc.AddOption("filter", &Opt)flags.BoolVarP(flagSet, &Opt.DeleteExcluded, "delete-excluded", "", false, "Delete files on dest excluded from sync")flags.StringArrayVarP(flagSet, &Opt.FilterRule, "filter", "f", nil, "Add a file-filtering rule")flags.StringArrayVarP(flagSet, &Opt.FilterFrom, "filter-from", "", nil, "Read filtering patterns from a file")diff --git a/fs/rc/config.go b/fs/rc/config.gonew file mode 100644index 000000000..0288749a1--- /dev/null+++ b/fs/rc/config.go@@ -0,0 +1,95 @@+// Implement config options reading and writing+//+// This is done here rather than in fs/fs.go so we don't cause a circular dependency++package rc++import (+ "github.com/pkg/errors"+)++var optionBlock = map[string]interface{}{}++// AddOption adds an option set+func AddOption(name string, option interface{}) {+ optionBlock[name] = option+}++func init() {+ Add(Call{+ Path: "options/blocks",+ Fn: rcOptionsBlocks,+ Title: "List all the option blocks",+ Help: `Returns+- options - a list of the options block names`,+ })+}++// Show the list of all the option blocks+func rcOptionsBlocks(in Params) (out Params, err error) {+ options := []string{}+ for name := range optionBlock {+ options = append(options, name)+ }+ out = make(Params)+ out["options"] = options+ return out, nil+}++func init() {+ Add(Call{+ Path: "options/get",+ Fn: rcOptionsGet,+ Title: "Get all the options",+ Help: `Returns an object where keys are option block names and values are an+object with the current option values in.++This shows the internal names of the option within rclone which should+map to the external options very easily with a few exceptions.+`,+ })+}++// Show the list of all the option blocks+func rcOptionsGet(in Params) (out Params, err error) {+ out = make(Params)+ for name, options := range optionBlock {+ out[name] = options+ }+ return out, nil+}++func init() {+ Add(Call{+ Path: "options/set",+ Fn: rcOptionsSet,+ Title: "Set an option",+ Help: `Parameters++- option block name containing an object with+ - key: value++Repeated as often as required.++Only supply the options you wish to change. If an option is unknown+it will be silently ignored. Not all options will have an effect when+changed like this.+`,+ })+}++// Set an option in an option block+func rcOptionsSet(in Params) (out Params, err error) {+ for name, options := range in {+ current := optionBlock[name]+ if current == nil {+ return nil, errors.Errorf("unknown option block %q", name)+ }+ err := Reshape(current, options)+ if err != nil {+ return nil, errors.Wrapf(err, "failed to write options from block %q", name)+ }++ }+ return out, nil+}diff --git a/fs/rc/rcflags/rcflags.go b/fs/rc/rcflags/rcflags.goindex 5440245af..1740fd3eb 100644--- a/fs/rc/rcflags/rcflags.go+++ b/fs/rc/rcflags/rcflags.go@@ -15,6 +15,7 @@ var (// AddFlags adds the remote control flags to the flagSetfunc AddFlags(flagSet *pflag.FlagSet) {+ rc.AddOption("rc", &Opt)flags.BoolVarP(flagSet, &Opt.Enabled, "rc", "", false, "Enable the remote control server.")flags.StringVarP(flagSet, &Opt.Files, "rc-files", "", "", "Serve these files on the HTTP server.")httpflags.AddFlagsPrefix(flagSet, "rc-", &Opt.HTTPOptions)diff --git a/vfs/vfsflags/vfsflags.go b/vfs/vfsflags/vfsflags.goindex 47abf8eab..b90e6509f 100644--- a/vfs/vfsflags/vfsflags.go+++ b/vfs/vfsflags/vfsflags.go@@ -3,6 +3,7 @@ package vfsflagsimport ("github.com/ncw/rclone/fs/config/flags"+ "github.com/ncw/rclone/fs/rc""github.com/ncw/rclone/vfs""github.com/spf13/pflag")@@ -14,6 +15,7 @@ var (// AddFlags adds the non filing system specific flags to the commandfunc AddFlags(flagSet *pflag.FlagSet) {+ rc.AddOption("vfs", &Opt)flags.BoolVarP(flagSet, &Opt.NoModTime, "no-modtime", "", Opt.NoModTime, "Don't read/write the modification time (can speed things up).")flags.BoolVarP(flagSet, &Opt.NoChecksum, "no-checksum", "", Opt.NoChecksum, "Don't compare checksums on up/download.")flags.BoolVarP(flagSet, &Opt.NoSeek, "no-seek", "", Opt.NoSeek, "Don't allow seeking in files.")