rclone: github.com/ncw/rclone/fs/config Index | Files | Directories

package config

import "github.com/ncw/rclone/fs/config"

Package config reads, writes and edits the config file and deals with command line flags


Package Files

config.go config_read_password.go config_unix.go rc.go


const (

    // ConfigToken is the key used to store the token under
    ConfigToken = "token"

    // ConfigClientID is the config key used to store the client id
    ConfigClientID = "client_id"

    // ConfigClientSecret is the config key used to store the client secret
    ConfigClientSecret = "client_secret"

    // ConfigAuthURL is the config key used to store the auth server endpoint
    ConfigAuthURL = "auth_url"

    // ConfigTokenURL is the config key used to store the token server endpoint
    ConfigTokenURL = "token_url"

    // ConfigEncoding is the config key to change the encoding for a backend
    ConfigEncoding = "encoding"

    // ConfigEncodingHelp is the help for ConfigEncoding
    ConfigEncodingHelp = "This sets the encoding for the backend.\n\nSee: the [encoding section in the overview](/overview/#encoding) for more info."

    // ConfigAuthorize indicates that we just want "rclone authorize"
    ConfigAuthorize = "config_authorize"

    // ConfigAuthNoBrowser indicates that we do not want to open browser
    ConfigAuthNoBrowser = "config_auth_no_browser"


var (

    // ConfigPath points to the config file
    ConfigPath = makeConfigPath()

    // CacheDir points to the cache directory.  Users of this
    // should make a subdirectory and use MkdirAll() to create it
    // and any parents.
    CacheDir = makeCacheDir()

    // output of prompt for password
    PasswordPromptOutput = os.Stderr

    // If set to true, the configKey is obscured with obscure.Obscure and saved to a temp file when it is
    // calculated from the password. The path of that temp file is then written to the environment variable
    // `_RCLONE_CONFIG_KEY_FILE`. If `_RCLONE_CONFIG_KEY_FILE` is present, password prompt is skipped and `RCLONE_CONFIG_PASS` ignored.
    // For security reasons, the temp file is deleted once the configKey is successfully loaded.
    // This can be used to pass the configKey to a child process.
    PassConfigKeyForDaemonization = false

    // Password can be used to configure the random password generator
    Password = random.Password


var ReadLine = func() string {
    buf := bufio.NewReader(os.Stdin)
    line, err := buf.ReadString('\n')
    if err != nil {
        log.Fatalf("Failed to read line: %v", err)
    return strings.TrimSpace(line)

ReadLine reads some input

func Authorize Uses

func Authorize(ctx context.Context, args []string, noAutoBrowser bool)

Authorize is for remote authorization of headless machines.

It expects 1 or 3 arguments

rclone authorize "fs name"
rclone authorize "fs name" "client id" "client secret"

func ChangePassword Uses

func ChangePassword(name string) string

ChangePassword will query the user twice for the named password. If the same password is entered it is returned.

func Choose Uses

func Choose(what string, defaults, help []string, newOk bool) string

Choose one of the defaults or type a new string if newOk is set

func ChooseNumber Uses

func ChooseNumber(what string, min, max int) int

ChooseNumber asks the user to enter a number between min and max inclusive prompting them with what.

func ChooseOption Uses

func ChooseOption(o *fs.Option, name string) string

ChooseOption asks the user to choose an option

func ChooseRemote Uses

func ChooseRemote() string

ChooseRemote chooses a remote name

func Command Uses

func Command(commands []string) byte

Command - choose one

func CommandDefault Uses

func CommandDefault(commands []string, defaultIndex int) byte

CommandDefault - choose one. If return is pressed then it will chose the defaultIndex if it is >= 0

func Confirm Uses

func Confirm(Default bool) bool

Confirm asks the user for Yes or No and returns true or false

If the user presses enter then the Default will be used

func ConfirmWithConfig Uses

func ConfirmWithConfig(ctx context.Context, m configmap.Getter, configName string, Default bool) bool

ConfirmWithConfig asks the user for Yes or No and returns true or false.

If AutoConfirm is set, it will look up the value in m and return that, but if it isn't set then it will return the Default value passed in

func CopyRemote Uses

func CopyRemote(name string)

CopyRemote copies a config section

func CreateRemote Uses

func CreateRemote(ctx context.Context, name string, provider string, keyValues rc.Params, doObscure, noObscure bool) error

CreateRemote creates a new remote with name, provider and a list of parameters which are key, value pairs. If update is set then it adds the new keys rather than replacing all of them.

func DeleteRemote Uses

func DeleteRemote(name string)

DeleteRemote gets the user to delete a remote

func Dump Uses

func Dump() error

Dump dumps all the config as a JSON file

func DumpRcBlob Uses

func DumpRcBlob() (dump rc.Params)

DumpRcBlob dumps all the config as an unstructured blob suitable for the rc

func DumpRcRemote Uses

func DumpRcRemote(name string) (dump rc.Params)

DumpRcRemote dumps the config for a single remote

func EditConfig Uses

func EditConfig(ctx context.Context)

EditConfig edits the config file interactively

func EditRemote Uses

func EditRemote(ctx context.Context, ri *fs.RegInfo, name string)

EditRemote gets the user to edit a remote

func FileDeleteKey Uses

func FileDeleteKey(section, key string) bool

FileDeleteKey deletes the config key in the config file. It returns true if the key was deleted, or returns false if the section or key didn't exist.

func FileGet Uses

func FileGet(section, key string, defaultVal ...string) string

FileGet gets the config key under section returning the default or empty string if not set.

It looks up defaults in the environment if they are present

func FileGetFlag Uses

func FileGetFlag(section, key string) (string, bool)

FileGetFlag gets the config key under section returning the the value and true if found and or ("", false) otherwise

func FileGetFresh Uses

func FileGetFresh(section, key string) (value string, err error)

FileGetFresh reads the config key under section return the value or an error if the config file was not found or that value couldn't be read.

func FileRefresh Uses

func FileRefresh() error

FileRefresh ensures the latest configFile is loaded from disk

func FileSections Uses

func FileSections() []string

FileSections returns the sections in the config file including any defined by environment variables.

func FileSet Uses

func FileSet(section, key, value string)

FileSet sets the key in section to value. It doesn't save the config file.

func GetPassword Uses

func GetPassword(prompt string) string

GetPassword asks the user for a password with the prompt given.

func JSONListProviders Uses

func JSONListProviders() error

JSONListProviders prints all the providers and options in JSON format

func LoadConfig Uses

func LoadConfig(ctx context.Context)

LoadConfig loads the config file

func MustFindByName Uses

func MustFindByName(name string) *fs.RegInfo

MustFindByName finds the RegInfo for the remote name passed in or exits with a fatal error.

func NewRemote Uses

func NewRemote(ctx context.Context, name string)

NewRemote make a new remote from its name

func NewRemoteName Uses

func NewRemoteName() (name string)

NewRemoteName asks the user for a name for a new remote

func OkRemote Uses

func OkRemote(name string) bool

OkRemote prints the contents of the remote and ask if it is OK

func PasswordRemote Uses

func PasswordRemote(ctx context.Context, name string, keyValues rc.Params) error

PasswordRemote adds the keyValues passed in to the remote of name. keyValues should be key, value pairs.

func ReadNonEmptyLine Uses

func ReadNonEmptyLine(prompt string) string

ReadNonEmptyLine prints prompt and calls Readline until non empty

func ReadPassword Uses

func ReadPassword() string

ReadPassword reads a password without echoing it to the terminal.

func RemoteConfig Uses

func RemoteConfig(ctx context.Context, name string)

RemoteConfig runs the config helper for the remote if needed

func RenameRemote Uses

func RenameRemote(name string)

RenameRemote renames a config section

func SaveConfig Uses

func SaveConfig()

SaveConfig calling function which saves configuration file. if saveConfig returns error trying again after sleep.

func SetPassword Uses

func SetPassword()

SetPassword will allow the user to modify the current configuration encryption settings.

func SetValueAndSave Uses

func SetValueAndSave(name, key, value string) (err error)

SetValueAndSave sets the key to the value and saves just that value in the config file. It loads the old config file in from disk first and overwrites the given value only.

func ShowConfig Uses

func ShowConfig()

ShowConfig prints the (unencrypted) config options

func ShowConfigLocation Uses

func ShowConfigLocation()

ShowConfigLocation prints the location of the config file in use

func ShowRemote Uses

func ShowRemote(name string)

ShowRemote shows the contents of the remote

func ShowRemotes Uses

func ShowRemotes()

ShowRemotes shows an overview of the config file

func UpdateRemote Uses

func UpdateRemote(ctx context.Context, name string, keyValues rc.Params, doObscure, noObscure bool) error

UpdateRemote adds the keyValues passed in to the remote of name. keyValues should be key, value pairs.


configflagsPackage configflags defines the flags used by rclone.
configmapPackage configmap provides an abstraction for reading and writing config
configstructPackage configstruct parses unstructured maps into structures
flagsPackage flags contains enhanced versions of spf13/pflag flag routines which will read from the environment also.
obscurePackage obscure contains the Obscure and Reveal commands

Package config imports 40 packages (graph) and is imported by 121 packages. Updated 2020-12-01. Refresh now. Tools for package owners.