config

package
v0.0.0-...-dae269f Latest Latest
Warning

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

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

Documentation

Overview

Package config contains distillery configuration

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHostRule

func MakeHostRule(hosts ...string) string

MakeHostRule builds a new Host() rule string to be used by traefik.

func Marshal

func Marshal(config *Config, previous []byte) ([]byte, error)

Marshal marshals this configuration in nicely formatted form. Where possible, this will maintain yaml comments.

Previous may optionally provide the bytes of a previous configuration file to replace settings in. The previous yaml file must be a valid configuration yaml, meaning all fields should be set. When previous is of length 0, the default configuration yaml will be used instead.

func TrimSuffixFold

func TrimSuffixFold(s string, suffix string) string

Types

type Config

type Config struct {
	Listen ListenConfig `yaml:"listen" recurse:"true"`
	Paths  PathsConfig  `yaml:"paths" recurse:"true"`
	HTTP   HTTPConfig   `yaml:"http" recurse:"true"`
	Home   HomeConfig   `yaml:"home" recurse:"true"`
	Docker DockerConfig `yaml:"docker" recurse:"true"`

	SQL SQLConfig `yaml:"sql" recurse:"true"`
	TS  TSConfig  `yaml:"triplestore" recurse:"true"`

	// Maximum age for backup in days
	MaxBackupAge time.Duration `yaml:"age" validate:"duration"`

	// Various components use password-based-authentication.
	// These passwords are generated automatically.
	// This variable can be used to determine their length.
	PasswordLength int `yaml:"password_length" default:"64" validate:"positive"`

	// session secret holds the secret for login
	SessionSecret string `yaml:"session_secret" validate:"nonempty" sensitive:"true"`

	// interval to trigger distillery cron tasks in
	CronInterval time.Duration `yaml:"cron_interval" default:"10m" validate:"duration"`

	// ConfigPath is the path this configuration was loaded from (if any)
	ConfigPath string `yaml:"-"`
}

Config represents the configuration of a WissKI Distillery.

Config is read from a byte stream using [Unmarshal].

Config contains many methods that do not require any interaction with any running components. Methods that require running components are instead store inside the [Distillery] or an appropriate [Component].

func (*Config) CSRFSecret

func (config *Config) CSRFSecret() []byte

CSRFSecret return the csrfSecret derived from the session secret

func (*Config) Marshal

func (config *Config) Marshal(dest io.Writer) error

func (Config) MarshalSensitive

func (config Config) MarshalSensitive() string

func (Config) NewPassword

func (cfg Config) NewPassword() (string, error)

NewPassword returns a new password using the password settings from this configuration

func (*Config) Unmarshal

func (config *Config) Unmarshal(src io.Reader) error

Unmarshal reads configuration from the provided io.Reader, and then validates it. Configuration is read in yaml format.

func (*Config) Validate

func (config *Config) Validate() error

Validate validates this configuration file and sets appropriate defaults

type DatabaseConfig

type DatabaseConfig struct {
	// Credentials for the admin user.
	// Is automatically created if it does not exist.
	AdminUsername string `yaml:"username" default:"admin" validate:"nonempty"`
	AdminPassword string `yaml:"password" validate:"nonempty"  sensitive:"****"`

	// Prefix for new users and data setss
	UserPrefix string `yaml:"user_prefix" default:"wisski-distillery-" validate:"slug"`
	DataPrefix string `yaml:"data_prefix" default:"wisski-distillery-" validate:"slug"`
}

type DockerConfig

type DockerConfig struct {
	NetworkPrefix string `yaml:"network" default:"distillery" validate:"nonempty"`
}

func (DockerConfig) Network

func (dc DockerConfig) Network() string

Network returns the name of the default network to attach all docker containers to.

func (DockerConfig) Networks

func (dc DockerConfig) Networks() []string

Networks returns a list of all docker networks to be created for purposes of the distillery.

type HTTPConfig

type HTTPConfig struct {
	// Each created Drupal Instance corresponds to a single domain name.
	// These domain names should either be a complete domain name or a sub-domain of a default domain.
	// This setting configures the default domain-name to create subdomains of.
	PrimaryDomain string `yaml:"domain" default:"localhost.kwarc.info" validate:"domain"`

	// By default, only the 'self' domain above is caught.
	// To catch additional domains, add them here (comma separated)
	ExtraDomains []string `yaml:"domains" validate:"domains"`

	// The system can support setting up certificate(s) automatically.
	// It can be enabled by setting an email for certbot certificates.
	// This email address can be configured here.
	CertbotEmail string `yaml:"certbot_email" validate:"email"`

	// API determines if the API is enabled.
	// In a future version of the distillery, it will be enabled by default.
	API validators.NullableBool `yaml:"api" validate:"bool" default:"false"`
}

func (HTTPConfig) DefaultHostRule

func (cfg HTTPConfig) DefaultHostRule() string

DefaultHostRule returns the default traefik hostname rule for this distillery. This consists of the [DefaultDomain] as well as [ExtraDomains].

func (HTTPConfig) Domains

func (hcfg HTTPConfig) Domains(sub string) []string

Domains adds the given subdomain to the primary and alias domains. If sub is empty, returns only the domains.

sub is not otherwise validated, and should be normalized by the caller.

func (HTTPConfig) HTTPSEnabled

func (hcfg HTTPConfig) HTTPSEnabled() bool

HTTPSEnabled returns if the distillery has HTTPS enabled, and false otherwise.

func (HTTPConfig) HTTPSEnabledEnv

func (hcfg HTTPConfig) HTTPSEnabledEnv() string

HTTPSEnabledEnv returns "true" if https is enabled, and "false" otherwise.

func (HTTPConfig) HostFromSlug

func (cfg HTTPConfig) HostFromSlug(slug string) string

HostFromSlug returns the hostname belonging to a given slug. When the slug is empty, returns the default (top-level) domain.

func (HTTPConfig) HostRule

func (hcfg HTTPConfig) HostRule(sub string) string

HostRule returns a HostRule for the provided subdomain. See Domains() for usage of sub.

func (HTTPConfig) JoinPath

func (hcfg HTTPConfig) JoinPath(elem ...string) *url.URL

JoinPath returns the root public url joined with the provided parts.

func (HTTPConfig) SlugFromHost

func (cfg HTTPConfig) SlugFromHost(host string) (slug string, ok bool)

SlugFromHost returns the slug belonging to the appropriate host.'

When host is a top-level domain, returns "", true. When no slug is found, returns "", false.

func (HTTPConfig) SpecialDomain

func (hcfg HTTPConfig) SpecialDomain(domain SpecialDomain) string

func (HTTPConfig) TCPMuxCommand

func (hcfg HTTPConfig) TCPMuxCommand(addr string, http string, https string, ssh string) string

TCPMuxCommand generates a command line for the sslh executable.

type HomeConfig

type HomeConfig struct {
	Title        string          `yaml:"title" default:"WissKI Distillery" validate:"nonempty"`
	SelfRedirect *validators.URL `yaml:"redirect" default:"https://github.com/FAU-CDI/wisski-distillery" validate:"https"`
	List         HomeListConfig  `yaml:"list" recurse:"true"`
}

HomeConfig determines options for the homepage of the distillery

type HomeListConfig

type HomeListConfig struct {
	// Is the list enabled for public visits?
	Public validators.NullableBool `yaml:"public" default:"true" validate:"bool"`
	// Is the list enabled for signed-in visits?
	Private validators.NullableBool `yaml:"private" default:"true" validate:"bool"`
	// Title of the list whenever it is shown
	Title string `yaml:"title" default:"WissKIs on this Distillery" validate:"nonempty"`
}

type ListenConfig

type ListenConfig struct {
	// Ports are the public addresses to bind to.
	// Each address is automatically multiplexed to serve http, https and ssh traffic.
	// This should typically be port 80 and port 443.
	Ports []uint16 `yaml:"ports" default:"80" validate:"ports"`

	// SSHPort is the port that shows up as the ssh port in various places in the interface.
	// It is automaticalled added to the ports to listen to.
	SSHPort uint16 `yaml:"ssh" default:"80" validate:"port"`
}

func (ListenConfig) ComposePorts

func (lc ListenConfig) ComposePorts(internal string) []string

ComposePorts returns a list of ports to be used within a docker-compose.yml file. These can be used to forward all ports to the internal port.

type PathsConfig

type PathsConfig struct {
	// Several docker-compose files are created to manage global services and the system itself.
	// On top of this all real-system space will be created under this directory.
	Root string `yaml:"root" default:"/var/www/deploy" validate:"directory"`

	// You can override individual URLS in the homepage
	// Do this by adding URLs (without trailing '/'s) into a JSON file
	OverridesJSON string `yaml:"overrides" validate:"file"`

	// You can block specific prefixes from being picked up by the resolver.
	// Do this by adding one prefix per file.
	ResolverBlocks string `yaml:"blocks" validate:"file"`
}

func (PathsConfig) CurrentExecutable

func (pcfg PathsConfig) CurrentExecutable() string

CurrentExecutable returns the path to the current executable being used. When it does not exist, falls back to the default executable.

func (PathsConfig) ExecutablePath

func (pcfg PathsConfig) ExecutablePath() string

ExecutablePath returns the path to the executable of this distillery.

func (PathsConfig) RuntimeDir

func (pcfg PathsConfig) RuntimeDir() string

RuntimeDir returns the path to the runtime directory

func (PathsConfig) UsingDistilleryExecutable

func (pcfg PathsConfig) UsingDistilleryExecutable() bool

UsingDistilleryExecutable checks if the current process is using the distillery executable

type SQLConfig

type SQLConfig struct {
	DatabaseConfig `yaml:",inline" recurse:"true"`

	// Database to use to store distillery datastructures
	Database string `yaml:"database" default:"distillery" validate:"slug"`
}

type SpecialDomain

type SpecialDomain string
var (
	TriplestoreDomain SpecialDomain = "ts"
)

type TSConfig

type TSConfig struct {
	DatabaseConfig `yaml:",inline" recurse:"true"`
}

type Template

type Template struct {
	RootPath      string
	DefaultDomain string

	TSAdminUser     string
	TSAdminPassword string

	SQLAdminUsername string
	SQLAdminPassword string

	DockerNetworkPrefix string
	SessionSecret       string
}

Template is used to generate a configuration file.

func (Template) Generate

func (tpl Template) Generate() Config

Generate generates a configuration file for this configuration

func (*Template) SetDefaults

func (tpl *Template) SetDefaults() (err error)

SetDefaults sets defaults on the template

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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