47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
package config
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
DBPath string
|
|
FirebaseKeyPath string
|
|
PairingCode string
|
|
FrigateURL string
|
|
FrigateUser string
|
|
FrigatePassword string
|
|
}
|
|
|
|
func Load() (*Config, error) {
|
|
c := &Config{
|
|
Port: getenv("RELAY_PORT", "8080"),
|
|
DBPath: getenv("RELAY_DB_PATH", "/data/relay.db"),
|
|
FirebaseKeyPath: os.Getenv("RELAY_FIREBASE_KEY_PATH"),
|
|
PairingCode: os.Getenv("RELAY_PAIRING_CODE"),
|
|
FrigateURL: os.Getenv("FRIGATE_URL"),
|
|
FrigateUser: os.Getenv("FRIGATE_USER"),
|
|
FrigatePassword: os.Getenv("FRIGATE_PASSWORD"),
|
|
}
|
|
if c.FirebaseKeyPath == "" {
|
|
return nil, errors.New("RELAY_FIREBASE_KEY_PATH is required")
|
|
}
|
|
if c.PairingCode == "" || len(c.PairingCode) < 6 {
|
|
return nil, errors.New("RELAY_PAIRING_CODE must be at least 6 chars (use: openssl rand -hex 3)")
|
|
}
|
|
if c.FrigateURL == "" {
|
|
return nil, errors.New("FRIGATE_URL is required (e.g. http://localhost:5000)")
|
|
}
|
|
// FRIGATE_USER + FRIGATE_PASSWORD optional — empty means Frigate has auth disabled.
|
|
return c, nil
|
|
}
|
|
|
|
func getenv(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|