Documentation
¶
Index ¶
- Constants
- Variables
- func APIKeysPageHandler(appState *AppState) http.HandlerFunc
- func BatchDeleteJobsHandler(appState *AppState) http.HandlerFunc
- func CSRFProtection(secretKey []byte, sessionCookieName string) func(http.Handler) http.Handler
- func CSRFTokenFromContext(ctx context.Context) string
- func ChangePasswordHandler(appState *AppState) http.HandlerFunc
- func CreateAPIKeyHandler(appState *AppState) http.HandlerFunc
- func DashboardHandler(appState *AppState) http.HandlerFunc
- func DeleteAllFilteredJobsHandler(appState *AppState) http.HandlerFunc
- func DeleteJobHandler(appState *AppState) http.HandlerFunc
- func DeleteWorkerHandler(appState *AppState) http.HandlerFunc
- func DownloadJobResultsHandler(appState *AppState) http.HandlerFunc
- func DownloadSSHKeyHandler(appState *AppState, keyType string) http.HandlerFunc
- func JobsPageHandler(appState *AppState) http.HandlerFunc
- func LoginPageHandler(appState *AppState) http.HandlerFunc
- func LoginSubmitHandler(appState *AppState) http.HandlerFunc
- func LogoutHandler(appState *AppState) http.HandlerFunc
- func ProvisionWorkerHandler(appState *AppState) http.HandlerFunc
- func RevokeAPIKeyHandler(appState *AppState) http.HandlerFunc
- func Routes(r chi.Router, appState *AppState, riverUIHandler http.Handler)
- func SaveProviderTokenHandler(appState *AppState) http.HandlerFunc
- func SessionAuth(store IStore, cookieName string) func(http.Handler) http.Handler
- func SettingsPageHandler(appState *AppState) http.HandlerFunc
- func StaticFileHandler() http.Handler
- func TerminalPageHandler(appState *AppState) http.HandlerFunc
- func TerminalWSHandler(appState *AppState) http.HandlerFunc
- func TwoFactorDisableHandler(appState *AppState) http.HandlerFunc
- func TwoFactorPromptPageHandler(appState *AppState) http.HandlerFunc
- func TwoFactorSetupPageHandler(appState *AppState) http.HandlerFunc
- func TwoFactorSetupSubmitHandler(appState *AppState) http.HandlerFunc
- func TwoFactorVerifyPageHandler(appState *AppState) http.HandlerFunc
- func TwoFactorVerifySubmitHandler(appState *AppState) http.HandlerFunc
- func WorkersPageHandler(appState *AppState) http.HandlerFunc
- func WorkersStreamHandler(appState *AppState) http.HandlerFunc
- type APIKey
- type AppConfig
- type AppState
- type IStore
- type ProvisionedResource
- type Session
- type User
- type WorkerHealth
- type WorkerView
Constants ¶
const ( DatabaseURLKey = "database_url" RegistryProviderSettingsKey = "registry_provider_settings" HashSaltKey = "hash_salt" AppKeyPairKey = "app_key_pair" DOTokenKey = "do_api_token" HetznerTokenKey = "hetzner_api_token" )
const DefaultCookieName = "gms_session"
Variables ¶
var ( ErrUserExists = errors.New("user already exists") ErrUserNotFound = errors.New("user not found") ErrInvalidPassword = errors.New("invalid password") ErrSessionNotFound = errors.New("session not found") ErrSessionExpired = errors.New("session expired") ErrResourceNotFound = errors.New("provisioned resource not found") )
Functions ¶
func APIKeysPageHandler ¶
func APIKeysPageHandler(appState *AppState) http.HandlerFunc
APIKeysPageHandler renders the API keys management page.
func BatchDeleteJobsHandler ¶
func BatchDeleteJobsHandler(appState *AppState) http.HandlerFunc
BatchDeleteJobsHandler queues deletion for multiple jobs and redirects back to the jobs page.
func CSRFProtection ¶
CSRFProtection middleware adds CSRF token to context and validates on POST/PUT/PATCH/DELETE. For authenticated users: uses HMAC-based token derived from session ID. For unauthenticated users: uses double-submit cookie pattern.
func CSRFTokenFromContext ¶
CSRFTokenFromContext retrieves the CSRF token from context.
func ChangePasswordHandler ¶
func ChangePasswordHandler(appState *AppState) http.HandlerFunc
ChangePasswordHandler handles password change requests.
func CreateAPIKeyHandler ¶
func CreateAPIKeyHandler(appState *AppState) http.HandlerFunc
CreateAPIKeyHandler handles API key creation.
func DashboardHandler ¶
func DashboardHandler(appState *AppState) http.HandlerFunc
DashboardHandler renders the admin dashboard.
func DeleteAllFilteredJobsHandler ¶
func DeleteAllFilteredJobsHandler(appState *AppState) http.HandlerFunc
DeleteAllFilteredJobsHandler queues deletion for all jobs matching the current state filter.
func DeleteJobHandler ¶
func DeleteJobHandler(appState *AppState) http.HandlerFunc
DeleteJobHandler deletes a job and redirects back to the jobs page.
func DeleteWorkerHandler ¶
func DeleteWorkerHandler(appState *AppState) http.HandlerFunc
DeleteWorkerHandler handles worker deletion requests.
func DownloadJobResultsHandler ¶
func DownloadJobResultsHandler(appState *AppState) http.HandlerFunc
DownloadJobResultsHandler streams job results as a JSON file download.
func DownloadSSHKeyHandler ¶
func DownloadSSHKeyHandler(appState *AppState, keyType string) http.HandlerFunc
DownloadSSHKeyHandler serves the SSH private or public key as a file download.
func JobsPageHandler ¶
func JobsPageHandler(appState *AppState) http.HandlerFunc
JobsPageHandler renders the jobs list page with state filtering and cursor pagination.
func LoginPageHandler ¶
func LoginPageHandler(appState *AppState) http.HandlerFunc
LoginPageHandler renders the login page.
func LoginSubmitHandler ¶
func LoginSubmitHandler(appState *AppState) http.HandlerFunc
LoginSubmitHandler handles the login form submission.
func LogoutHandler ¶
func LogoutHandler(appState *AppState) http.HandlerFunc
LogoutHandler handles logout.
func ProvisionWorkerHandler ¶
func ProvisionWorkerHandler(appState *AppState) http.HandlerFunc
ProvisionWorkerHandler handles worker provisioning requests.
func RevokeAPIKeyHandler ¶
func RevokeAPIKeyHandler(appState *AppState) http.HandlerFunc
RevokeAPIKeyHandler handles API key revocation.
func SaveProviderTokenHandler ¶
func SaveProviderTokenHandler(appState *AppState) http.HandlerFunc
SaveProviderTokenHandler saves a cloud provider API token.
func SessionAuth ¶
SessionAuth middleware checks for valid session cookie.
func SettingsPageHandler ¶
func SettingsPageHandler(appState *AppState) http.HandlerFunc
SettingsPageHandler renders the settings page.
func StaticFileHandler ¶
StaticFileHandler returns an http.Handler for serving static files.
func TerminalPageHandler ¶
func TerminalPageHandler(appState *AppState) http.HandlerFunc
TerminalPageHandler renders the terminal page for a worker.
func TerminalWSHandler ¶
func TerminalWSHandler(appState *AppState) http.HandlerFunc
TerminalWSHandler handles the WebSocket connection for a worker terminal.
func TwoFactorDisableHandler ¶
func TwoFactorDisableHandler(appState *AppState) http.HandlerFunc
TwoFactorDisableHandler handles disabling 2FA.
func TwoFactorPromptPageHandler ¶
func TwoFactorPromptPageHandler(appState *AppState) http.HandlerFunc
TwoFactorPromptPageHandler renders the 2FA prompt page for users without 2FA enabled.
func TwoFactorSetupPageHandler ¶
func TwoFactorSetupPageHandler(appState *AppState) http.HandlerFunc
TwoFactorSetupPageHandler renders the 2FA setup page.
func TwoFactorSetupSubmitHandler ¶
func TwoFactorSetupSubmitHandler(appState *AppState) http.HandlerFunc
TwoFactorSetupSubmitHandler handles enabling 2FA after verification.
func TwoFactorVerifyPageHandler ¶
func TwoFactorVerifyPageHandler(appState *AppState) http.HandlerFunc
TwoFactorVerifyPageHandler renders the 2FA verification page during login.
func TwoFactorVerifySubmitHandler ¶
func TwoFactorVerifySubmitHandler(appState *AppState) http.HandlerFunc
TwoFactorVerifySubmitHandler handles 2FA code verification during login.
func WorkersPageHandler ¶
func WorkersPageHandler(appState *AppState) http.HandlerFunc
WorkersPageHandler renders the workers management page.
func WorkersStreamHandler ¶
func WorkersStreamHandler(appState *AppState) http.HandlerFunc
WorkersStreamHandler streams worker data via Server-Sent Events.
Types ¶
type APIKey ¶
type APIKey struct {
ID int
UserID int
Name string
KeyPrefix string
CreatedAt time.Time
LastUsedAt *time.Time
RevokedAt *time.Time
}
APIKey represents an API key.
type AppState ¶
type IStore ¶
type IStore interface {
// Config
GetConfig(ctx context.Context, key string) (*AppConfig, error)
SetConfig(ctx context.Context, cfg *AppConfig, encrypt bool) error
DeleteConfig(ctx context.Context, key string) error
// Users
CreateUser(ctx context.Context, username, password string) (*User, error)
GetUser(ctx context.Context, username string) (*User, error)
GetUserByID(ctx context.Context, id int) (*User, error)
UpdatePassword(ctx context.Context, username, password string) error
// TOTP
GetTOTPSecret(ctx context.Context, userID int) (string, error)
SetTOTPSecret(ctx context.Context, userID int, secret string) error
EnableTOTP(ctx context.Context, userID int) error
DisableTOTP(ctx context.Context, userID int) error
SetBackupCodes(ctx context.Context, userID int, hashedCodes string) error
ValidateBackupCode(ctx context.Context, userID int, code string) (bool, error)
// Sessions
CreateSession(ctx context.Context, userID int, ipAddress, userAgent string, duration time.Duration) (*Session, error)
GetSession(ctx context.Context, sessionID string) (*Session, error)
DeleteSession(ctx context.Context, sessionID string) error
DeleteUserSessionsExcept(ctx context.Context, userID int, exceptSessionID string) error
CleanupExpiredSessions(ctx context.Context) (int64, error)
// API Keys
CreateAPIKey(ctx context.Context, userID int, name, keyHash, keyPrefix string) (*APIKey, error)
ListAPIKeys(ctx context.Context, userID int) ([]APIKey, error)
RevokeAPIKey(ctx context.Context, userID int, keyID int) error
// Provisioned Resources
CreateProvisionedResource(ctx context.Context, res *ProvisionedResource) (*ProvisionedResource, error)
GetProvisionedResource(ctx context.Context, id int) (*ProvisionedResource, error)
ListProvisionedResources(ctx context.Context, provider string) ([]ProvisionedResource, error)
UpdateProvisionedResourceStatus(ctx context.Context, id int, status, ipAddress string) error
SoftDeleteProvisionedResource(ctx context.Context, id int) error
}
type ProvisionedResource ¶
type ProvisionedResource struct {
ID int
Provider string
ResourceType string
ResourceID string
Name string
Region string
Size string
Status string
IPAddress string
Metadata map[string]any
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
}
ProvisionedResource represents a cloud resource (e.g. a DigitalOcean droplet).
type Session ¶
type Session struct {
ID string
UserID int
CreatedAt time.Time
ExpiresAt time.Time
IPAddress string
UserAgent string
}
Session represents an admin session.
func SessionFromContext ¶
SessionFromContext retrieves the session from context.
type User ¶
type User struct {
ID int
Username string
PasswordHash string
TOTPSecret *string
TOTPEnabled bool
BackupCodesHash *string
CreatedAt time.Time
UpdatedAt time.Time
}
User represents an admin user.
type WorkerHealth ¶
type WorkerHealth struct {
Reachable bool `json:"reachable"`
Status string `json:"status"`
Uptime string `json:"uptime"`
JobsProcessed int64 `json:"jobs_processed"`
ResultsCollected int64 `json:"results_collected"`
ResultsPerMinute float64 `json:"results_per_minute"`
Concurrency int `json:"concurrency"`
CheckedAt string `json:"checked_at"`
}
WorkerHealth holds the cached health check result for a worker.
type WorkerView ¶
type WorkerView struct {
ProvisionedResource
Health *WorkerHealth
SSHCmd string
ErrorMessage string
}
WorkerView extends ProvisionedResource with health info, SSH command, and error details for the template.