From 4cf82118d914a9be5ad12f349f59b63a4ea2680d Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 21 May 2020 17:34:13 +0530 Subject: [PATCH] rc: add plugins support --- fs/rc/plugins.go | 127 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 fs/rc/plugins.go diff --git a/fs/rc/plugins.go b/fs/rc/plugins.go new file mode 100644 index 000000000..e49f43e11 --- /dev/null +++ b/fs/rc/plugins.go @@ -0,0 +1,127 @@ +package rc + +import ( + "context" + "errors" + "fmt" +) + +type PackageJSON struct { + Name string `json:"name"` + Version string `json:"version"` + Description string `json:"description"` + Author string `json:"author"` + Copyright string `json:"copyright"` + License string `json:"license"` + Private bool `json:"private"` + Homepage string `json:"homepage"` + Repository struct { + Type string `json:"type"` + URL string `json:"url"` + } `json:"repository"` + Bugs struct { + URL string `json:"url"` + } `json:"bugs"` +} + +var loadedTestPlugins map[string]string + +func init() { + loadedTestPlugins = make(map[string]string) +} + +func init() { + Add(Call{ + Path: "pluginsctl/addTestPlugin", + AuthRequired: true, + Fn: rcAddPlugin, + Title: "Show current mount points", + Help: `This shows currently mounted points, which can be used for performing an unmount + +This takes no parameters and returns + +- mountPoints: list of current mount points + +Eg + + rclone rc mount/listmounts +`, + }) +} + +func rcAddPlugin(_ context.Context, in Params) (out Params, err error) { + test, err := in.GetBool("test") + if err != nil { + return nil, err + } + name, err := in.GetString("name") + if err != nil { + return nil, err + } + + url, err := in.GetString("loadUrl") + if err != nil { + return nil, err + } + if test { + loadedTestPlugins[name] = url + } + return nil, nil +} + +func init() { + Add(Call{ + Path: "pluginsctl/listTestPlugins", + AuthRequired: true, + Fn: rcGetLoadedPlugins, + Title: "Show current mount points", + Help: `This shows currently mounted points, which can be used for performing an unmount + +This takes no parameters and returns + +- mountPoints: list of current mount points + +Eg + + rclone rc mount/listmounts +`, + }) +} + +func rcGetLoadedPlugins(_ context.Context, in Params) (out Params, err error) { + return Params{ + "loadedTestPlugins": loadedTestPlugins, + }, nil +} + +func init() { + Add(Call{ + Path: "pluginsctl/removeTestPlugin", + AuthRequired: true, + Fn: rcRemovePlugin, + Title: "Show current mount points", + Help: `This shows currently mounted points, which can be used for performing an unmount + +This takes no parameters and returns + +- mountPoints: list of current mount points + +Eg + + rclone rc mount/listmounts +`, + }) +} + +func rcRemovePlugin(_ context.Context, in Params) (out Params, err error) { + name, err := in.GetString("name") + if err != nil { + return nil, err + } + _, ok := loadedTestPlugins[name] + if ok { + delete(loadedTestPlugins, name) + return nil, nil + } + return nil, errors.New(fmt.Sprintf("plugin %s not loaded", name)) +}