config

package
v16.10.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package config implements types for handling the configuation for the app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewV2FromV1 added in v16.10.0

func NewV2FromV1(d *dataV1) (*dataV2, error)

Migrate will migrate some settings, depending on the version it finds. Migrations are only going upwards,i.e. from a lower version to a higher version.

Types

type Auth0Tenant

type Auth0Tenant struct {
	Domain   string   `json:"domain"`
	Audience string   `json:"audience"`
	ClientID string   `json:"clientid"`
	Users    []string `json:"users"`
}

type Config

type Config struct {
	Data
	// contains filtered or unexported fields
}

Config is a wrapper for Data

func New

func New() *Config

New returns a Config which is initialized with its default values

func NewConfigFrom

func NewConfigFrom(d *Config) *Config

NewConfigFrom returns a clone of a Config

func (*Config) HasErrors

func (d *Config) HasErrors() bool

HasErrors returns whether there are some error messages in the log.

func (*Config) Merge

func (d *Config) Merge()

Merge merges the values of the known environment variables into the configuration

func (*Config) Messages

func (d *Config) Messages(logger func(level string, v Variable, message string))

Messages calls for each log entry the provided callback. The level has the values 'error', 'warn', or 'info'. The name is the name of the configuration value, e.g. 'api.auth.enable'. The message is the log message.

func (*Config) Overrides

func (d *Config) Overrides() []string

Overrides returns a list of configuration value names that have been overriden by an environment variable.

func (*Config) SetPublicIPs

func (d *Config) SetPublicIPs()

SetPublicIPs will try to figure out the public IPs (v4 and v6) we're running on. There's a timeout of max. 5 seconds to do it. If it fails, the IPs will simply not be set.

func (*Config) Validate

func (d *Config) Validate(resetLogs bool)

Validate validates the current state of the Config for completeness and sanity. Errors are written to the log. Use resetLogs to indicate to reset the logs prior validation.

type Data

type Data struct {
	CreatedAt       time.Time `json:"created_at"`
	LoadedAt        time.Time `json:"-"`
	UpdatedAt       time.Time `json:"-"`
	Version         int64     `json:"version" jsonschema:"minimum=3,maximum=3"`
	ID              string    `json:"id"`
	Name            string    `json:"name"`
	Address         string    `json:"address"`
	CheckForUpdates bool      `json:"update_check"`
	Log             struct {
		Level    string   `json:"level" enums:"debug,info,warn,error,silent" jsonschema:"enum=debug,enum=info,enum=warn,enum=error,enum=silent"`
		Topics   []string `json:"topics"`
		MaxLines int      `json:"max_lines"`
	} `json:"log"`
	DB struct {
		Dir string `json:"dir"`
	} `json:"db"`
	Host struct {
		Name []string `json:"name"`
		Auto bool     `json:"auto"`
	} `json:"host"`
	API struct {
		ReadOnly bool `json:"read_only"`
		Access   struct {
			HTTP struct {
				Allow []string `json:"allow"`
				Block []string `json:"block"`
			} `json:"http"`
			HTTPS struct {
				Allow []string `json:"allow"`
				Block []string `json:"block"`
			} `json:"https"`
		} `json:"access"`
		Auth struct {
			Enable           bool   `json:"enable"`
			DisableLocalhost bool   `json:"disable_localhost"`
			Username         string `json:"username"`
			Password         string `json:"password"`
			JWT              struct {
				Secret string `json:"secret"`
			} `json:"jwt"`
			Auth0 struct {
				Enable  bool          `json:"enable"`
				Tenants []Auth0Tenant `json:"tenants"`
			} `json:"auth0"`
		} `json:"auth"`
	} `json:"api"`
	TLS struct {
		Address  string `json:"address"`
		Enable   bool   `json:"enable"`
		Auto     bool   `json:"auto"`
		Email    string `json:"email"`
		CertFile string `json:"cert_file"`
		KeyFile  string `json:"key_file"`
	} `json:"tls"`
	Storage struct {
		Disk struct {
			Dir   string `json:"dir"`
			Size  int64  `json:"max_size_mbytes"`
			Cache struct {
				Enable   bool   `json:"enable"`
				Size     uint64 `json:"max_size_mbytes"`
				TTL      int64  `json:"ttl_seconds"`
				FileSize uint64 `json:"max_file_size_mbytes"`
				Types    struct {
					Allow []string `json:"allow"`
					Block []string `json:"block"`
				} `json:"types"`
			} `json:"cache"`
		} `json:"disk"`
		Memory struct {
			Auth struct {
				Enable   bool   `json:"enable"`
				Username string `json:"username"`
				Password string `json:"password"`
			} `json:"auth"`
			Size  int64 `json:"max_size_mbytes"`
			Purge bool  `json:"purge"`
		} `json:"memory"`
		CORS struct {
			Origins []string `json:"origins"`
		} `json:"cors"`
		MimeTypes string `json:"mimetypes_file"`
	} `json:"storage"`
	RTMP struct {
		Enable     bool   `json:"enable"`
		EnableTLS  bool   `json:"enable_tls"`
		Address    string `json:"address"`
		AddressTLS string `json:"address_tls"`
		App        string `json:"app"`
		Token      string `json:"token"`
	} `json:"rtmp"`
	SRT struct {
		Enable     bool   `json:"enable"`
		Address    string `json:"address"`
		Passphrase string `json:"passphrase"`
		Token      string `json:"token"`
		Log        struct {
			Enable bool     `json:"enable"`
			Topics []string `json:"topics"`
		} `json:"log"`
	} `json:"srt"`
	FFmpeg struct {
		Binary       string `json:"binary"`
		MaxProcesses int64  `json:"max_processes"`
		Access       struct {
			Input struct {
				Allow []string `json:"allow"`
				Block []string `json:"block"`
			} `json:"input"`
			Output struct {
				Allow []string `json:"allow"`
				Block []string `json:"block"`
			} `json:"output"`
		} `json:"access"`
		Log struct {
			MaxLines   int `json:"max_lines"`
			MaxHistory int `json:"max_history"`
		} `json:"log"`
	} `json:"ffmpeg"`
	Playout struct {
		Enable  bool `json:"enable"`
		MinPort int  `json:"min_port"`
		MaxPort int  `json:"max_port"`
	} `json:"playout"`
	Debug struct {
		Profiling bool `json:"profiling"`
		ForceGC   int  `json:"force_gc"`
	} `json:"debug"`
	Metrics struct {
		Enable           bool  `json:"enable"`
		EnablePrometheus bool  `json:"enable_prometheus"`
		Range            int64 `json:"range_sec"`    // seconds
		Interval         int64 `json:"interval_sec"` // seconds
	} `json:"metrics"`
	Sessions struct {
		Enable          bool     `json:"enable"`
		IPIgnoreList    []string `json:"ip_ignorelist"`
		SessionTimeout  int      `json:"session_timeout_sec"`
		Persist         bool     `json:"persist"`
		PersistInterval int      `json:"persist_interval_sec"`
		MaxBitrate      uint64   `json:"max_bitrate_mbit"`
		MaxSessions     uint64   `json:"max_sessions"`
	} `json:"sessions"`
	Service struct {
		Enable bool   `json:"enable"`
		Token  string `json:"token"`
		URL    string `json:"url"`
	} `json:"service"`
	Router struct {
		BlockedPrefixes []string          `json:"blocked_prefixes"`
		Routes          map[string]string `json:"routes"`
		UIPath          string            `json:"ui_path"`
	} `json:"router"`
}

Data is the actual configuration data for the app

func NewV3FromV2 added in v16.10.0

func NewV3FromV2(d *dataV2) (*Data, error)

type DataVersion added in v16.10.0

type DataVersion struct {
	Version int64 `json:"version"`
}

type Store

type Store interface {
	// Get the current configuration.
	Get() *Config

	// Set a new configuration for persistence.
	Set(data *Config) error

	// GetActive returns the configuration that has been set as
	// active before, otherwise it return nil.
	GetActive() *Config

	// SetActive will keep the given configuration
	// as active in memory. It can be retrieved later with GetActive()
	SetActive(data *Config) error

	// Reload will reload the stored configuration. It has to make sure
	// that all affected components will receiver their potentially
	// changed configuration.
	Reload() error
}

Store is a store for the configuration data.

func NewDummyStore

func NewDummyStore() Store

NewDummyStore returns a store that returns the default config

func NewJSONStore

func NewJSONStore(path string, reloadFn func()) (Store, error)

NewJSONStore will read a JSON config file from the given path. After successfully reading it in, it will be written back to the path. The returned error will be nil if everything went fine. If the path doesn't exist, a default JSON config file will be written to that path. The returned ConfigStore can be used to retrieve or write the config.

type Variable

type Variable struct {
	Value       string
	Name        string
	EnvName     string
	Description string
	Merged      bool
}

Jump to

Keyboard shortcuts

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