config

package
v0.0.0-...-f81bbf2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

* knoxite * Copyright (c) 2020, Nicolas Martin <penguwin@penguwin.eu> * 2020, Sergio Rubio <sergio@rubio.im> * * For license see LICENSE

* knoxite * Copyright (c) 2020, Nicolas Martin <penguwin@penguwin.eu> * 2020, Sergio Rubio <sergio@rubio.im> * * For license see LICENSE

* knoxite * Copyright (c) 2020, Nicolas Martin <penguwin@penguwin.eu> * 2020, Sergio Rubio <sergio@rubio.im> * * For license see LICENSE

* knoxite * Copyright (c) 2020, Nicolas Martin <penguwin@penguwin.eu> * 2020, Sergio Rubio <sergio@rubio.im> * * For license see LICENSE

Index

Constants

View Source
const (
	FileConf = iota
	CryptoConf
	MemoryConf
)

Available configuration backends.

View Source
const EncryptedHeaderPrefix = "knoxiteconf+"

EncryptedHeaderPrefix is added to the encrypted configuration to make it possible to detect it's an encrypted configuration file.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath returns Knoxite's default config path.

The path returned is OS dependant. If there's an error while trying to figure out the OS dependant path, "knoxite.conf" in the current working dir is returned.

func IsEncrypted

func IsEncrypted(u *url.URL) (bool, error)

IsEncrypted returns true and no error if the configuration is encrypted

If the error returned is not nil, an error was returned while opening or reading the file.

func Lookup

func Lookup() string

Lookup tries to find the config file.

If a config file is found in the current working directory, that's returned. Otherwise we try to locate it following an OS dependant:

Unix:

  • ~/.config/knoxite/knoxite.conf

macOS:

  • ~/Library/Preferences/knoxite/knoxite.conf

Windows:

  • %LOCALAPPDATA%/knoxite/Config/knoxite.conf

If no valid config file is found, an empty string is returned.

Types

type AESBackend

type AESBackend struct{}

AESBackend symmetrically encrypts the configuration file using AES-GCM.

func NewAESBackend

func NewAESBackend(u *url.URL) (*AESBackend, error)

NewAESBackend creates the backend.

Given the password is required to encrypt/decrypt the configuration, if the URL passed doesn't have a password or PasswordEnvVar is not defined, it'll return an error.

func (*AESBackend) Load

func (b *AESBackend) Load(u *url.URL) (*Config, error)

Load configuration file from the given URL and decrypt it.

func (*AESBackend) Save

func (b *AESBackend) Save(config *Config) error

Save encrypts then saves the configuration.

func (*AESBackend) Type

func (b *AESBackend) Type() int

type Config

type Config struct {
	Repositories map[string]RepoConfig `toml:"repositories"`
	// contains filtered or unexported fields
}

func New

func New(url string) (*Config, error)

New returns a new Config struct

The URL will be matched against all the supported backends and the first backend that can handle the URL scheme will be loaded.

func (*Config) Load

func (c *Config) Load() error

Load the configuration.

The backend loaded will be responsible for loading it from the given URL.

func (*Config) Save

func (c *Config) Save() error

func (*Config) SetURL

func (c *Config) SetURL(u string) error

SetURL updates the configuration URL.

Next time the config is loaded or saved the new URL will be used.

func (*Config) Type

func (c *Config) Type() int

Type of the backend which is currently being used.

func (*Config) URL

func (c *Config) URL() *url.URL

URL currently being used.

type ConfigBackend

type ConfigBackend interface {
	Load(*url.URL) (*Config, error)
	Save(*Config) error
	Type() int
}

ConfigBackend is the interface implemented by the configuration backends.

Backends are responsible for loading and saving the Config struct to the local filesystem, the network, etc.

type FileBackend

type FileBackend struct{}

FileBackend implements a filesystem backend for the configuration.

func NewFileBackend

func NewFileBackend() *FileBackend

NewFileBackend returns a FileBackend that handles loading and saving files from the local filesytem.

func (*FileBackend) Load

func (fs *FileBackend) Load(u *url.URL) (*Config, error)

Load a config from a URL.

func (*FileBackend) Save

func (fs *FileBackend) Save(config *Config) error

Save config.

func (*FileBackend) Type

func (fs *FileBackend) Type() int

type MemBackend

type MemBackend struct {
	// contains filtered or unexported fields
}

MemBackend implements a dummy memory backend for the configuration.

func NewMemBackend

func NewMemBackend() *MemBackend

NewMemBackend returns a backend that handles loading and saving the configuration from memory.

func (*MemBackend) Load

func (m *MemBackend) Load(u *url.URL) (*Config, error)

Load the config from memory.

No need to do anything here, already loaded.

func (*MemBackend) Save

func (m *MemBackend) Save(config *Config) error

Save the config to memory.

No need to do anything special here, already in memory.

func (*MemBackend) Type

func (m *MemBackend) Type() int

type RepoConfig

type RepoConfig struct {
	Url             string   `toml:"url" comment:"Repository directory to backup to/restore from"`
	Compression     string   `toml:"compression" comment:"Compression algo to use: none (default), flate, gzip, lzma, zlib, zstd"`
	Tolerance       uint     `toml:"tolerance" comment:"Failure tolerance against n backend failures"`
	Encryption      string   `toml:"encryption" comment:"Encryption algo to use: aes (default), none"`
	Pedantic        bool     `toml:"pedantic" comment:"Stop backup operation after the first error occurred"`
	StoreExcludes   []string `toml:"store_excludes" comment:"Specify excludes for the store operation"`
	RestoreExcludes []string `toml:"restore_excludes" comment:"Specify excludes for the restore operation"`
}

The RepoConfig struct contains all the default values for a a repository.

Jump to

Keyboard shortcuts

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