Documentation
¶
Index ¶
- func AddMetadata(ctx context.Context, key string, value any)
- func AddMetadataBatch(ctx context.Context, metadata map[string]any)
- func GetMetadata(ctx context.Context) map[string]any
- func SetMetadata(ctx context.Context, metadata map[string]any)
- func SetResource(ctx context.Context, resource *Resource)
- type ActionCategory
- type ActionDefinition
- type ActionResolver
- type Actor
- type AuditData
- type Event
- type Logger
- type Middleware
- type Resource
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddMetadata ¶
AddMetadata adds a single key-value pair to the audit metadata If metadata doesn't exist yet, it creates a new map
func AddMetadataBatch ¶
AddMetadataBatch adds multiple key-value pairs to the audit metadata If metadata doesn't exist yet, it creates a new map
func GetMetadata ¶
GetMetadata retrieves the audit metadata from the context Returns nil if no metadata has been set
func SetMetadata ¶
SetMetadata stores additional audit metadata Handlers can call this to add custom fields to the audit event
func SetResource ¶
SetResource stores resource information for audit logging Handlers should call this to specify which resource is being acted upon
Types ¶
type ActionCategory ¶
type ActionCategory string
ActionCategory represents the category of audit action
const ( CategoryResource ActionCategory = "resource" CategoryAuth ActionCategory = "auth" CategoryObservability ActionCategory = "observability" )
type ActionDefinition ¶
type ActionDefinition struct {
// Method is the HTTP method (GET, POST, PUT, DELETE, etc.)
Method string
// Pattern is the route pattern to match (using Go 1.22+ ServeMux patterns)
// Examples: "/api/v1/namespaces/{namespace}/projects", "POST /api/v1/components/{id}"
Pattern string
// Action is the semantic action name for audit logging
Action string
// Category is the action category
Category ActionCategory
}
ActionDefinition defines how to map an HTTP route to an audit action
type ActionResolver ¶
type ActionResolver struct {
// contains filtered or unexported fields
}
ActionResolver resolves HTTP requests to audit action definitions
func NewActionResolver ¶
func NewActionResolver(definitions []ActionDefinition) *ActionResolver
NewActionResolver creates a new action resolver with the given definitions
func (*ActionResolver) Resolve ¶
func (r *ActionResolver) Resolve(req *http.Request) *ActionDefinition
Resolve attempts to match an HTTP request to an action definition Returns the matching definition or nil if no match is found
type Actor ¶
type Actor struct {
Type string `json:"type"` // e.g., "user", "service_account", "anonymous"
ID string `json:"id"` // User ID, service account ID, or "anonymous"
Entitlements map[string]interface{} `json:"entitlements,omitempty"` // Optional entitlements associated with the actor
}
Actor represents who performed the action
type Event ¶
type Event struct {
EventID string `json:"event_id"` // Unique identifier (UUID v7)
Timestamp time.Time `json:"timestamp"` // When the action occurred
Actor Actor `json:"actor"` // Who performed the action
Action string `json:"action"` // Semantic action name (e.g., "create_project")
Category ActionCategory `json:"category"` // Action category
Resource *Resource `json:"resource"` // Target resource (can be nil for non-resource actions)
Result Result `json:"result"` // Outcome
RequestID string `json:"request_id"` // Correlation ID linking to access log
SourceIP string `json:"source_ip"` // Client IP address
Service string `json:"service"` // Emitting service (e.g., "openchoreo-api")
Metadata map[string]any `json:"metadata,omitempty"` // Additional context (optional)
}
Event represents a complete audit log event
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger handles emitting audit log events using structured logging
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware handles audit logging for HTTP requests
func NewMiddleware ¶
func NewMiddleware(logger *Logger, resolver *ActionResolver) *Middleware
NewMiddleware creates a new audit middleware
type Resource ¶
type Resource struct {
Type string `json:"type"` // e.g., "project", "component", "environment"
ID string `json:"id,omitempty"` // Resource identifier
Name string `json:"name,omitempty"` // Resource name (if different from ID)
}
Resource represents the target resource of an action
func GetResource ¶
GetResource retrieves the resource information from the context Returns nil if no resource has been set