Documentation
¶
Overview ¶
Package management provides management API capabilities with optional authentication for the CBT engine.
Index ¶
- Variables
- func CombinedAuthMiddleware(expectedPassword string, store *SessionStore) fiber.Handler
- func PasswordAuthMiddleware(expectedPassword string) fiber.Handler
- func SessionAuthMiddleware(store *SessionStore) fiber.Handler
- type AuthConfig
- type BaseConfigProvider
- type Config
- type FrontendConfig
- type GitHubConfig
- type GitHubHandler
- type Handlers
- func (h *Handlers) ClearAllConfigOverrides(c fiber.Ctx) error
- func (h *Handlers) Consolidate(c fiber.Ctx) error
- func (h *Handlers) DeleteBounds(c fiber.Ctx) error
- func (h *Handlers) DeleteConfigOverride(c fiber.Ctx) error
- func (h *Handlers) DeletePeriod(c fiber.Ctx) error
- func (h *Handlers) GetConfigOverride(c fiber.Ctx) error
- func (h *Handlers) ListConfigOverrides(c fiber.Ctx) error
- func (h *Handlers) SetBaseConfigProvider(p BaseConfigProvider)
- func (h *Handlers) SetConfigOverride(c fiber.Ctx) error
- func (h *Handlers) TriggerRefreshBounds(c fiber.Ctx) error
- func (h *Handlers) TriggerScheduledRun(c fiber.Ctx) error
- func (h *Handlers) UpdateBounds(c fiber.Ctx) error
- type Service
- type SessionData
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
var ( // ErrGitHubClientIDRequired is returned when GitHub OAuth is configured // without a client ID. ErrGitHubClientIDRequired = errors.New("github client_id is required") // ErrGitHubClientSecretRequired is returned when GitHub OAuth is // configured without a client secret. ErrGitHubClientSecretRequired = errors.New( "github client_secret is required", ) // ErrGitHubCallbackURLRequired is returned when GitHub OAuth is // configured without a callback URL. ErrGitHubCallbackURLRequired = errors.New( "github callback_url is required", ) // ErrGitHubAuthorizationRequired is returned when GitHub OAuth is // configured without org or allowed_users. ErrGitHubAuthorizationRequired = errors.New( "github requires at least one of org or allowed_users", ) )
var ( // ErrEmptyGitHubLogin is returned when the GitHub API returns an empty login. ErrEmptyGitHubLogin = errors.New("empty login in GitHub API response") // ErrUserNotAuthorized is returned when a user is not in the allowed // list or org. ErrUserNotAuthorized = errors.New("user is not authorized") // ErrUnexpectedGitHubStatus is returned when the GitHub API returns an // unexpected status code. ErrUnexpectedGitHubStatus = errors.New("unexpected GitHub API status") )
Functions ¶
func CombinedAuthMiddleware ¶
func CombinedAuthMiddleware( expectedPassword string, store *SessionStore, ) fiber.Handler
CombinedAuthMiddleware returns middleware that accepts either Bearer token or session cookie authentication. It tries password first, then session.
func PasswordAuthMiddleware ¶
PasswordAuthMiddleware returns middleware that validates a Bearer token against the expected password using constant-time comparison.
func SessionAuthMiddleware ¶
func SessionAuthMiddleware(store *SessionStore) fiber.Handler
SessionAuthMiddleware returns middleware that validates a session cookie against the Redis session store.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
// Password is a simple bearer token. Empty means disabled.
Password string `yaml:"password"` //nolint:gosec // configuration field name is intentional.
// GitHub holds GitHub OAuth configuration. Nil means disabled.
GitHub *GitHubConfig `yaml:"github"`
}
AuthConfig holds authentication configuration for the management API.
func (*AuthConfig) AuthRequired ¶
func (c *AuthConfig) AuthRequired() bool
AuthRequired reports whether any authentication method is configured.
func (*AuthConfig) GitHubEnabled ¶
func (c *AuthConfig) GitHubEnabled() bool
GitHubEnabled reports whether GitHub OAuth authentication is configured.
func (*AuthConfig) Methods ¶
func (c *AuthConfig) Methods() []string
Methods returns the list of enabled authentication method names.
func (*AuthConfig) PasswordEnabled ¶
func (c *AuthConfig) PasswordEnabled() bool
PasswordEnabled reports whether password authentication is configured.
func (*AuthConfig) Validate ¶
func (c *AuthConfig) Validate() error
Validate validates the authentication configuration.
type BaseConfigProvider ¶
type BaseConfigProvider interface {
GetBaseConfig(modelID string) (json.RawMessage, error)
}
BaseConfigProvider returns original (pre-override) config for a model.
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled"`
Auth AuthConfig `yaml:"auth"`
}
Config represents the management API configuration.
type FrontendConfig ¶
type FrontendConfig struct {
ManagementEnabled bool `json:"managementEnabled"`
AuthMethods []string `json:"authMethods"`
}
FrontendConfig holds configuration injected into the frontend.
type GitHubConfig ¶
type GitHubConfig struct {
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"` //nolint:gosec // configuration field name is intentional.
CallbackURL string `yaml:"callback_url"`
Org string `yaml:"org"`
AllowedUsers []string `yaml:"allowed_users"`
SessionTTL time.Duration `yaml:"session_ttl"`
}
GitHubConfig holds GitHub OAuth flow configuration.
func (*GitHubConfig) Validate ¶
func (c *GitHubConfig) Validate() error
Validate validates the GitHub OAuth configuration.
type GitHubHandler ¶
type GitHubHandler struct {
// contains filtered or unexported fields
}
GitHubHandler manages the GitHub OAuth login flow.
func NewGitHubHandler ¶
func NewGitHubHandler( cfg *GitHubConfig, redisClient *redis.Client, sessionStore *SessionStore, log logrus.FieldLogger, ) *GitHubHandler
NewGitHubHandler creates a new GitHub OAuth handler.
func (*GitHubHandler) HandleCallback ¶
func (h *GitHubHandler) HandleCallback(c fiber.Ctx) error
HandleCallback processes the GitHub OAuth callback, exchanges the code for a token, validates the user, creates a session, and redirects to the root.
func (*GitHubHandler) HandleLogin ¶
func (h *GitHubHandler) HandleLogin(c fiber.Ctx) error
HandleLogin initiates the GitHub OAuth flow by generating CSRF state and PKCE verifier, storing them in Redis, and redirecting to GitHub.
func (*GitHubHandler) HandleLogout ¶
func (h *GitHubHandler) HandleLogout(c fiber.Ctx) error
HandleLogout deletes the session and clears the cookie.
type Handlers ¶
type Handlers struct {
// contains filtered or unexported fields
}
Handlers implements management action endpoints.
func NewHandlers ¶
func NewHandlers( adminService admin.Service, modelsService models.Service, coord coordinator.Service, log logrus.FieldLogger, ) *Handlers
NewHandlers creates a new management Handlers instance.
func (*Handlers) ClearAllConfigOverrides ¶
ClearAllConfigOverrides removes all live overrides.
func (*Handlers) Consolidate ¶
Consolidate triggers historical data consolidation for a model.
func (*Handlers) DeleteBounds ¶
DeleteBounds removes external model bounds from Redis cache.
func (*Handlers) DeleteConfigOverride ¶
DeleteConfigOverride removes the live override for a model (reverts to base config).
func (*Handlers) DeletePeriod ¶
DeletePeriod removes tracking rows overlapping a position range and optionally cascades the deletion to all transitive incremental dependents.
func (*Handlers) GetConfigOverride ¶
GetConfigOverride returns the live override for a specific model, along with the original base config snapshot for comparison.
func (*Handlers) ListConfigOverrides ¶
ListConfigOverrides returns all live overrides.
func (*Handlers) SetBaseConfigProvider ¶
func (h *Handlers) SetBaseConfigProvider(p BaseConfigProvider)
SetBaseConfigProvider sets the provider used to retrieve original config snapshots.
func (*Handlers) SetConfigOverride ¶
SetConfigOverride creates or updates a live override for a model.
func (*Handlers) TriggerRefreshBounds ¶
TriggerRefreshBounds enqueues a full external scan via the coordinator.
func (*Handlers) TriggerScheduledRun ¶
TriggerScheduledRun enqueues an immediate run for a scheduled transformation.
type Service ¶
type Service interface {
// RegisterRoutes registers management routes on the given router.
RegisterRoutes(router fiber.Router)
// GetFrontendConfig returns the configuration to inject into the frontend.
GetFrontendConfig() FrontendConfig
// SetBaseConfigProvider sets the provider for original config snapshots.
SetBaseConfigProvider(p BaseConfigProvider)
}
Service defines the management service interface.
func NewService ¶
func NewService( cfg *Config, adminService admin.Service, modelsService models.Service, coord coordinator.Service, redisClient *redis.Client, log logrus.FieldLogger, ) Service
NewService creates a new management Service.
type SessionData ¶
type SessionData struct {
Username string `json:"username"`
AuthMode string `json:"auth_mode"`
CreatedAt int64 `json:"created_at"`
}
SessionData holds the data associated with an authenticated session.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore manages sessions backed by Redis.
func NewSessionStore ¶
func NewSessionStore(client *redis.Client, ttl time.Duration) *SessionStore
NewSessionStore creates a new Redis-backed session store.
func (*SessionStore) Create ¶
func (s *SessionStore) Create( ctx context.Context, data *SessionData, ) (string, error)
Create generates a new session ID, stores the data in Redis, and returns the session ID.
func (*SessionStore) Delete ¶
func (s *SessionStore) Delete(ctx context.Context, id string) error
Delete removes a session from Redis.
func (*SessionStore) Get ¶
func (s *SessionStore) Get( ctx context.Context, id string, ) (*SessionData, error)
Get retrieves session data for the given session ID. Returns nil if the session does not exist or has expired.