config

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextKey = struct{ string }{"config"}

ContextKey is the context key for the config.

Functions

func DefaultDataPath

func DefaultDataPath() string

DefaultDataPath returns the path to the data directory. It uses the SOFT_SERVE_DATA_PATH environment variable if set, otherwise it uses "data".

func IsDebug

func IsDebug() bool

IsDebug returns true if the server is running in debug mode.

func IsVerbose

func IsVerbose() bool

IsVerbose returns true if the server is running in verbose mode. Verbose mode is only enabled if debug mode is enabled.

func WithContext

func WithContext(ctx context.Context, cfg *Config) context.Context

WithContext returns a new context with the configuration attached.

Types

type Config

type Config struct {
	// Name is the name of the server.
	Name string `env:"NAME" yaml:"name"`

	// SSH is the configuration for the SSH server.
	SSH SSHConfig `envPrefix:"SSH_" yaml:"ssh"`

	// Git is the configuration for the Git daemon.
	Git GitConfig `envPrefix:"GIT_" yaml:"git"`

	// HTTP is the configuration for the HTTP server.
	HTTP HTTPConfig `envPrefix:"HTTP_" yaml:"http"`

	// Stats is the configuration for the stats server.
	Stats StatsConfig `envPrefix:"STATS_" yaml:"stats"`

	// Log is the logger configuration.
	Log LogConfig `envPrefix:"LOG_" yaml:"log"`

	// DB is the database configuration.
	DB DBConfig `envPrefix:"DB_" yaml:"db"`

	// LFS is the configuration for Git LFS.
	LFS LFSConfig `envPrefix:"LFS_" yaml:"lfs"`

	// Jobs is the configuration for cron jobs
	Jobs JobsConfig `envPrefix:"JOBS_" yaml:"jobs"`

	// InitialAdminKeys is a list of public keys that will be added to the list of admins.
	InitialAdminKeys []string `env:"INITIAL_ADMIN_KEYS" envSeparator:"\n" yaml:"initial_admin_keys"`

	// DataPath is the path to the directory where Soft Serve will store its data.
	DataPath string `env:"DATA_PATH" yaml:"-"`
}

Config is the configuration for Soft Serve.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default Config. All the path values are relative to the data directory. Use Validate() to validate the config and ensure absolute paths.

func FromContext

func FromContext(ctx context.Context) *Config

FromContext returns the configuration from the context.

func (*Config) AdminKeys

func (c *Config) AdminKeys() []ssh.PublicKey

AdminKeys returns the server admin keys.

func (*Config) ConfigPath

func (c *Config) ConfigPath() string

ConfigPath returns the path to the config file.

func (*Config) Environ

func (c *Config) Environ() []string

Environ returns the config as a list of environment variables.

func (*Config) Exist

func (c *Config) Exist() bool

Exist returns true if the config file exists.

func (*Config) Parse

func (c *Config) Parse() error

Parse parses the config from the default file path and environment variables. This also calls Validate() on the config.

func (*Config) ParseEnv

func (c *Config) ParseEnv() error

ParseEnv parses the config from the environment variables. This also calls Validate() on the config.

func (*Config) ParseFile

func (c *Config) ParseFile() error

ParseFile parses the config from the default file path. This also calls Validate() on the config.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration. It updates the configuration with absolute paths.

func (*Config) WriteConfig

func (c *Config) WriteConfig() error

WriteConfig writes the configuration to the default file.

type DBConfig

type DBConfig struct {
	// Driver is the driver for the database.
	Driver string `env:"DRIVER" yaml:"driver"`

	// DataSource is the database data source name.
	DataSource string `env:"DATA_SOURCE" yaml:"data_source"`
}

DBConfig is the database connection configuration.

type GitConfig

type GitConfig struct {
	// ListenAddr is the address on which the Git daemon will listen.
	ListenAddr string `env:"LISTEN_ADDR" yaml:"listen_addr"`

	// PublicURL is the public URL of the Git daemon server.
	PublicURL string `env:"PUBLIC_URL" yaml:"public_url"`

	// MaxTimeout is the maximum number of seconds a connection can take.
	MaxTimeout int `env:"MAX_TIMEOUT" yaml:"max_timeout"`

	// IdleTimeout is the number of seconds a connection can be idle before it is closed.
	IdleTimeout int `env:"IDLE_TIMEOUT" yaml:"idle_timeout"`

	// MaxConnections is the maximum number of concurrent connections.
	MaxConnections int `env:"MAX_CONNECTIONS" yaml:"max_connections"`
}

GitConfig is the Git daemon configuration for the server.

type HTTPConfig

type HTTPConfig struct {
	// ListenAddr is the address on which the HTTP server will listen.
	ListenAddr string `env:"LISTEN_ADDR" yaml:"listen_addr"`

	// TLSKeyPath is the path to the TLS private key.
	TLSKeyPath string `env:"TLS_KEY_PATH" yaml:"tls_key_path"`

	// TLSCertPath is the path to the TLS certificate.
	TLSCertPath string `env:"TLS_CERT_PATH" yaml:"tls_cert_path"`

	// PublicURL is the public URL of the HTTP server.
	PublicURL string `env:"PUBLIC_URL" yaml:"public_url"`
}

HTTPConfig is the HTTP configuration for the server.

type JobsConfig

type JobsConfig struct {
	MirrorPull string `env:"MIRROR_PULL" yaml:"mirror_pull"`
}

JobsConfig is the configuration for cron jobs.

type LFSConfig

type LFSConfig struct {
	// Enabled is whether or not Git LFS is enabled.
	Enabled bool `env:"ENABLED" yaml:"enabled"`

	// SSHEnabled is whether or not Git LFS over SSH is enabled.
	// This is only used if LFS is enabled.
	SSHEnabled bool `env:"SSH_ENABLED" yaml:"ssh_enabled"`
}

LFSConfig is the configuration for Git LFS.

type LogConfig

type LogConfig struct {
	// Format is the format of the logs.
	// Valid values are "json", "logfmt", and "text".
	Format string `env:"FORMAT" yaml:"format"`

	// Time format for the log `ts` field.
	// Format must be described in Golang's time format.
	TimeFormat string `env:"TIME_FORMAT" yaml:"time_format"`

	// Path to a file to write logs to.
	// If not set, logs will be written to stderr.
	Path string `env:"PATH" yaml:"path"`
}

LogConfig is the logger configuration.

type SSHConfig

type SSHConfig struct {
	// ListenAddr is the address on which the SSH server will listen.
	ListenAddr string `env:"LISTEN_ADDR" yaml:"listen_addr"`

	// PublicURL is the public URL of the SSH server.
	PublicURL string `env:"PUBLIC_URL" yaml:"public_url"`

	// KeyPath is the path to the SSH server's private key.
	KeyPath string `env:"KEY_PATH" yaml:"key_path"`

	// ClientKeyPath is the path to the server's client private key.
	ClientKeyPath string `env:"CLIENT_KEY_PATH" yaml:"client_key_path"`

	// MaxTimeout is the maximum number of seconds a connection can take.
	MaxTimeout int `env:"MAX_TIMEOUT" yaml:"max_timeout"`

	// IdleTimeout is the number of seconds a connection can be idle before it is closed.
	IdleTimeout int `env:"IDLE_TIMEOUT" yaml:"idle_timeout"`
}

SSHConfig is the configuration for the SSH server.

func (SSHConfig) KeyPair

func (c SSHConfig) KeyPair() (*keygen.SSHKeyPair, error)

KeyPair returns the server's SSH key pair.

type StatsConfig

type StatsConfig struct {
	// ListenAddr is the address on which the stats server will listen.
	ListenAddr string `env:"LISTEN_ADDR" yaml:"listen_addr"`
}

StatsConfig is the configuration for the stats server.

Jump to

Keyboard shortcuts

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