2018-11-04 19:23:12 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fs/rc"
|
2018-11-04 19:23:12 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rc.Add(rc.Call{
|
|
|
|
Path: "config/dump",
|
|
|
|
Fn: rcDump,
|
|
|
|
Title: "Dumps the config file.",
|
|
|
|
AuthRequired: true,
|
|
|
|
Help: `
|
|
|
|
Returns a JSON object:
|
|
|
|
- key: value
|
|
|
|
|
|
|
|
Where keys are remote names and values are the config parameters.
|
|
|
|
|
|
|
|
See the [config dump command](/commands/rclone_config_dump/) command for more information on the above.
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the config file dump
|
2019-06-17 10:34:30 +02:00
|
|
|
func rcDump(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
2018-11-04 19:23:12 +01:00
|
|
|
return DumpRcBlob(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rc.Add(rc.Call{
|
|
|
|
Path: "config/get",
|
|
|
|
Fn: rcGet,
|
|
|
|
Title: "Get a remote in the config file.",
|
|
|
|
AuthRequired: true,
|
|
|
|
Help: `
|
|
|
|
Parameters:
|
2019-10-27 11:32:56 +01:00
|
|
|
|
2018-11-04 19:23:12 +01:00
|
|
|
- name - name of remote to get
|
|
|
|
|
|
|
|
See the [config dump command](/commands/rclone_config_dump/) command for more information on the above.
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the config file get
|
2019-06-17 10:34:30 +02:00
|
|
|
func rcGet(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
2018-11-04 19:23:12 +01:00
|
|
|
name, err := in.GetString("name")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return DumpRcRemote(name), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rc.Add(rc.Call{
|
|
|
|
Path: "config/listremotes",
|
|
|
|
Fn: rcListRemotes,
|
|
|
|
Title: "Lists the remotes in the config file.",
|
|
|
|
AuthRequired: true,
|
|
|
|
Help: `
|
|
|
|
Returns
|
|
|
|
- remotes - array of remote names
|
|
|
|
|
|
|
|
See the [listremotes command](/commands/rclone_listremotes/) command for more information on the above.
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the a list of remotes in the config file
|
2019-06-17 10:34:30 +02:00
|
|
|
func rcListRemotes(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
2018-11-04 19:23:12 +01:00
|
|
|
var remotes = []string{}
|
|
|
|
for _, remote := range getConfigData().GetSectionList() {
|
|
|
|
remotes = append(remotes, remote)
|
|
|
|
}
|
|
|
|
out = rc.Params{
|
|
|
|
"remotes": remotes,
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rc.Add(rc.Call{
|
|
|
|
Path: "config/providers",
|
|
|
|
Fn: rcProviders,
|
|
|
|
Title: "Shows how providers are configured in the config file.",
|
|
|
|
AuthRequired: true,
|
|
|
|
Help: `
|
|
|
|
Returns a JSON object:
|
|
|
|
- providers - array of objects
|
|
|
|
|
|
|
|
See the [config providers command](/commands/rclone_config_providers/) command for more information on the above.
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the config file providers
|
2019-06-17 10:34:30 +02:00
|
|
|
func rcProviders(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
2018-11-04 19:23:12 +01:00
|
|
|
out = rc.Params{
|
|
|
|
"providers": fs.Registry,
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
for _, name := range []string{"create", "update", "password"} {
|
|
|
|
name := name
|
|
|
|
extraHelp := ""
|
|
|
|
if name == "create" {
|
|
|
|
extraHelp = "- type - type of the new remote\n"
|
|
|
|
}
|
2020-05-12 15:24:53 +02:00
|
|
|
if name == "create" || name == "update" {
|
|
|
|
extraHelp += "- obscure - optional bool - forces obscuring of passwords\n"
|
|
|
|
extraHelp += "- noObscure - optional bool - forces passwords not to be obscured\n"
|
|
|
|
}
|
2018-11-04 19:23:12 +01:00
|
|
|
rc.Add(rc.Call{
|
|
|
|
Path: "config/" + name,
|
|
|
|
AuthRequired: true,
|
2019-06-17 10:34:30 +02:00
|
|
|
Fn: func(ctx context.Context, in rc.Params) (rc.Params, error) {
|
|
|
|
return rcConfig(ctx, in, name)
|
2018-11-04 19:23:12 +01:00
|
|
|
},
|
|
|
|
Title: name + " the config for a remote.",
|
|
|
|
Help: `This takes the following parameters
|
|
|
|
|
|
|
|
- name - name of remote
|
2019-09-03 09:29:44 +02:00
|
|
|
- parameters - a map of \{ "key": "value" \} pairs
|
2018-11-04 19:23:12 +01:00
|
|
|
` + extraHelp + `
|
|
|
|
|
|
|
|
See the [config ` + name + ` command](/commands/rclone_config_` + name + `/) command for more information on the above.`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Manipulate the config file
|
2019-06-17 10:34:30 +02:00
|
|
|
func rcConfig(ctx context.Context, in rc.Params, what string) (out rc.Params, err error) {
|
2018-11-04 19:23:12 +01:00
|
|
|
name, err := in.GetString("name")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
parameters := rc.Params{}
|
|
|
|
err = in.GetStruct("parameters", ¶meters)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-12 15:24:53 +02:00
|
|
|
doObscure, _ := in.GetBool("obscure")
|
|
|
|
noObscure, _ := in.GetBool("noObscure")
|
2018-11-04 19:23:12 +01:00
|
|
|
switch what {
|
|
|
|
case "create":
|
|
|
|
remoteType, err := in.GetString("type")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-05 19:02:26 +01:00
|
|
|
return nil, CreateRemote(ctx, name, remoteType, parameters, doObscure, noObscure)
|
2018-11-04 19:23:12 +01:00
|
|
|
case "update":
|
2020-11-05 19:02:26 +01:00
|
|
|
return nil, UpdateRemote(ctx, name, parameters, doObscure, noObscure)
|
2018-11-04 19:23:12 +01:00
|
|
|
case "password":
|
2020-11-05 19:02:26 +01:00
|
|
|
return nil, PasswordRemote(ctx, name, parameters)
|
2018-11-04 19:23:12 +01:00
|
|
|
}
|
|
|
|
panic("unknown rcConfig type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rc.Add(rc.Call{
|
|
|
|
Path: "config/delete",
|
|
|
|
Fn: rcDelete,
|
|
|
|
Title: "Delete a remote in the config file.",
|
|
|
|
AuthRequired: true,
|
|
|
|
Help: `
|
|
|
|
Parameters:
|
2019-09-03 09:29:44 +02:00
|
|
|
|
2018-11-04 19:23:12 +01:00
|
|
|
- name - name of remote to delete
|
|
|
|
|
|
|
|
See the [config delete command](/commands/rclone_config_delete/) command for more information on the above.
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the config file delete
|
2019-06-17 10:34:30 +02:00
|
|
|
func rcDelete(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
2018-11-04 19:23:12 +01:00
|
|
|
name, err := in.GetString("name")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
DeleteRemote(name)
|
|
|
|
return nil, nil
|
|
|
|
}
|