Refactor configuration system with centralized type-safe config package

- Create internal/config package with unified config structs and validation
- Abstract viper dependency behind config.Loader interface for better testability
- Replace manual config parsing and type assertions with type-safe loading
- Consolidate AuthConfig, SiteConfig, and DiscoveryConfig into single package
- Add comprehensive validation with clear error messages
- Remove ~200 lines of duplicate config handling code
- Maintain backward compatibility with existing config files
This commit is contained in:
2025-10-08 17:58:03 +02:00
parent 2959ecedf9
commit 38c2897ece
11 changed files with 550 additions and 332 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/coreos/go-oidc/v3/oidc"
"github.com/golang-jwt/jwt/v5"
"github.com/insertr/insertr/internal/config"
"golang.org/x/oauth2"
)
@@ -24,31 +25,10 @@ type UserInfo struct {
Provider string `json:"iss,omitempty"`
}
// AuthConfig holds authentication configuration
type AuthConfig struct {
DevMode bool
Provider string
JWTSecret string
OAuthConfigs map[string]OAuthConfig
OIDC *OIDCConfig
}
// OAuthConfig holds OAuth provider configuration
type OAuthConfig struct {
ClientID string
ClientSecret string
RedirectURL string
Scopes []string
}
// OIDCConfig holds OIDC configuration for Authentik
type OIDCConfig struct {
Endpoint string
ClientID string
ClientSecret string
RedirectURL string
Scopes []string
}
// Type aliases for backward compatibility
type AuthConfig = config.AuthConfig
type OAuthConfig = config.OAuthConfig
type OIDCConfig = config.OIDCConfig
// AuthService handles authentication operations
type AuthService struct {