Documentation
¶
Overview ¶
Package writeaudit carries authenticated, non-secret request provenance to business transactions, and owns the rules for recording it and its read models. It does not authorize requests or replace principals. persistence/postgres/auditpg stores it.
Index ¶
- Variables
- func ValidKeyDigest(digest string) bool
- func ValidResourceType(value string) bool
- func ValidText(value string, max int, required bool) bool
- func ValidateOwnerQuery(resourceType string, resourceIDs []string) error
- func ValidateRecord(source Source, tenant, action string, resources []Resource) error
- func WithSource(ctx context.Context, source Source) context.Context
- type APIKey
- type Filter
- type Operation
- type Page
- type Reader
- type Resource
- type ResourceOwner
- type Source
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidQuery = errors.New("invalid write audit query")
ErrInvalidQuery reports a provenance query with an invalid tenant, filter, page size or cursor.
var ErrInvalidSource = errors.New("invalid write audit source")
ErrInvalidSource reports a write audit record that cannot be recorded: malformed provenance, or an action or resource outside the audit vocabulary. The write it belongs to fails closed.
Functions ¶
func ValidKeyDigest ¶
ValidKeyDigest reports whether digest is the lowercase hexadecimal SHA-256 digest that identifies a Project key.
func ValidResourceType ¶
ValidResourceType reports whether value is an audited resource type. The list is closed; recording and owner queries share it.
func ValidText ¶
ValidText reports whether value is valid UTF-8 of at most max runes without control characters, and nonempty when required. Every recorded or queried audit string passes it.
func ValidateOwnerQuery ¶
ValidateOwnerQuery checks a batch creator lookup of one to 100 resources of one audited type.
func ValidateRecord ¶
ValidateRecord checks a write record in tenant: source must be well-formed provenance from tenant, action an audited write action, and every resource an audited resource.
Types ¶
type APIKey ¶
type APIKey struct {
ID string `json:"id"`
Name string `json:"name"`
Prefix string `json:"prefix"`
Kind string `json:"kind"`
RevokedAt *time.Time `json:"revoked_at"`
}
APIKey is the recorded identity of the key that made a write, with its current revocation time.
type Filter ¶
type Filter struct {
KeyID, ResourceType, ResourceID, After string
CreatedAfter, CreatedBefore *time.Time
Limit int
}
Filter selects committed writes, newest first. A zero Limit is the default page size.
type Operation ¶
type Operation struct {
ID string `json:"id"`
Action string `json:"action"`
ResourceType string `json:"resource_type"`
ResourceID string `json:"resource_id"`
ParentID string `json:"parent_id"`
RequestID string `json:"request_id"`
TraceID string `json:"trace_id"`
APIKey APIKey `json:"api_key"`
CreatedAt time.Time `json:"created_at"`
}
Operation is one committed write.
type Reader ¶
type Reader interface {
GetResourceOwners(ctx context.Context, tenantID, resourceType string, resourceIDs []string) ([]ResourceOwner, error)
ListWriteOperations(ctx context.Context, tenantID string, filter Filter) (Page, error)
}
Reader reads write provenance as safe read models, never request bodies or credentials.
type Resource ¶
type Resource struct{ Type, ID, ParentID string }
Resource identifies a resource genuinely created by the current transaction.
type ResourceOwner ¶
type ResourceOwner struct {
ResourceID string `json:"resource_id"`
APIKey *APIKey `json:"api_key"`
Source *string `json:"source"`
AdminAuditID *string `json:"admin_audit_id"`
}
ResourceOwner is the recorded creator of one resource. Both creator fields are null for a resource without recorded creation provenance.
type Source ¶
type Source struct {
KeyID string `json:"key_id"`
Name string `json:"name"`
Prefix string `json:"prefix"`
Kind string `json:"kind"`
TenantID string `json:"tenant_id"`
RequestID string `json:"request_id"`
TraceID string `json:"trace_id"`
}
Source contains no bearer token, payload, file path or native credentials. RequestID is server-generated; TraceID may be shared by related requests.