config

package
v0.0.0-...-b197db6 Latest Latest
Warning

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

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

Documentation

Overview

Package config contains distillery configuration

Index

Constants

This section is empty.

Variables

View Source
var RestrictedSlugs = []string{
	"www",
	"admin",
	PanelDomain.Domain(),
	TriplestoreDomain.Domain(),
	PHPMyAdminDomain.Domain(),
}

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"`

	// Debug determines if error messages should be written as html pages with stack traces to http clients.
	// This potentially exposes sensitive information and may cause certain API responses to be of content type 'text/html' unexpectedly.
	Debug validators.NullableBool `yaml:"debug" validate:"bool" default:"false"`

	// Also serve the panel on the toplevel domain.
	// Note that the panel is *always* servered under the "panel" domain.
	// Disabling this is not recommended.
	Panel validators.NullableBool `yaml:"panel" validate:"bool" default:"true"`

	// 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"`

	// TS determintes if the special Triplestore domain is enabled.
	TS validators.NullableBool `yaml:"ts" validate:"bool" default:"false"`

	// PhpMyAdmin determines if the special PhpMyAdmin domain is enabled.
	PhpMyAdmin validators.NullableBool `yaml:"phpmyadmin" validate:"bool" default:"false"`
}

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.

It is guaranteed that the first domain returned will always be the primary domain.

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) NormSlugFromHost

func (cfg HTTPConfig) NormSlugFromHost(host string) (string, bool)

NormSlugFromHost is like SlugFromHost, but normalizes the panel host

func (HTTPConfig) PanelDomain

func (hcfg HTTPConfig) PanelDomain() string

PanelDomain is the domain name where the control panel runs.

func (HTTPConfig) PanelHostRule

func (cfg HTTPConfig) PanelHostRule() string

DefaultHostRule returns the host rule for the control panel of this distillery.

func (HTTPConfig) PhpMyAdminURL

func (hcfg HTTPConfig) PhpMyAdminURL() template.URL

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) TCPMuxCommand

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

TCPMuxCommand generates a command line for the sslh executable.

func (HTTPConfig) TSURL

func (hcfg HTTPConfig) TSURL() template.URL

TSDomain returns the full url to the triplestore, if any

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

SpecialDomain represents a reserved domain

var (
	PanelDomain       SpecialDomain = "panel"
	TriplestoreDomain SpecialDomain = "ts"
	PHPMyAdminDomain  SpecialDomain = "phpmyadmin"
)

func (SpecialDomain) Domain

func (sd SpecialDomain) Domain() string

type TSConfig

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

	// DangerouslyUseAdapterPrefixes inidicates if scanning for prefixes should just use prefixes declared in all adapters.
	// This may not reflect what is actually in the database.
	DangerouslyUseAdapterPrefixes validators.NullableBool `yaml:"dangerously_use_adapter_prefixes" default:"false" validate:"bool"`
}

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