mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
chore: rearrange audit logging code into enterprise folder (#3741)
This commit is contained in:
56
codersdk/audit.go
Normal file
56
codersdk/audit.go
Normal file
@ -0,0 +1,56 @@
|
||||
package codersdk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type ResourceType string
|
||||
|
||||
const (
|
||||
ResourceTypeOrganization ResourceType = "organization"
|
||||
ResourceTypeTemplate ResourceType = "template"
|
||||
ResourceTypeTemplateVersion ResourceType = "template_version"
|
||||
ResourceTypeUser ResourceType = "user"
|
||||
ResourceTypeWorkspace ResourceType = "workspace"
|
||||
)
|
||||
|
||||
type AuditAction string
|
||||
|
||||
const (
|
||||
AuditActionCreate AuditAction = "create"
|
||||
AuditActionWrite AuditAction = "write"
|
||||
AuditActionDelete AuditAction = "delete"
|
||||
)
|
||||
|
||||
type AuditDiff map[string]AuditDiffField
|
||||
|
||||
type AuditDiffField struct {
|
||||
Old any
|
||||
New any
|
||||
Secret bool
|
||||
}
|
||||
|
||||
type AuditLog struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
RequestID uuid.UUID `json:"request_id"`
|
||||
Time time.Time `json:"time"`
|
||||
OrganizationID uuid.UUID `json:"organization_id"`
|
||||
IP netip.Addr `json:"ip"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
ResourceType ResourceType `json:"resource_type"`
|
||||
ResourceID uuid.UUID `json:"resource_id"`
|
||||
// ResourceTarget is the name of the resource.
|
||||
ResourceTarget string `json:"resource_target"`
|
||||
ResourceIcon string `json:"resource_icon"`
|
||||
Action AuditAction `json:"action"`
|
||||
Diff AuditDiff `json:"diff"`
|
||||
StatusCode int32 `json:"status_code"`
|
||||
AdditionalFields json.RawMessage `json:"additional_fields"`
|
||||
Description string `json:"description"`
|
||||
|
||||
User *User `json:"user"`
|
||||
}
|
Reference in New Issue
Block a user