api

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package api provides a RESTful API for the access control system

Package api provides a RESTful API for the access control system

Package api provides a RESTful API for the access control system

Package api provides a RESTful API for the access control system

Package api provides a RESTful API for the access control system

Package api provides a RESTful API for the access control system

Package api provides a RESTful API for the access control system

Package api provides a RESTful API for the access control system

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, statusCode int, message string)

WriteErrorResponse writes an error response to the HTTP response writer

func WriteJSON

func WriteJSON(w http.ResponseWriter, statusCode int, data interface{})

WriteJSON writes a JSON response to the HTTP response writer

func WriteSuccessResponse

func WriteSuccessResponse(w http.ResponseWriter, statusCode int, message string, data interface{})

WriteSuccessResponse writes a success response to the HTTP response writer

Types

type APIConfig

type APIConfig struct {
	// Port is the port to listen on
	Port int

	// BasePath is the base path for all API endpoints
	BasePath string

	// EnableCORS enables Cross-Origin Resource Sharing
	EnableCORS bool

	// AllowedOrigins is a list of allowed origins for CORS
	AllowedOrigins []string

	// EnableRateLimit enables rate limiting
	EnableRateLimit bool

	// RateLimitPerMinute is the number of requests allowed per minute per IP
	RateLimitPerMinute int

	// EnableRequestLogging enables logging of all API requests
	EnableRequestLogging bool
}

APIConfig contains configuration for the API server

func DefaultAPIConfig

func DefaultAPIConfig() *APIConfig

DefaultAPIConfig returns a default API configuration

type AddPermissionRequest

type AddPermissionRequest struct {
	Permission string `json:"permission"`
}

AddPermissionRequest represents a request to add a permission to a role

type AuditLogResponse

type AuditLogResponse struct {
	ID         string                 `json:"id"`
	Timestamp  string                 `json:"timestamp"`
	UserID     string                 `json:"user_id,omitempty"`
	Username   string                 `json:"username,omitempty"`
	Action     string                 `json:"action"`
	Resource   string                 `json:"resource,omitempty"`
	ResourceID string                 `json:"resource_id,omitempty"`
	Severity   string                 `json:"severity"`
	Status     string                 `json:"status"`
	IPAddress  string                 `json:"ip_address,omitempty"`
	UserAgent  string                 `json:"user_agent,omitempty"`
	Details    map[string]interface{} `json:"details,omitempty"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
}

AuditLogResponse represents an audit log entry in the response

type AuthMiddleware

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

AuthMiddleware handles authentication for API requests

func NewAuthMiddleware

func NewAuthMiddleware(accessManager access.AccessControlManager) *AuthMiddleware

NewAuthMiddleware creates a new authentication middleware

func (*AuthMiddleware) Middleware

func (m *AuthMiddleware) Middleware(next http.Handler) http.Handler

Middleware is the HTTP middleware function for authentication

type CreateIncidentRequest

type CreateIncidentRequest struct {
	Title       string                 `json:"title"`
	Description string                 `json:"description"`
	Severity    string                 `json:"severity"`
	AuditLogIDs []string               `json:"audit_log_ids,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

CreateIncidentRequest represents a request to create a new security incident

type CreateRoleRequest

type CreateRoleRequest struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Permissions []string `json:"permissions"`
	ParentRoles []string `json:"parent_roles,omitempty"`
}

CreateRoleRequest represents a request to create a new role

type CreateUserRequest

type CreateUserRequest struct {
	Username    string                 `json:"username"`
	Email       string                 `json:"email"`
	Password    string                 `json:"password"`
	Roles       []string               `json:"roles"`
	MFAEnabled  bool                   `json:"mfa_enabled"`
	MFAMethods  []string               `json:"mfa_methods,omitempty"`
	Permissions []string               `json:"permissions,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

CreateUserRequest represents a request to create a new user

type CreateVulnerabilityRequest

type CreateVulnerabilityRequest struct {
	Title           string                 `json:"title"`
	Description     string                 `json:"description"`
	CVEID           string                 `json:"cve_id,omitempty"`
	Severity        string                 `json:"severity"`
	AffectedSystem  string                 `json:"affected_system,omitempty"`
	RemediationPlan string                 `json:"remediation_plan,omitempty"`
	Metadata        map[string]interface{} `json:"metadata,omitempty"`
}

CreateVulnerabilityRequest represents a request to create a new vulnerability

type IncidentResponse

type IncidentResponse struct {
	ID          string                 `json:"id"`
	Title       string                 `json:"title"`
	Description string                 `json:"description"`
	Severity    string                 `json:"severity"`
	Status      string                 `json:"status"`
	ReportedBy  string                 `json:"reported_by,omitempty"`
	AssignedTo  string                 `json:"assigned_to,omitempty"`
	CreatedAt   string                 `json:"created_at"`
	UpdatedAt   string                 `json:"updated_at"`
	ResolvedAt  string                 `json:"resolved_at,omitempty"`
	AuditLogIDs []string               `json:"audit_log_ids,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

IncidentResponse represents a security incident response

type LoggingMiddleware

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

LoggingMiddleware handles logging of API requests

func NewLoggingMiddleware

func NewLoggingMiddleware(accessManager access.AccessControlManager) *LoggingMiddleware

NewLoggingMiddleware creates a new logging middleware

func (*LoggingMiddleware) Middleware

func (m *LoggingMiddleware) Middleware(next http.Handler) http.Handler

Middleware is the HTTP middleware function for logging

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

LoginRequest represents a login request

type LoginResponse

type LoginResponse struct {
	UserID       string   `json:"user_id"`
	Username     string   `json:"username"`
	Email        string   `json:"email"`
	Token        string   `json:"token"`
	RefreshToken string   `json:"refresh_token"`
	ExpiresAt    int64    `json:"expires_at"`
	MFARequired  bool     `json:"mfa_required"`
	MFAMethods   []string `json:"mfa_methods,omitempty"`
}

LoginResponse represents a login response

type MFAVerifyRequest

type MFAVerifyRequest struct {
	Token  string `json:"token"`
	Method string `json:"method"`
	Code   string `json:"code"`
}

MFAVerifyRequest represents an MFA verification request

type ManageMFARequest

type ManageMFARequest struct {
	Enabled bool     `json:"enabled"`
	Methods []string `json:"methods,omitempty"`
}

ManageMFARequest represents a request to manage a user's MFA settings

type RBACMiddleware

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

RBACMiddleware handles role-based access control for API requests

func NewRBACMiddleware

func NewRBACMiddleware(accessManager access.AccessControlManager) *RBACMiddleware

NewRBACMiddleware creates a new RBAC middleware

func (*RBACMiddleware) RequirePermission

func (m *RBACMiddleware) RequirePermission(permission access.Permission) func(http.Handler) http.Handler

RequirePermission returns a middleware function that requires a specific permission

func (*RBACMiddleware) RequireRole

func (m *RBACMiddleware) RequireRole(role string) func(http.Handler) http.Handler

RequireRole returns a middleware function that requires a specific role

type RateLimitMiddleware

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

RateLimitMiddleware handles rate limiting for API requests

func NewRateLimitMiddleware

func NewRateLimitMiddleware(requestsPerMinute int) *RateLimitMiddleware

NewRateLimitMiddleware creates a new rate limit middleware

func (*RateLimitMiddleware) Middleware

func (m *RateLimitMiddleware) Middleware(next http.Handler) http.Handler

Middleware is the HTTP middleware function for rate limiting

func (*RateLimitMiddleware) Stop

func (m *RateLimitMiddleware) Stop()

Stop stops the cleanup goroutine

type RefreshTokenRequest

type RefreshTokenRequest struct {
	RefreshToken string `json:"refresh_token"`
}

RefreshTokenRequest represents a token refresh request

type RequestContext

type RequestContext interface {
	context.Context
	// Add any specific methods needed for the API layer
	GetUserID() string
	GetUsername() string
	GetIPAddress() string
	GetUserAgent() string
}

RequestContext is an interface that extends the standard context.Context to provide additional methods for access control in API handlers

func NewRequestContext

func NewRequestContext(ctx context.Context, userID, username, ipAddress, userAgent string) RequestContext

NewRequestContext creates a new RequestContext

type ResetPasswordRequest

type ResetPasswordRequest struct {
	Password string `json:"password"`
}

ResetPasswordRequest represents a request to reset a user's password

type Response

type Response struct {
	Success bool        `json:"success"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
}

Response is a standard API response format

type RoleResponse

type RoleResponse struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Permissions []string `json:"permissions"`
	ParentRoles []string `json:"parent_roles,omitempty"`
	IsBuiltIn   bool     `json:"is_built_in"`
}

RoleResponse represents a role response

type Server

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

Server is the API server for the access control system

func NewServer

func NewServer(config *APIConfig, accessManager access.AccessControlManager) *Server

NewServer creates a new API server

func (*Server) Start

func (s *Server) Start() error

Start starts the API server

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop stops the API server

type UpdateIncidentRequest

type UpdateIncidentRequest struct {
	Status     string `json:"status,omitempty"`
	AssignedTo string `json:"assigned_to,omitempty"`
}

UpdateIncidentRequest represents a request to update a security incident

type UpdateRoleRequest

type UpdateRoleRequest struct {
	Description string   `json:"description,omitempty"`
	ParentRoles []string `json:"parent_roles,omitempty"`
}

UpdateRoleRequest represents a request to update a role

type UpdateUserRequest

type UpdateUserRequest struct {
	Email       string                 `json:"email,omitempty"`
	Roles       []string               `json:"roles,omitempty"`
	Active      *bool                  `json:"active,omitempty"`
	MFAEnabled  *bool                  `json:"mfa_enabled,omitempty"`
	MFAMethods  []string               `json:"mfa_methods,omitempty"`
	Permissions []string               `json:"permissions,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

UpdateUserRequest represents a request to update a user

type UpdateVulnerabilityRequest

type UpdateVulnerabilityRequest struct {
	Status          string `json:"status,omitempty"`
	AssignedTo      string `json:"assigned_to,omitempty"`
	RemediationPlan string `json:"remediation_plan,omitempty"`
}

UpdateVulnerabilityRequest represents a request to update a vulnerability

type UserResponse

type UserResponse struct {
	ID          string                 `json:"id"`
	Username    string                 `json:"username"`
	Email       string                 `json:"email"`
	Roles       []string               `json:"roles"`
	Permissions []string               `json:"permissions,omitempty"`
	MFAEnabled  bool                   `json:"mfa_enabled"`
	MFAMethods  []string               `json:"mfa_methods,omitempty"`
	Active      bool                   `json:"active"`
	Locked      bool                   `json:"locked"`
	LastLogin   string                 `json:"last_login,omitempty"`
	CreatedAt   string                 `json:"created_at"`
	UpdatedAt   string                 `json:"updated_at"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

UserResponse represents a user response

type VulnerabilityResponse

type VulnerabilityResponse struct {
	ID              string                 `json:"id"`
	Title           string                 `json:"title"`
	Description     string                 `json:"description"`
	CVE             string                 `json:"cve,omitempty"`
	Severity        string                 `json:"severity"`
	Status          string                 `json:"status"`
	ReportedBy      string                 `json:"reported_by,omitempty"`
	AssignedTo      string                 `json:"assigned_to,omitempty"`
	AffectedSystem  string                 `json:"affected_system,omitempty"`
	RemediationPlan string                 `json:"remediation_plan,omitempty"`
	CreatedAt       string                 `json:"created_at"`
	UpdatedAt       string                 `json:"updated_at"`
	ResolvedAt      string                 `json:"resolved_at,omitempty"`
	Metadata        map[string]interface{} `json:"metadata,omitempty"`
}

VulnerabilityResponse represents a vulnerability response

Jump to

Keyboard shortcuts

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