{"modulePath":"github.com/chainloop-dev/chainloop","version":"v1.138.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package auditor\n\n## Constants\n\n```go\nconst ActorSystemIdentifier = \"system@chainloop.dev\"\n```\nGetActorIdentifier returns the actor identifier for audit log descriptions. It prioritizes ActorName, then ActorEmail, and finally falls back to system@chainloop.dev.\n\n```go\nconst AuditEventType = \"AUDIT_EVENT\"\n```\n\n## Functions\n\n```go\nfunc GetActorIdentifier() string\n```\n\n## Types\n\n```go\ntype ActorType string\n```\nActorType is the type for the actor of a log entry, meaning the user or service that performed the action.\n\n```go\nconst (\n\t// ActorTypeUser is the type for a user actor.\n\tActorTypeUser ActorType = \"USER\"\n\t// ActorTypeAPIToken is the type for am API Token actor.\n\tActorTypeAPIToken ActorType = \"API_TOKEN\"\n\t// ActorTypeSystem is the type for a system actor.\n\tActorTypeSystem = \"SYSTEM\"\n)\n```\n\n```go\ntype AuditEventPayload struct {\n\tActionType  string\n\tTargetType  TargetType\n\tTargetID    *uuid.UUID\n\tActorType   ActorType\n\tActorID     *uuid.UUID\n\tActorEmail  string\n\tActorName   string\n\tOrgID       *uuid.UUID\n\tDescription string\n\tInfo        json.RawMessage\n\tDigest      *cr_v1.Hash\n}\n```\n\n```go\ntype AuditLogPublisher struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewAuditLogPublisher(ctx context.Context, rc *natsconn.ReloadableConnection, logger log.Logger) (*AuditLogPublisher, error)\n```\nNewAuditLogPublisher creates a publisher that owns the JetStream stream: it creates or updates it on boot and after every NATS reconnection.\n\n```go\nfunc NewPublishOnlyAuditLogPublisher(rc *natsconn.ReloadableConnection, logger log.Logger) (*AuditLogPublisher, error)\n```\nNewPublishOnlyAuditLogPublisher creates a publisher that never creates or updates the JetStream stream. Meant for components (e.g. the Artifact CAS) that publish to the stream owned and configured by the control plane, so they can't accidentally override its configuration (e.g. downgrade the replica count).\n\n```go\nfunc (p *AuditLogPublisher) Publish(data *EventPayload) error\n```\n\n```go\ntype DescriptionVariables struct {\n\tActorType  ActorType\n\tActorID    *uuid.UUID\n\tActorEmail string\n\tActorName  string\n\tOrgID      *uuid.UUID\n}\n```\n\n```go\ntype Dispatcher struct {\n\t// contains filtered or unexported fields\n}\n```\nDispatcher centralizes the generate -\u003e publish -\u003e error-reporting flow shared by every component that emits audit events (e.g. the control plane's biz.AuditorUseCase and the Artifact CAS). Callers resolve the actor and organization themselves and pass them as GeneratorOptions, so each component keeps its own actor/org policy (request context vs JWT claims) while sharing the common dispatch machinery.\n\n```go\nfunc NewDispatcher(publisher Publisher, logger log.Logger) *Dispatcher\n```\nNewDispatcher builds a Dispatcher. A nil publisher (e.g. NATS not configured) turns Dispatch into a no-op and makes Enabled report false.\n\n```go\nfunc (d *Dispatcher) Dispatch(entry LogEntry, opts ...GeneratorOption)\n```\nDispatch generates the audit event from entry and the given options and publishes it. Best-effort: failures are logged and reported to Sentry, never returned, so they can't fail or slow down the caller. A disabled dispatcher is a no-op.\n\n```go\nfunc (d *Dispatcher) Enabled() bool\n```\nEnabled reports whether Dispatch would actually publish an event. Callers can use it to skip extra work when the dispatcher is a no-op.\n\n```go\ntype EventPayload struct {\n\tEventType string // AUDIT_EVENT\n\tTimestamp time.Time\n\tData      *AuditEventPayload\n}\n```\n\n```go\nfunc GenerateAuditEvent(entry LogEntry, opts ...GeneratorOption) (*EventPayload, error)\n```\n\n```go\nfunc (e *EventPayload) ToJSON() ([]byte, error)\n```\n\n```go\ntype GeneratorOption func(*GeneratorOptions) error\n```\n\n```go\nfunc WithActor(actorType ActorType, actorID uuid.UUID, email, name string) GeneratorOption\n```\n\n```go\nfunc WithOrgID(orgID uuid.UUID) GeneratorOption\n```\n\n```go\ntype GeneratorOptions struct {\n\tActorType  ActorType\n\tActorID    *uuid.UUID\n\tActorEmail string\n\tActorName  string\n\tOrgID      *uuid.UUID\n}\n```\n\n```go\ntype LogEntry interface {\n\t// ActionType returns the type of the action performed.\n\tActionType() string\n\t// ActionInfo returns the information about the action performed.\n\tActionInfo() (json.RawMessage, error)\n\t// TargetType returns the type of the target of the action.\n\tTargetType() TargetType\n\t// TargetID returns the ID of the target of the action.\n\tTargetID() *uuid.UUID\n\t// Description returns a templatable string, see the DescriptionVariables struct.\n\tDescription() string\n\tRequiresActor() bool\n}\n```\nLogEntry is the interface for all log entries. All events should implement this interface to be able to be logged.\n\n```go\ntype Publisher interface {\n\tPublish(data *EventPayload) error\n}\n```\nPublisher publishes generated audit event payloads to the event bus. Implemented by \\*AuditLogPublisher; abstracted so it can be faked in tests and so a nil publisher can act as a no-op (NATS not configured).\n\n```go\ntype TargetType string\n```\nTargetType is the type for the target of a log entry, aka the resource acted upon.\n\n","path":"github.com/chainloop-dev/chainloop/app/controlplane/pkg/auditor","name":"auditor","synopsis":"","isRedistributable":true}
