go-tell/internal/config/config.go

59 lines
2.1 KiB
Go
Raw Normal View History

2026-10-03 04:41:31 +02:00
// Package config carries the runtime settings for the CMS. There is no
2026-09-19 17:33:44 +02:00
// database to configure: content is seeded in memory and optionally mirrored to
2026-10-03 04:41:31 +02:00
// a single JSON file. Editing rights come from Go Loose, from the single-sign-on
// proxy, or from the demo profile, depending on what is configured.
package config
2026-09-19 17:33:44 +02:00
import "os"
type Config struct {
2026-09-19 17:33:44 +02:00
HTTPAddr, Profile, ContentFile, PostgresURL string
2026-09-19 16:45:24 +02:00
AllowedOrigins, SSOHeader, SSOToken, SSOCookie string
2026-10-03 04:41:31 +02:00
GoLoose GoLooseConfig
}
2026-10-03 04:41:31 +02:00
// GoLooseConfig describes the Go Loose hosted-login integration. Go Tell is
// served from a single host, so one client application covers every request:
// Tenant picks the Go Loose tenant that owns the login, AuthDomain is the
// identity domain shared by all tenants, and AppDomain is the public host of
// the CMS, which also determines the registered redirect URI.
type GoLooseConfig struct {
Tenant string
AuthDomain string
AppDomain string
CAFile string
ClientID string
ClientSecret string
}
// Enabled reports whether Go Loose client credentials are configured.
func (g GoLooseConfig) Enabled() bool { return g.ClientID != "" && g.ClientSecret != "" }
2026-09-19 16:45:24 +02:00
func Load() Config {
2026-09-19 14:48:42 +02:00
return Config{
2026-09-19 17:33:44 +02:00
HTTPAddr: get("CMS_HTTP_ADDR", ":8080"),
Profile: get("CMS_PROFILE", "demo"),
ContentFile: get("CMS_CONTENT_FILE", ""),
PostgresURL: get("CMS_POSTGRES_URL", ""),
AllowedOrigins: get("CMS_ALLOWED_ORIGINS", "http://localhost:5173"),
SSOHeader: get("CMS_SSO_HEADER", "X-SSO-Token"),
SSOToken: get("CMS_SSO_TOKEN", ""),
SSOCookie: get("CMS_SSO_COOKIE", ""),
2026-10-03 04:41:31 +02:00
GoLoose: GoLooseConfig{
Tenant: get("GO_LOOSE_TENANT", "tell"),
AuthDomain: get("GO_LOOSE_AUTH_DOMAIN", "auth.dev"),
AppDomain: get("GO_LOOSE_APP_DOMAIN", "tell.dev"),
CAFile: os.Getenv("GO_LOOSE_CA_FILE"),
ClientID: os.Getenv("GO_LOOSE_CLIENT_ID"),
ClientSecret: os.Getenv("GO_LOOSE_CLIENT_SECRET"),
},
2026-09-19 14:48:42 +02:00
}
}
2026-09-19 16:45:24 +02:00
func get(k, d string) string {
if v := os.Getenv(k); v != "" {
return v
}
return d
}