1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-23 06:12:20 +00:00
ghostream/internal/config/config.go

125 lines
3.2 KiB
Go
Raw Normal View History

2020-10-11 19:48:00 +00:00
// Package config loads application settings
package config
import (
"net"
2020-10-12 19:23:06 +00:00
"github.com/sherifabdlnaby/configuro"
"gitlab.crans.org/nounous/ghostream/auth"
"gitlab.crans.org/nounous/ghostream/auth/basic"
"gitlab.crans.org/nounous/ghostream/auth/ldap"
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
"gitlab.crans.org/nounous/ghostream/stream/forwarding"
"gitlab.crans.org/nounous/ghostream/stream/srt"
2020-10-13 16:04:00 +00:00
"gitlab.crans.org/nounous/ghostream/stream/telnet"
"gitlab.crans.org/nounous/ghostream/stream/webrtc"
"gitlab.crans.org/nounous/ghostream/transcoder"
"gitlab.crans.org/nounous/ghostream/transcoder/text"
"gitlab.crans.org/nounous/ghostream/web"
)
// Config holds application configuration
type Config struct {
Auth auth.Options
Forwarding forwarding.Options
Monitoring monitoring.Options
Srt srt.Options
2020-10-12 22:15:23 +00:00
Telnet telnet.Options
2020-10-18 09:06:54 +00:00
Transcoder transcoder.Options
Web web.Options
WebRTC webrtc.Options
}
// New configuration with default values
func New() *Config {
return &Config{
Auth: auth.Options{
Enabled: true,
Backend: "Basic",
Basic: basic.Options{
2020-10-12 19:23:06 +00:00
Credentials: make(map[string]string),
},
LDAP: ldap.Options{
URI: "ldap://127.0.0.1:389",
UserDn: "cn=users,dc=example,dc=com",
},
},
Forwarding: make(map[string][]string),
Monitoring: monitoring.Options{
Enabled: true,
ListenAddress: ":2112",
},
Srt: srt.Options{
Enabled: true,
ListenAddress: ":9710",
MaxClients: 64,
},
2020-10-12 22:15:23 +00:00
Telnet: telnet.Options{
Enabled: false,
ListenAddress: ":8023",
},
Transcoder: transcoder.Options{
Text: text.Options{
Enabled: false,
Width: 80,
Height: 45,
Framerate: 20,
},
2020-10-12 22:15:23 +00:00
},
Web: web.Options{
Enabled: true,
Favicon: "/static/img/favicon.svg",
Hostname: "localhost",
ListenAddress: ":8080",
Name: "Ghostream",
MapDomainToStream: make(map[string]string),
PlayerPoster: "/static/img/no_stream.svg",
ViewersCounterRefreshPeriod: 20000,
},
WebRTC: webrtc.Options{
Enabled: true,
MaxPortUDP: 10005,
MinPortUDP: 10000,
STUNServers: []string{"stun:stun.l.google.com:19302"},
},
}
}
// Load global configuration as a struct
func Load() (*Config, error) {
2020-10-12 19:23:06 +00:00
// Create Configuro
config, err := configuro.NewConfig(
configuro.WithLoadFromEnvVars("GHOSTREAM"),
2020-10-12 19:27:44 +00:00
configuro.WithLoadFromConfigFile("/etc/ghostream/ghostream.yml", false),
2020-10-12 19:23:06 +00:00
configuro.WithEnvConfigPathOverload("GHOSTREAM_CONFIG"),
)
2020-10-14 19:33:51 +00:00
if err != nil {
return nil, err
}
2020-10-12 19:23:06 +00:00
// Load default configuration
cfg := New()
2020-10-12 19:23:06 +00:00
// Load values in configuration struct
if err := config.Load(cfg); err != nil {
return nil, err
}
// Copy STUN configuration to clients
cfg.Web.STUNServers = cfg.WebRTC.STUNServers
// Copy SRT server port to display it on web page
_, srtPort, err := net.SplitHostPort(cfg.Srt.ListenAddress)
if err != nil {
return nil, err
}
cfg.Web.SRTServerPort = srtPort
2020-10-12 19:23:06 +00:00
// If no credentials register, add demo account with password "demo"
if len(cfg.Auth.Basic.Credentials) < 1 {
cfg.Auth.Basic.Credentials["demo"] = "$2b$15$LRnG3eIHFlYIguTxZOLH7eHwbQC/vqjnLq6nDFiHSUDKIU.f5/1H6"
}
return cfg, nil
}