M1/#292: add Auth.AdminBootstrap config + env overrides

This commit is contained in:
2026-04-19 02:30:39 +00:00
parent 69ffc32b7d
commit 70cd49299a
+19
View File
@@ -12,6 +12,7 @@ type Config struct {
Server ServerConfig `yaml:"server"` Server ServerConfig `yaml:"server"`
Database DatabaseConfig `yaml:"database"` Database DatabaseConfig `yaml:"database"`
Log LogConfig `yaml:"log"` Log LogConfig `yaml:"log"`
Auth AuthConfig `yaml:"auth"`
} }
type ServerConfig struct { type ServerConfig struct {
@@ -27,6 +28,18 @@ type LogConfig struct {
Format string `yaml:"format"` Format string `yaml:"format"`
} }
type AuthConfig struct {
AdminBootstrap AdminBootstrapConfig `yaml:"admin_bootstrap"`
}
// AdminBootstrapConfig drives the one-shot admin creation on an empty users
// table. Username is required to enable the flow; leaving Password blank asks
// the server to generate a random one and log it to stderr.
type AdminBootstrapConfig struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
}
func Default() Config { func Default() Config {
return Config{ return Config{
Server: ServerConfig{Address: ":4533"}, Server: ServerConfig{Address: ":4533"},
@@ -64,4 +77,10 @@ func applyEnv(cfg *Config) {
if v, ok := os.LookupEnv("SMARTMUSIC_LOG_FORMAT"); ok { if v, ok := os.LookupEnv("SMARTMUSIC_LOG_FORMAT"); ok {
cfg.Log.Format = strings.ToLower(v) cfg.Log.Format = strings.ToLower(v)
} }
if v, ok := os.LookupEnv("SMARTMUSIC_AUTH_ADMIN_USERNAME"); ok {
cfg.Auth.AdminBootstrap.Username = v
}
if v, ok := os.LookupEnv("SMARTMUSIC_AUTH_ADMIN_PASSWORD"); ok {
cfg.Auth.AdminBootstrap.Password = v
}
} }