2018-11-04 19:23:12 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
2021-11-04 11:12:57 +01:00
|
|
|
"errors"
|
2024-01-17 11:36:17 +01:00
|
|
|
"os"
|
2019-06-17 10:34:30 +02:00
|
|
|
|
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.
|
|
|
|
|
2022-06-19 15:51:37 +02:00
|
|
|
See the [config dump](/commands/rclone_config_dump/) command for more information on the above.
|
2018-11-04 19:23:12 +01:00
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2022-06-19 15:51:37 +02:00
|
|
|
See the [config dump](/commands/rclone_config_dump/) command for more information on the above.
|
2018-11-04 19:23:12 +01:00
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2023-06-25 12:27:42 +02:00
|
|
|
Title: "Lists the remotes in the config file and defined in environment variables.",
|
2018-11-04 19:23:12 +01:00
|
|
|
AuthRequired: true,
|
|
|
|
Help: `
|
|
|
|
Returns
|
|
|
|
- remotes - array of remote names
|
|
|
|
|
2022-06-19 15:51:37 +02:00
|
|
|
See the [listremotes](/commands/rclone_listremotes/) command for more information on the above.
|
2018-11-04 19:23:12 +01:00
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the a list of remotes in the config file
|
2023-06-25 12:27:42 +02:00
|
|
|
// including any defined by environment variables.
|
2019-06-17 10:34:30 +02:00
|
|
|
func rcListRemotes(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
2023-11-04 02:48:42 +01:00
|
|
|
remoteNames := GetRemoteNames()
|
2018-11-04 19:23:12 +01:00
|
|
|
out = rc.Params{
|
2023-11-04 02:48:42 +01:00
|
|
|
"remotes": remoteNames,
|
2018-11-04 19:23:12 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
|
|
2024-07-10 19:24:13 +02:00
|
|
|
See the [config providers](/commands/rclone_config_providers/) command
|
|
|
|
for more information on the above.
|
|
|
|
|
|
|
|
Note that the Options blocks are in the same format as returned by
|
|
|
|
"options/info". They are described in the
|
|
|
|
[option blocks](#option-blocks) section.
|
2018-11-04 19:23:12 +01:00
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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" {
|
2021-05-05 12:45:30 +02:00
|
|
|
extraHelp += `- opt - a dictionary of options to control the configuration
|
|
|
|
- obscure - declare passwords are plain and need obscuring
|
|
|
|
- noObscure - declare passwords are already obscured and don't need obscuring
|
|
|
|
- nonInteractive - don't interact with a user, return questions
|
|
|
|
- continue - continue the config process with an answer
|
2021-05-09 17:03:18 +02:00
|
|
|
- all - ask all the config questions not just the post config ones
|
2021-05-11 14:36:34 +02:00
|
|
|
- state - state to restart with - used with continue
|
|
|
|
- result - result to restart with - used with continue
|
2021-05-05 12:45:30 +02:00
|
|
|
`
|
2020-05-12 15:24:53 +02:00
|
|
|
}
|
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.",
|
2021-08-16 11:30:01 +02:00
|
|
|
Help: `This takes the following parameters:
|
2018-11-04 19:23:12 +01:00
|
|
|
|
|
|
|
- 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 + `
|
|
|
|
|
2022-06-19 15:51:37 +02:00
|
|
|
See the [config ` + name + `](/commands/rclone_config_` + name + `/) command for more information on the above.`,
|
2018-11-04 19:23:12 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2021-05-05 12:45:30 +02:00
|
|
|
var opt UpdateRemoteOpt
|
|
|
|
err = in.GetStruct("opt", &opt)
|
|
|
|
if err != nil && !rc.IsErrParamNotFound(err) {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Backwards compatibility
|
|
|
|
if value, err := in.GetBool("obscure"); err == nil {
|
|
|
|
opt.Obscure = value
|
|
|
|
}
|
|
|
|
if value, err := in.GetBool("noObscure"); err == nil {
|
|
|
|
opt.NoObscure = value
|
|
|
|
}
|
|
|
|
var configOut *fs.ConfigOut
|
2018-11-04 19:23:12 +01:00
|
|
|
switch what {
|
|
|
|
case "create":
|
2021-05-05 12:45:30 +02:00
|
|
|
remoteType, typeErr := in.GetString("type")
|
|
|
|
if typeErr != nil {
|
|
|
|
return nil, typeErr
|
2018-11-04 19:23:12 +01:00
|
|
|
}
|
2021-05-05 12:45:30 +02:00
|
|
|
configOut, err = CreateRemote(ctx, name, remoteType, parameters, opt)
|
2018-11-04 19:23:12 +01:00
|
|
|
case "update":
|
2021-05-05 12:45:30 +02:00
|
|
|
configOut, err = UpdateRemote(ctx, name, parameters, opt)
|
2018-11-04 19:23:12 +01:00
|
|
|
case "password":
|
2021-05-05 12:45:30 +02:00
|
|
|
err = PasswordRemote(ctx, name, parameters)
|
|
|
|
default:
|
|
|
|
err = errors.New("unknown rcConfig type")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-11-04 19:23:12 +01:00
|
|
|
}
|
2021-05-05 12:45:30 +02:00
|
|
|
if !opt.NonInteractive {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
if configOut == nil {
|
|
|
|
configOut = &fs.ConfigOut{}
|
|
|
|
}
|
|
|
|
err = rc.Reshape(&out, configOut)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return out, nil
|
2018-11-04 19:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-06-19 15:51:37 +02:00
|
|
|
See the [config delete](/commands/rclone_config_delete/) command for more information on the above.
|
2018-11-04 19:23:12 +01:00
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2022-12-02 14:44:08 +01:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
rc.Add(rc.Call{
|
|
|
|
Path: "config/setpath",
|
|
|
|
Fn: rcSetPath,
|
|
|
|
Title: "Set the path of the config file",
|
|
|
|
AuthRequired: true,
|
|
|
|
Help: `
|
|
|
|
Parameters:
|
|
|
|
|
|
|
|
- path - path to the config file to use
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the config file path
|
|
|
|
func rcSetPath(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
|
|
|
path, err := in.GetString("path")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = SetConfigPath(path)
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-01-17 11:36:17 +01:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
rc.Add(rc.Call{
|
|
|
|
Path: "config/paths",
|
|
|
|
Fn: rcPaths,
|
|
|
|
Title: "Reads the config file path and other important paths.",
|
|
|
|
AuthRequired: true,
|
|
|
|
Help: `
|
|
|
|
Returns a JSON object with the following keys:
|
|
|
|
|
|
|
|
- config: path to config file
|
|
|
|
- cache: path to root of cache directory
|
|
|
|
- temp: path to root of temporary directory
|
|
|
|
|
|
|
|
Eg
|
|
|
|
|
|
|
|
{
|
|
|
|
"cache": "/home/USER/.cache/rclone",
|
|
|
|
"config": "/home/USER/.rclone.conf",
|
|
|
|
"temp": "/tmp"
|
|
|
|
}
|
|
|
|
|
|
|
|
See the [config paths](/commands/rclone_config_paths/) command for more information on the above.
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the config file path
|
|
|
|
func rcPaths(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
|
|
|
return rc.Params{
|
|
|
|
"config": GetConfigPath(),
|
|
|
|
"cache": GetCacheDir(),
|
|
|
|
"temp": os.TempDir(),
|
|
|
|
}, nil
|
|
|
|
}
|