web

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package web provides HTTP handlers for the web UI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuditTemplateFuncs added in v0.18.0

func AuditTemplateFuncs() map[string]any

AuditTemplateFuncs returns template functions for audit templates.

func StaticFS

func StaticFS() (fs.FS, error)

StaticFS returns the embedded static filesystem for external use.

Types

type AuditHandler added in v0.18.0

type AuditHandler struct {
	// contains filtered or unexported fields
}

AuditHandler handles audit log web UI requests.

func NewAuditHandler added in v0.18.0

func NewAuditHandler(auditStore AuditStore, auth AuthProvider, h *Handler) *AuditHandler

NewAuditHandler creates a new audit handler.

func (*AuditHandler) HandleAuditPage added in v0.18.0

func (h *AuditHandler) HandleAuditPage(w http.ResponseWriter, r *http.Request)

HandleAuditPage handles GET /audit - renders full audit page.

func (*AuditHandler) HandleAuditTable added in v0.18.0

func (h *AuditHandler) HandleAuditTable(w http.ResponseWriter, r *http.Request)

HandleAuditTable handles GET /web/audit - returns audit table partial for HTMX.

type AuditLogger added in v0.18.0

type AuditLogger interface {
	LogAudit(ctx context.Context, entry store.AuditEntry) error
}

AuditLogger defines the interface for audit log storage.

type AuditStore added in v0.18.0

type AuditStore interface {
	QueryAudit(ctx context.Context, q store.AuditQuery) ([]store.AuditEntry, int, error)
}

AuditStore defines the interface for audit log queries.

type AuthProvider

type AuthProvider interface {
	Enabled() bool
	GetSessionUser(ctx context.Context, token string) (string, bool)
	FilterUserKeys(username string, keys []string) []string
	CheckUserPermission(username, key string, write bool) bool
	UserCanWrite(username string) bool
	IsAdmin(username string) bool

	IsValidUser(username, password string) bool
	CreateSession(ctx context.Context, username string) (string, error)
	InvalidateSession(ctx context.Context, token string)
	LoginTTL() time.Duration
}

AuthProvider defines the interface for authentication operations.

type Config

type Config struct {
	BaseURL      string
	PageSize     int
	AuditEnabled bool
}

Config holds web handler configuration.

type Deps added in v0.19.0

type Deps struct {
	Store     KVStore
	Auth      AuthProvider
	Validator Validator
	Git       GitService     // optional
	Audit     AuditLogger    // optional
	Events    EventPublisher // optional
}

Deps holds dependencies for the web handler.

type EventPublisher added in v0.19.0

type EventPublisher interface {
	Publish(key string, action enum.AuditAction)
}

EventPublisher defines the interface for publishing key change events.

type GitService

type GitService interface {
	Commit(req git.CommitRequest) error
	Delete(key string, author git.Author) error
	History(key string, limit int) ([]git.HistoryEntry, error)
	GetRevision(key string, rev string) ([]byte, string, error)
}

GitService defines the interface for git operations.

type Handler

type Handler struct {
	Deps
	Config
	// contains filtered or unexported fields
}

Handler handles web UI requests.

func New

func New(deps Deps, cfg Config) (*Handler, error)

New creates a new web handler.

func (*Handler) Register

func (h *Handler) Register(r *routegroup.Bundle)

Register registers web UI routes on the given router.

func (*Handler) RegisterAuth

func (h *Handler) RegisterAuth(r *routegroup.Bundle)

RegisterAuth registers auth routes (login/logout) on the given router.

func (*Handler) RegisterLogin

func (h *Handler) RegisterLogin(r *routegroup.Bundle, middleware func(http.Handler) http.Handler)

RegisterLogin registers the login POST handler with custom middleware.

type Highlighter

type Highlighter struct{}

Highlighter provides syntax highlighting for code.

func NewHighlighter

func NewHighlighter() *Highlighter

NewHighlighter creates a new Highlighter instance.

func (*Highlighter) Code

func (h *Highlighter) Code(code, format string) template.HTML

Code applies syntax highlighting to code based on format. returns HTML-safe highlighted code or plain escaped text if format is "text" or highlighting fails.

type KVStore

type KVStore interface {
	GetWithFormat(ctx context.Context, key string) ([]byte, string, error)
	GetInfo(ctx context.Context, key string) (store.KeyInfo, error)
	Set(ctx context.Context, key string, value []byte, format string) (created bool, err error)
	SetWithVersion(ctx context.Context, key string, value []byte, format string, expectedVersion time.Time) error
	Delete(ctx context.Context, key string) error
	List(ctx context.Context, filter enum.SecretsFilter) ([]store.KeyInfo, error)
	SecretsEnabled() bool
}

KVStore defines the interface for key-value storage operations.

type Validator

type Validator interface {
	Validate(format string, value []byte) error
	IsValidFormat(format string) bool
	SupportedFormats() []string
}

Validator defines the interface for format validation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL