Documentation
¶
Index ¶
- Variables
- type Approval
- type ApprovalStatus
- type ApprovalStore
- func (s *ApprovalStore) ApproveApproval(id int, approvedBy, confirmation, note string) error
- func (s *ApprovalStore) Close() error
- func (s *ApprovalStore) CreateApproval(approval *Approval) (int, error)
- func (s *ApprovalStore) GetApproval(id int) (*Approval, error)
- func (s *ApprovalStore) GetPendingApprovals() ([]*Approval, error)
- func (s *ApprovalStore) RejectApproval(id int, rejectedBy, reason string) error
- type AuthConfig
- type AuthService
- func (s *AuthService) AddUser(username, password string, roles []Role) error
- func (s *AuthService) CheckAnyRole(claims *Claims, requiredRoles ...Role) error
- func (s *AuthService) CheckRole(claims *Claims, requiredRole Role) error
- func (s *AuthService) GenerateToken(user *User) (string, error)
- func (s *AuthService) GetUser(username string) (*User, error)
- func (s *AuthService) Login(username, password string) (string, error)
- func (s *AuthService) ValidateToken(tokenString string) (*Claims, error)
- type Claims
- type Config
- type ImpactAnalysis
- type OIDCConfig
- type PolicyBuilder
- func (pb *PolicyBuilder) AddRule(rule *VisualRule) error
- func (pb *PolicyBuilder) AnalyzeImpact(ruleID string, commands []string) (*ImpactAnalysis, error)
- func (pb *PolicyBuilder) ConvertToYAML() (string, error)
- func (pb *PolicyBuilder) GetRule(id string) *VisualRule
- func (pb *PolicyBuilder) ImportFromYAML(yamlContent string) error
- func (pb *PolicyBuilder) ListRules() []*VisualRule
- func (pb *PolicyBuilder) RemoveRule(id string)
- func (pb *PolicyBuilder) TestRule(ruleID string, command string) (*TestResult, error)
- type Role
- type RuleTemplate
- type Server
- type TestResult
- type User
- type VisualRule
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 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
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the web API 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 ¶
HasAnyRole checks if user has any of the specified roles
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