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 ¶
- func WriteErrorResponse(w http.ResponseWriter, statusCode int, message string)
- func WriteJSON(w http.ResponseWriter, statusCode int, data interface{})
- func WriteSuccessResponse(w http.ResponseWriter, statusCode int, message string, data interface{})
- type APIConfig
- type AddPermissionRequest
- type AuditLogResponse
- type AuthMiddleware
- type BackupCodesResponse
- type CreateIncidentRequest
- type CreateRoleRequest
- type CreateUserRequest
- type CreateVulnerabilityRequest
- type IncidentResponse
- type LoggingMiddleware
- type LoginRequest
- type LoginResponse
- type MFAHandler
- type MFASetupRequest
- type MFAStatusResponse
- type MFAVerifyRequest
- type ManageMFARequest
- type RBACMiddleware
- type RateLimitMiddleware
- type RefreshTokenRequest
- type RequestContext
- type ResetPasswordRequest
- type Response
- type RoleResponse
- type SMSSetupRequest
- type Server
- type TOTPSetupResponse
- type UpdateIncidentRequest
- type UpdateRoleRequest
- type UpdateUserRequest
- type UpdateVulnerabilityRequest
- type UserResponse
- type VulnerabilityResponse
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 BackupCodesResponse ¶
type BackupCodesResponse struct {
Codes []string `json:"codes"`
Generated time.Time `json:"generated"`
}
BackupCodesResponse represents the response for backup codes
type CreateIncidentRequest ¶
type CreateIncidentRequest struct {
Title string `json:"title"`
Description string `json:"description"`
Severity string `json:"severity"`
AffectedResources []string `json:"affected_resources,omitempty"`
Tags []string `json:"tags,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 []common.AuthMethod `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"`
AffectedSystems []string `json:"affected_systems,omitempty"`
RemediationSteps string `json:"remediation_steps,omitempty"`
Tags []string `json:"tags,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"`
ResolutionNotes string `json:"resolution_notes,omitempty"`
AffectedResources []string `json:"affected_resources,omitempty"`
Tags []string `json:"tags,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 ¶
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 MFAHandler ¶
type MFAHandler struct {
// contains filtered or unexported fields
}
MFAHandler handles MFA-related API endpoints
func NewMFAHandler ¶
func NewMFAHandler(authManager *access.AuthManager) *MFAHandler
NewMFAHandler creates a new MFA handler
func (*MFAHandler) RegisterRoutes ¶
func (h *MFAHandler) RegisterRoutes(router *http.ServeMux)
RegisterRoutes registers the MFA API routes
type MFASetupRequest ¶
type MFASetupRequest struct {
Method common.AuthMethod `json:"method"`
}
MFASetupRequest represents a request to set up MFA
type MFAStatusResponse ¶
type MFAStatusResponse struct {
Enabled bool `json:"enabled"`
Methods []common.AuthMethod `json:"methods"`
DefaultMethod common.AuthMethod `json:"default_method"`
LastUpdated time.Time `json:"last_updated,omitempty"`
}
MFAStatusResponse represents the response for MFA status
type MFAVerifyRequest ¶
type MFAVerifyRequest struct {
Method common.AuthMethod `json:"method"`
Code string `json:"code"`
}
MFAVerifyRequest represents a request to verify an MFA code
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 ¶
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 SMSSetupRequest ¶
type SMSSetupRequest struct {
PhoneNumber string `json:"phone_number"`
}
SMSSetupRequest represents a request to set up SMS verification
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the API server for the access control system
type TOTPSetupResponse ¶
type TOTPSetupResponse struct {
Secret string `json:"secret"`
QRCodeURL string `json:"qr_code_url"`
}
TOTPSetupResponse represents the response for TOTP setup
type UpdateIncidentRequest ¶
type UpdateIncidentRequest struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Severity string `json:"severity,omitempty"`
Status string `json:"status,omitempty"`
AssignedTo string `json:"assigned_to,omitempty"`
ResolutionNotes string `json:"resolution_notes,omitempty"`
AffectedResources []string `json:"affected_resources,omitempty"`
Tags []string `json:"tags,omitempty"`
Metadata map[string]interface{} `json:"metadata,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 []common.AuthMethod `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 {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
CVEID string `json:"cve_id,omitempty"`
Severity string `json:"severity,omitempty"`
Status string `json:"status,omitempty"`
AssignedTo string `json:"assigned_to,omitempty"`
PatchNotes string `json:"patch_notes,omitempty"`
AffectedSystems []string `json:"affected_systems,omitempty"`
RemediationSteps string `json:"remediation_steps,omitempty"`
Tags []string `json:"tags,omitempty"`
Metadata map[string]interface{} `json:"metadata,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"`
CVEID string `json:"cve_id,omitempty"`
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"`
PatchedAt string `json:"patched_at,omitempty"`
PatchNotes string `json:"patch_notes,omitempty"`
AffectedSystems []string `json:"affected_systems,omitempty"`
RemediationSteps string `json:"remediation_steps,omitempty"`
Tags []string `json:"tags,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
VulnerabilityResponse represents a vulnerability response