web

package
v0.0.0-...-8198c06 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrInvalidToken       = errors.New("invalid token")
	ErrTokenExpired       = errors.New("token expired")
	ErrInsufficientRole   = errors.New("insufficient role")
	ErrUserNotFound       = errors.New("user not found")
)

Errors

Functions

This section is empty.

Types

type Approval

type Approval struct {
	ID              int                    `json:"id"`
	RunID           int                    `json:"run_id"`
	Prompt          string                 `json:"prompt"`
	Command         string                 `json:"command"`
	RiskLevel       string                 `json:"risk_level"`
	RequiredScopes  []string               `json:"required_scopes"`
	PluginMetadata  map[string]interface{} `json:"plugin_metadata"`
	RequestedBy     string                 `json:"requested_by"`
	RequestedAt     time.Time              `json:"requested_at"`
	Status          ApprovalStatus         `json:"status"`
	ApprovedBy      string                 `json:"approved_by,omitempty"`
	ApprovedAt      *time.Time             `json:"approved_at,omitempty"`
	RejectedBy      string                 `json:"rejected_by,omitempty"`
	RejectedAt      *time.Time             `json:"rejected_at,omitempty"`
	RejectionReason string                 `json:"rejection_reason,omitempty"`
	Confirmation    string                 `json:"confirmation,omitempty"`
	ApprovalNote    string                 `json:"approval_note,omitempty"`
}

Approval represents a pending approval for a job

type ApprovalStatus

type ApprovalStatus string

ApprovalStatus represents the status of an approval

const (
	ApprovalStatusPending  ApprovalStatus = "pending"
	ApprovalStatusApproved ApprovalStatus = "approved"
	ApprovalStatusRejected ApprovalStatus = "rejected"
)

type ApprovalStore

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

ApprovalStore manages approval records

func NewApprovalStore

func NewApprovalStore(dbPath string) (*ApprovalStore, error)

NewApprovalStore creates a new approval store

func (*ApprovalStore) ApproveApproval

func (s *ApprovalStore) ApproveApproval(id int, approvedBy, confirmation, note string) error

ApproveApproval approves a pending approval

func (*ApprovalStore) Close

func (s *ApprovalStore) Close() error

Close closes the database connection

func (*ApprovalStore) CreateApproval

func (s *ApprovalStore) CreateApproval(approval *Approval) (int, error)

CreateApproval creates a new pending approval

func (*ApprovalStore) GetApproval

func (s *ApprovalStore) GetApproval(id int) (*Approval, error)

GetApproval retrieves an approval by ID

func (*ApprovalStore) GetPendingApprovals

func (s *ApprovalStore) GetPendingApprovals() ([]*Approval, error)

GetPendingApprovals retrieves all pending approvals

func (*ApprovalStore) RejectApproval

func (s *ApprovalStore) RejectApproval(id int, rejectedBy, reason string) error

RejectApproval rejects a pending approval

type AuthConfig

type AuthConfig struct {
	JWTSecret     string
	TokenDuration time.Duration
	DevMode       bool
	OIDCEnabled   bool
	OIDCConfig    *OIDCConfig
}

AuthConfig represents authentication configuration

func DefaultAuthConfig

func DefaultAuthConfig() *AuthConfig

DefaultAuthConfig returns default auth configuration

type AuthService

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

AuthService handles authentication and authorization

func NewAuthService

func NewAuthService(config *AuthConfig) *AuthService

NewAuthService creates a new auth service

func (*AuthService) AddUser

func (s *AuthService) AddUser(username, password string, roles []Role) error

AddUser adds a new user (dev mode only)

func (*AuthService) CheckAnyRole

func (s *AuthService) CheckAnyRole(claims *Claims, requiredRoles ...Role) error

CheckAnyRole verifies if a user has any of the specified roles

func (*AuthService) CheckRole

func (s *AuthService) CheckRole(claims *Claims, requiredRole Role) error

CheckRole verifies if a user has a specific role

func (*AuthService) GenerateToken

func (s *AuthService) GenerateToken(user *User) (string, error)

GenerateToken generates a JWT token for a user

func (*AuthService) GetUser

func (s *AuthService) GetUser(username string) (*User, error)

GetUser retrieves a user by username

func (*AuthService) Login

func (s *AuthService) Login(username, password string) (string, error)

Login authenticates a user and returns a JWT token

func (*AuthService) ValidateToken

func (s *AuthService) ValidateToken(tokenString string) (*Claims, error)

ValidateToken validates a JWT token and returns the claims

type Claims

type Claims struct {
	UserID   string `json:"user_id"`
	Username string `json:"username"`
	Roles    []Role `json:"roles"`
	jwt.RegisteredClaims
}

Claims represents JWT claims

type Config

type Config struct {
	Port           int
	AuthConfig     *AuthConfig
	AuditDBPath    string
	ApprovalDBPath string
	CORSOrigins    []string
}

Config represents server configuration

type ImpactAnalysis

type ImpactAnalysis struct {
	RuleID          string   `json:"rule_id"`
	TotalCommands   int      `json:"total_commands"`
	MatchedCount    int      `json:"matched_count"`
	BlockedCount    int      `json:"blocked_count"`
	ApprovalCount   int      `json:"approval_count"`
	MatchedExamples []string `json:"matched_examples"`
}

ImpactAnalysis analyzes the impact of a rule on historical commands

type OIDCConfig

type OIDCConfig struct {
	Issuer       string
	ClientID     string
	ClientSecret string
	RedirectURL  string
}

OIDCConfig represents OIDC configuration (placeholder for future)

type PolicyBuilder

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

PolicyBuilder helps build and test policy rules visually

func NewPolicyBuilder

func NewPolicyBuilder() *PolicyBuilder

NewPolicyBuilder creates a new policy builder

func (*PolicyBuilder) AddRule

func (pb *PolicyBuilder) AddRule(rule *VisualRule) error

AddRule adds a new visual rule

func (*PolicyBuilder) AnalyzeImpact

func (pb *PolicyBuilder) AnalyzeImpact(ruleID string, commands []string) (*ImpactAnalysis, error)

AnalyzeImpact analyzes how a rule would affect commands

func (*PolicyBuilder) ConvertToYAML

func (pb *PolicyBuilder) ConvertToYAML() (string, error)

ConvertToYAML converts visual rules to policy YAML

func (*PolicyBuilder) GetRule

func (pb *PolicyBuilder) GetRule(id string) *VisualRule

GetRule gets a rule by ID

func (*PolicyBuilder) ImportFromYAML

func (pb *PolicyBuilder) ImportFromYAML(yamlContent string) error

ImportFromYAML imports rules from policy YAML

func (*PolicyBuilder) ListRules

func (pb *PolicyBuilder) ListRules() []*VisualRule

ListRules returns all rules

func (*PolicyBuilder) RemoveRule

func (pb *PolicyBuilder) RemoveRule(id string)

RemoveRule removes a rule by ID

func (*PolicyBuilder) TestRule

func (pb *PolicyBuilder) TestRule(ruleID string, command string) (*TestResult, error)

TestRule tests a rule against a command

type Role

type Role string

Role represents a user role

const (
	RoleViewer   Role = "viewer"
	RoleOperator Role = "operator"
	RoleApprover Role = "approver"
	RoleAdmin    Role = "admin"
)

type RuleTemplate

type RuleTemplate struct {
	Name        string       `json:"name"`
	Description string       `json:"description"`
	Category    string       `json:"category"`
	Rules       []VisualRule `json:"rules"`
}

RuleTemplate represents a pre-built rule template

func GetTemplates

func GetTemplates() []RuleTemplate

GetTemplates returns common rule templates

type Server

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

Server represents the web API server

func NewServer

func NewServer(config *Config) (*Server, error)

NewServer creates a new web server

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTP server

type TestResult

type TestResult struct {
	RuleID  string `json:"rule_id"`
	Command string `json:"command"`
	Matched bool   `json:"matched"`
	Action  string `json:"action"`
	Message string `json:"message"`
}

TestResult represents the result of testing a rule

type User

type User struct {
	ID       string    `json:"id"`
	Username string    `json:"username"`
	Password string    `json:"-"` // Never expose password
	Roles    []Role    `json:"roles"`
	Email    string    `json:"email,omitempty"`
	Created  time.Time `json:"created"`
}

User represents a user in the system

func (*User) HasAnyRole

func (u *User) HasAnyRole(roles ...Role) bool

HasAnyRole checks if user has any of the specified roles

func (*User) HasRole

func (u *User) HasRole(role Role) bool

HasRole checks if user has a specific role

type VisualRule

type VisualRule struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	RuleType    string   `json:"rule_type"` // "allowlist", "denylist", "approval"
	Pattern     string   `json:"pattern"`
	IsRegex     bool     `json:"is_regex"`
	Action      string   `json:"action"`     // "allow", "block", "approve"
	AppliesTo   []string `json:"applies_to"` // roles
	Priority    int      `json:"priority"`
	Enabled     bool     `json:"enabled"`
	Examples    []string `json:"examples,omitempty"`
}

VisualRule represents a policy rule in a visual/form-friendly format

func (*VisualRule) ToJSON

func (vr *VisualRule) ToJSON() (string, error)

ToJSON converts visual rule to JSON

Jump to

Keyboard shortcuts

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