This commit is contained in:
Lennart J. Kurzweg (Nx2)
2026-03-22 18:48:45 +01:00
parent 41e36a4545
commit 1d99749f72
12 changed files with 567 additions and 216 deletions

View File

@@ -2,13 +2,16 @@ package config
import (
"os"
"slices"
"gopkg.in/yaml.v3"
)
type Access struct {
User string `yaml:"user"`
Mode string `yaml:"mode"` // "read-only" or "read-write"
User string `yaml:"user,omitempty"`
Group string `yaml:"group,omitempty"`
Groups string `yaml:"groups,omitempty"`
Mode string `yaml:"mode"` // "read-only" or "read-write"
}
type Calendar struct {
@@ -17,10 +20,18 @@ type Calendar struct {
Access []Access `yaml:"access,omitempty"`
}
type Aggregate struct {
ID string `yaml:"id"`
Owner string `yaml:"owner"`
Sources []string `yaml:"sources"` // Calendar IDs
Access []Access `yaml:"access,omitempty"`
}
type User struct {
Name string `yaml:"name"`
Password string `yaml:"password"`
PasswordCmd string `yaml:"password_cmd"`
Name string `yaml:"name"`
Password string `yaml:"password"`
PasswordCmd string `yaml:"password_cmd"`
Groups []string `yaml:"groups,omitempty"`
}
type DatabaseConfig struct {
@@ -28,16 +39,18 @@ type DatabaseConfig struct {
}
type ServerConfig struct {
BindAddress string `yaml:"bind_address"`
PublicURL string `yaml:"public_url"`
Redaction string `yaml:"redaction_text"`
BindAddress string `yaml:"bind_address"`
PublicURL string `yaml:"public_url"`
Redaction string `yaml:"redaction_text"`
DefaultClass string `yaml:"default_class"`
}
type Config struct {
Server ServerConfig `yaml:"server"`
Database DatabaseConfig `yaml:"database"`
Users []User `yaml:"users"`
Calendars []Calendar `yaml:"calendars"`
Server ServerConfig `yaml:"server"`
Database DatabaseConfig `yaml:"database"`
Users []User `yaml:"users"`
Calendars []Calendar `yaml:"calendars"`
Aggregates []Aggregate `yaml:"aggregates"`
}
func Load(path string) (*Config, error) {
@@ -53,10 +66,17 @@ func Load(path string) (*Config, error) {
return nil, err
}
cfg.checkConfig()
cfg.setDefaults()
return &cfg, nil
}
func (c *Config) checkConfig() {
if !(slices.Contains([]string{"PUBLIC", "PRIVATE", "CONFIDENTIAL"}, c.Server.DefaultClass)) {
panic("Invaldi Config, default_class")
}
}
func (c *Config) setDefaults() {
if c.Server.BindAddress == "" {
c.Server.BindAddress = ":8080"
@@ -64,6 +84,9 @@ func (c *Config) setDefaults() {
if c.Server.Redaction == "" {
c.Server.Redaction = "Busy"
}
if c.Server.DefaultClass == "" {
c.Server.DefaultClass = "CONFIDENTIAL"
}
if c.Database.URL == "" {
c.Database.URL = "postgres://nxcaldav@localhost:5432/nxcaldav?sslmode=disable"
}