config

package
v1.57.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 38 Imported by: 5

Documentation

Overview

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

Index

Constants

View Source
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 = "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"
)

Variables

View Source
var (

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

	// PassConfigKeyForDaemonization 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
)
View Source
var ErrorConfigFileNotFound = errors.New("config file not found")

ErrorConfigFileNotFound is returned when the config file is not found

View Source
var (
	// Password can be used to configure the random password generator
	Password = random.Password
)

Global

View Source
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

Functions

func Authorize

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

Authorize is for remote authorization of headless machines.

It expects 1, 2 or 3 arguments

rclone authorize "fs name"
rclone authorize "fs name" "base64 encoded JSON blob"
rclone authorize "fs name" "client id" "client secret"

func ChangePassword

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

func Choose(what string, kind string, choices, help []string, defaultValue string, required bool, newOk bool) string

Choose one of the choices, or default, or type a new string if newOk is set

func ChooseNumber

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

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

ChooseOption asks the user to choose an option

func ChoosePassword added in v1.57.1

func ChoosePassword(defaultValue string, required bool) string

ChoosePassword asks the user for a password

func ChooseRemote

func ChooseRemote() string

ChooseRemote chooses a remote name

func ClearConfigPassword added in v1.55.0

func ClearConfigPassword()

ClearConfigPassword sets the current the password to empty

func Command

func Command(commands []string) byte

Command - choose one

func CommandDefault added in v1.6.1

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

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 CopyRemote

func CopyRemote(name string)

CopyRemote copies a config section

func CreateRemote

func CreateRemote(ctx context.Context, name string, Type string, keyValues rc.Params, opts UpdateRemoteOpt) (out *fs.ConfigOut, err error)

CreateRemote creates a new remote with name, type 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 Decrypt added in v1.55.0

func Decrypt(b io.ReadSeeker) (io.Reader, error)

Decrypt will automatically decrypt a reader

func DeleteRemote

func DeleteRemote(name string)

DeleteRemote gets the user to delete a remote

func Dump

func Dump() error

Dump dumps all the config as a JSON file

func DumpRcBlob

func DumpRcBlob() (dump rc.Params)

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

func DumpRcRemote

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

DumpRcRemote dumps the config for a single remote

func EditConfig

func EditConfig(ctx context.Context) (err error)

EditConfig edits the config file interactively

func EditRemote

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

EditRemote gets the user to edit a remote

func Encrypt added in v1.55.0

func Encrypt(src io.Reader, dst io.Writer) error

Encrypt the config file

func Enter added in v1.57.1

func Enter(what string, kind string, defaultValue string, required bool) string

Enter prompts for an input value of a specified type

func FileDeleteKey

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

func FileGet(section, key string) string

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

It looks up defaults in the environment if they are present

func FileGetFlag

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 FileSections

func FileSections() []string

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

func FileSet

func FileSet(section, key, value string)

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

func GetCacheDir added in v1.57.1

func GetCacheDir() string

GetCacheDir returns the default directory for cache

The directory is neither guaranteed to exist nor have accessible permissions. Users of this should make a subdirectory and use MkdirAll() to create it and any parents.

func GetConfigPath added in v1.56.0

func GetConfigPath() string

GetConfigPath returns the current config file path

func GetPassword

func GetPassword(prompt string) string

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

func JSONListProviders

func JSONListProviders() error

JSONListProviders prints all the providers and options in JSON format

func NewRemote

func NewRemote(ctx context.Context, name string) error

NewRemote make a new remote from its name

func NewRemoteName

func NewRemoteName() (name string)

NewRemoteName asks the user for a name for a new remote

func OkRemote

func OkRemote(name string) bool

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

func PasswordRemote

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 PostConfig added in v1.56.0

func PostConfig(ctx context.Context, name string, m configmap.Mapper, ri *fs.RegInfo) error

PostConfig configures the backend after the main config has been done

The is the user interface loop that drives the post configuration backend config.

func ReadNonEmptyLine added in v1.6.1

func ReadNonEmptyLine(prompt string) string

ReadNonEmptyLine prints prompt and calls Readline until non empty

func ReadPassword

func ReadPassword() string

ReadPassword reads a password without echoing it to the terminal.

func RemoteConfig

func RemoteConfig(ctx context.Context, name string) error

RemoteConfig runs the config helper for the remote if needed

func RenameRemote

func RenameRemote(name string)

RenameRemote renames a config section

func SaveConfig

func SaveConfig()

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

func SetCacheDir added in v1.57.1

func SetCacheDir(path string) (err error)

SetCacheDir sets new default directory for cache

func SetConfigPassword added in v1.55.0

func SetConfigPassword(password string) error

SetConfigPassword will set the configKey to the hash of the password. If the length of the password is zero after trimming+normalization, an error is returned.

func SetConfigPath added in v1.56.0

func SetConfigPath(path string) (err error)

SetConfigPath sets new config file path

Checks for empty string, os null device, or special path, all of which indicates in-memory config.

func SetData added in v1.56.0

func SetData(newData Storage)

SetData sets new config file storage

func SetPassword

func SetPassword()

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

func SetTempDir added in v1.57.1

func SetTempDir(path string) (err error)

SetTempDir sets new default directory to use for temporary files.

Assuming golang's os.TempDir is used to get the directory: "On Unix systems, it returns $TMPDIR if non-empty, else /tmp. On Windows, it uses GetTempPath, returning the first non-empty value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory."

To override the default we therefore set environment variable TMPDIR on Unix systems, and both TMP and TEMP on Windows (they are almost exclusively aliases for the same path, and programs may refer to to either of them). This should make all libraries and forked processes use the same.

func SetValueAndSave

func SetValueAndSave(name, key, value string) 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

func ShowConfig()

ShowConfig prints the (unencrypted) config options

func ShowConfigLocation

func ShowConfigLocation()

ShowConfigLocation prints the location of the config file in use

func ShowRemote

func ShowRemote(name string)

ShowRemote shows the contents of the remote

func ShowRemotes

func ShowRemotes()

ShowRemotes shows an overview of the config file

func UpdateRemote

func UpdateRemote(ctx context.Context, name string, keyValues rc.Params, opt UpdateRemoteOpt) (out *fs.ConfigOut, err error)

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

Types

type Storage added in v1.55.0

type Storage interface {
	// GetSectionList returns a slice of strings with names for all the
	// sections
	GetSectionList() []string

	// HasSection returns true if section exists in the config file
	HasSection(section string) bool

	// DeleteSection removes the named section and all config from the
	// config file
	DeleteSection(section string)

	// GetKeyList returns the keys in this section
	GetKeyList(section string) []string

	// GetValue returns the key in section with a found flag
	GetValue(section string, key string) (value string, found bool)

	// SetValue sets the value under key in section
	SetValue(section string, key string, value string)

	// DeleteKey removes the key under section
	DeleteKey(section string, key string) bool

	// Load the config from permanent storage
	Load() error

	// Save the config to permanent storage
	Save() error

	// Serialize the config into a string
	Serialize() (string, error)
}

Storage defines an interface for loading and saving config to persistent storage. Rclone provides a default implementation to load and save to a config file when this is imported

import "github.com/artpar/rclone/fs/config/configfile" configfile.Install()

func Data added in v1.55.0

func Data() Storage

Data returns current config file storage

func LoadedData added in v1.56.0

func LoadedData() Storage

LoadedData ensures the config file storage is loaded and returns it

type UpdateRemoteOpt added in v1.56.0

type UpdateRemoteOpt struct {
	// Treat all passwords as plain that need obscuring
	Obscure bool `json:"obscure"`
	// Treat all passwords as obscured
	NoObscure bool `json:"noObscure"`
	// Don't interact with the user - return questions
	NonInteractive bool `json:"nonInteractive"`
	// If set then supply state and result parameters to continue the process
	Continue bool `json:"continue"`
	// If set then ask all the questions, not just the post config questions
	All bool `json:"all"`
	// State to restart with - used with Continue
	State string `json:"state"`
	// Result to return - used with Continue
	Result string `json:"result"`
	// If set then edit existing values
	Edit bool `json:"edit"`
}

UpdateRemoteOpt configures the remote update

Directories

Path Synopsis
Package configfile implements a config file loader and saver
Package configfile implements a config file loader and saver
Package configflags defines the flags used by rclone.
Package configflags defines the flags used by rclone.
Package configmap provides an abstraction for reading and writing config
Package configmap provides an abstraction for reading and writing config
Package configstruct parses unstructured maps into structures
Package configstruct parses unstructured maps into structures
Package flags contains enhanced versions of spf13/pflag flag routines which will read from the environment also.
Package flags contains enhanced versions of spf13/pflag flag routines which will read from the environment also.
Package obscure contains the Obscure and Reveal commands
Package obscure contains the Obscure and Reveal commands

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL