writeaudit

package
v0.0.13-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
var ErrInvalidQuery = errors.New("invalid write audit query")

ErrInvalidQuery reports a provenance query with an invalid tenant, filter, page size or cursor.

View Source
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 ValidResourceType

func ValidResourceType(value string) bool

ValidResourceType reports whether value is an audited resource type. The list is closed; recording and owner queries share it.

func ValidText

func ValidText(value string, max int, required bool) bool

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

func ValidateOwnerQuery(resourceType string, resourceIDs []string) error

ValidateOwnerQuery checks a batch creator lookup of one to 100 resources of one audited type.

func ValidateRecord

func ValidateRecord(source Source, tenant string, action Action, resources []Resource) error

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.

func WithSource

func WithSource(ctx context.Context, source Source) context.Context

Types

type APIKey

type APIKey struct {
	ID        string     `json:"id" binding:"required"`
	Name      string     `json:"name" binding:"required"`
	Prefix    string     `json:"prefix" binding:"required"`
	Kind      string     `json:"kind" enums:"issued" binding:"required"`
	RevokedAt *time.Time `json:"revoked_at" extensions:"x-nullable" binding:"required"`
}

APIKey is the recorded identity of the key that made a write, with its current revocation time.

type Action added in v0.0.10

type Action string
const (
	ActionCreate               Action = "create"
	ActionUpdate               Action = "update"
	ActionDelete               Action = "delete"
	ActionSendEvents           Action = "send_events"
	ActionUploadFile           Action = "upload_file"
	ActionUploadVersion        Action = "upload_version"
	ActionUpdateDefaultVersion Action = "update_default_version"
)

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.

func (Filter) Validate

func (f Filter) Validate() (Filter, error)

Validate checks f and returns it with the default page size applied. The cursor is checked where it is resolved.

type Operation

type Operation struct {
	ID           string       `json:"id" binding:"required"`
	Action       Action       `json:"action" binding:"required"`
	ResourceType ResourceType `json:"resource_type" binding:"required"`
	ResourceID   string       `json:"resource_id" binding:"required"`
	ParentID     string       `json:"parent_id" binding:"required"`
	RequestID    string       `json:"request_id" binding:"required"`
	TraceID      string       `json:"trace_id" binding:"required"`
	APIKey       APIKey       `json:"api_key" binding:"required"`
	CreatedAt    time.Time    `json:"created_at" binding:"required"`
}

Operation is one committed write.

type Page

type Page struct {
	Data       []Operation `json:"data" binding:"required"`
	HasMore    bool        `json:"has_more" binding:"required"`
	NextCursor string      `json:"next_cursor" binding:"required"`
}

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         ResourceType
	ID, ParentID string
}

Resource identifies a resource genuinely created by the current transaction.

type ResourceOwner

type ResourceOwner struct {
	ResourceID string  `json:"resource_id" binding:"required"`
	APIKey     *APIKey `json:"api_key" extensions:"x-nullable" binding:"required"`
}

ResourceOwner is the recorded creator of one resource. APIKey is null for a resource without recorded creation provenance.

type ResourceType added in v0.0.10

type ResourceType string
const (
	ResourceAgent               ResourceType = "agent"
	ResourceSession             ResourceType = "session"
	ResourceEnvironment         ResourceType = "environment"
	ResourceEnvironmentTemplate ResourceType = "environment_template"
	ResourceSkill               ResourceType = "skill"
	ResourceSkillVersion        ResourceType = "skill_version"
	ResourceFile                ResourceType = "file"
	ResourceVault               ResourceType = "vault"
	ResourceCredential          ResourceType = "credential"
	ResourceArtifact            ResourceType = "artifact"
)

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.

func FromContext

func FromContext(ctx context.Context) (Source, bool)

func (Source) Validate

func (s Source) Validate(tenant string) error

Validate checks that s is well-formed provenance of a write in tenant.

Jump to

Keyboard shortcuts

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