config

package
v0.0.0-...-a1758a3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package config provides an interface to configure a pcopy server and client

Index

Constants

View Source
const (
	// DefaultPort defines the default port. Server addresses without port will be expanded to include it.
	DefaultPort = 2586

	// DefaultServerConfigFile defines the default config file at which "pcopy serve" will look for the config.
	// This is a server-only setting.
	DefaultServerConfigFile = "/etc/pcopy/server.conf"

	// DefaultClipboardName defines the default name of the clipboard as it appears in the Web UI
	DefaultClipboardName = "pcopy"

	// DefaultClipboardDir defines the default location to store the clipboard contents at. This setting is only
	// relevant for the server.
	DefaultClipboardDir = "/var/cache/pcopy"

	// DefaultClipboard defines the default clipboard name if it's not overridden by the user. This is primarily
	// used to find the config file location. This setting is only relevant for the client.
	DefaultClipboard = "default"

	// DefaultID is the default file name if none is passed by the user.
	DefaultID = "default"

	// DefaultClipboardSizeLimit is the total size in bytes that the server will allow to be written to the
	// clipboard directory. This setting is only relevant for the server.
	DefaultClipboardSizeLimit = 0

	// DefaultClipboardCountLimit is the total number of files that the server will allow in the clipboard directory.
	// This setting is only relevant for the server.
	DefaultClipboardCountLimit = 0

	// DefaultFileSizeLimit is the size in bytes that each individual clipboard file is allowed to have. The server
	// will reject files larger than that.
	DefaultFileSizeLimit = 0

	// DefaultFileExpireAfter is the duration after which the server will delete a clipboard file.
	DefaultFileExpireAfter = time.Hour * 24 * 7

	// DefaultFileModesAllowed is the default setting for whether files are overwritable
	DefaultFileModesAllowed = "rw ro"

	// FileModeReadWrite allows files to be overwritten
	FileModeReadWrite = "rw"

	// FileModeReadOnly ensures that files cannot be overwritten
	FileModeReadOnly = "ro"

	// EnvKey provides the ability to provide a key for certain CLI commands
	EnvKey = "PCOPY_KEY"

	// EnvConfigDir allows overriding the user-specific config dir
	EnvConfigDir = "PCOPY_CONFIG_DIR"
)

Variables

View Source
var (
	// SystemdUnit contains the systemd unit file content.
	//go:embed "pcopy.service"
	SystemdUnit string
)

Functions

func CollapseServerAddr

func CollapseServerAddr(serverAddr string) string

CollapseServerAddr removes the default port from the given server address if the address contains the default port, but leaves the address unchanged if it doesn't contain it.

func DefaultCertFile

func DefaultCertFile(configFile string, mustExist bool) string

DefaultCertFile returns the default path to the certificate file, relative to the config file. If mustExist is true, the function returns an empty string if the file does not exist.

func DefaultKeyFile

func DefaultKeyFile(configFile string, mustExist bool) string

DefaultKeyFile returns the default path to the key file, relative to the config file. If mustExist is true, the function returns an empty string.

func ExpandServerAddr

func ExpandServerAddr(serverAddr string) string

ExpandServerAddr expands the server address with the default port if no port is provided to a full URL, including protocol prefix. For instance: "myhost" will become "https://myhost:2586", and "myhost:443" will become "https://myhost", but "http://myhost:1234" will remain unchanged.

func ExpandServerAddrsGuess

func ExpandServerAddrsGuess(serverAddr string) []string

ExpandServerAddrsGuess expands the server address (similar to ExpandServerAddr), except that it will return two addresses if no explicit port is passed: one with the default port and one with port 443. This is to be able to do "pcopy join example.com" and have it work unless it's not the default or not 443.

func ExtractClipboard

func ExtractClipboard(filename string) string

ExtractClipboard extracts the name of the clipboard from the config filename, e.g. the name of a clipboard with the config file /etc/pcopy/work.conf is "work".

Types

type Config

type Config struct {
	ListenHTTPS               string
	ListenHTTP                string
	ListenTCP                 string
	ServerAddr                string
	DefaultID                 string
	Key                       *crypto.Key
	KeyFile                   string
	CertFile                  string
	ClipboardName             string
	ClipboardDir              string
	ClipboardSizeLimit        int64
	ClipboardCountLimit       int
	FileSizeLimit             int64
	FileExpireAfterDefault    time.Duration
	FileExpireAfterNonTextMax time.Duration
	FileExpireAfterTextMax    time.Duration
	FileModesAllowed          []string
	ProgressFunc              util.ProgressFunc
	ManagerInterval           time.Duration
	LimitGET                  rate.Limit
	LimitGETBurst             int
	LimitPUT                  rate.Limit
	LimitPUTBurst             int
}

Config is the configuration struct used to configure the client and the server. Some settings only apply to the client, others only to the server. Some apply to both. Many (but not all) of these settings can be set either via the config file, or via command line parameters.

func LoadFromFile

func LoadFromFile(filename string) (*Config, error)

LoadFromFile loads the configuration from a file

func New

func New() *Config

New returns the default config

func (*Config) WriteFile

func (c *Config) WriteFile(filename string) error

WriteFile writes the configuration to a file.

type Store

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

Store represents the config folder

func NewStore

func NewStore() *Store

NewStore creates a new config store using the user-specific config dir

func (*Store) All

func (c *Store) All() map[string]*Config

All reads the config folder and returns a map of config files and their Config structs

func (*Store) FileFromName

func (c *Store) FileFromName(clipboard string) string

FileFromName returns the config file path for the given clipboard name.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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