beehive: github.com/muesli/beehive/cfg Index | Files

package cfg

import "github.com/muesli/beehive/cfg"

Index

Package Files

aesbackend.go config.go filebackend.go membackend.go

Constants

const EncryptedHeaderPrefix = "beehiveconf+"

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

const PasswordEnvVar = "BEEHIVE_CONFIG_PASSWORD"

PasswordEnvVar defines the environment variable name that should contain the configuration password.

func DefaultPath Uses

func DefaultPath() string

DefaultPath returns Beehive's default config path.

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

func IsEncrypted Uses

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 Uses

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/app/filename.conf

macOS:

- ~/Library/Preferences/app/filename.conf

Windows:

- %LOCALAPPDATA%/app/Config/filename.conf

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

type AESBackend Uses

type AESBackend struct{}

AESBackend symmetrically encrypts the configuration file using AES-GCM

func NewAESBackend Uses

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 Uses

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

Load configuration file from the given URL and decrypt it

func (*AESBackend) Save Uses

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

Save encrypts then saves the configuration

type Config Uses

type Config struct {
    Bees    []bees.BeeConfig
    Actions []bees.Action
    Chains  []bees.Chain
    // contains filtered or unexported fields
}

Config contains an entire configuration set for Beehive

func New Uses

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.

A UNIX style path is also accepted, and will be handled by the default FileBackend.

func (*Config) Backend Uses

func (c *Config) Backend() ConfigBackend

Backend currently being used.

func (*Config) Load Uses

func (c *Config) Load() error

Load the configuration.

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

func (*Config) Save Uses

func (c *Config) Save() error

Save the current configuration.

The backend loaded will be responsible for saving it to the given URL

func (*Config) SetURL Uses

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) URL Uses

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

URL currently being used.

type ConfigBackend Uses

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

ConfigBackend is the interface implemented by the configuration backends.

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

type FileBackend Uses

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

FileBackend implements a filesystem backend for the configuration

func NewFileBackend Uses

func NewFileBackend() *FileBackend

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

func (*FileBackend) Load Uses

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

Load loads chains from config

func (*FileBackend) Save Uses

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

Save saves chains to config

type Format Uses

type Format int
const (
    FormatJSON Format = iota
    FormatYAML        = iota
)

type MemBackend Uses

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

MemBackend implements a dummy memory backend for the configuration

func NewMemBackend Uses

func NewMemBackend() *MemBackend

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

func (*MemBackend) Load Uses

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 Uses

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

Save the config to memory

No need to do anything special here, already in memory

Package cfg imports 16 packages (graph) and is imported by 4 packages. Updated 2021-01-26. Refresh now. Tools for package owners.