publisher

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package publisher emits the results of an AMPEL policy evaluation to external systems. The Publisher object aggregates a set of configured emitters (the drivers: a webhook, a gRPC API, an eventing system, etc) and fans a single PublishResults call out to all of them.

For now, publishing is best effort: PublishResults invokes every emitter but never queues, retries or fails because an emitter returned an error. Any emitter that needs a retry mechanism implements it itself.

Emitters are pluggable and follow the same registration model as the collector's repository drivers: each emitter registers a factory under a moniker and is selected through an initstring of the form "moniker:spec". The factory receives the spec (everything after the first colon) and parses it however the emitter sees fit. The built-in emitters are wired into the registry by the publisher/drivers package's LoadDefaultEmitterTypes.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTypeAlreadyRegistered = errors.New("emitter type already registered")
)

Functions

func RegisterEmitterType

func RegisterEmitterType(moniker string, factory EmitterFactory) error

RegisterEmitterType registers a new type of emitter.

func UnregisterEmitterType

func UnregisterEmitterType(moniker string)

UnregisterEmitterType removes an emitter type from the registry.

Types

type EmitOpt

type EmitOpt func(*EmitOptions)

EmitOpt is a functional option modifying a single Emit call.

type EmitOptions

type EmitOptions struct{}

EmitOptions carries cross-emitter options for an Emit call. It is currently empty but reserved so the Emit signature is stable as options are added.

type Emitter

type Emitter interface {
	// Emit sends the evaluation results to the emitter's destination. It is
	// called once per evaluation with the results of the verified policy
	// material. The papi.Results interface is satisfied by all of the material
	// kinds the verifier can produce (*papi.Result, *papi.ResultGroup and
	// *papi.ResultSet). Emit is best-effort: a returned error is logged by the
	// Publisher but never fails the evaluation.
	Emit(context.Context, papi.Results, ...EmitOpt) error
}

Emitter is the interface implemented by all publisher drivers.

func EmitterFromString

func EmitterFromString(init string) (Emitter, error)

EmitterFromString builds an emitter from an initstring of the form "moniker:spec". The string is split on the first colon: the first half selects the emitter factory from the registry and the remainder is handed to it verbatim.

type EmitterFactory

type EmitterFactory func(string) (Emitter, error)

EmitterFactory builds a configured emitter from the spec portion of an initstring (everything after the "moniker:" prefix). Each emitter parses its own spec.

type Publisher

type Publisher struct {
	Emitters []Emitter
	// contains filtered or unexported fields
}

Publisher fans an evaluation's results out to a set of configured emitters.

func New

func New() *Publisher

New returns an empty Publisher with default emitter loading enabled.

func (*Publisher) AddEmitter

func (p *Publisher) AddEmitter(emitters ...Emitter)

AddEmitter adds already-built emitters to the publisher.

func (*Publisher) AddEmitterInit

func (p *Publisher) AddEmitterInit(inits ...string)

AddEmitterInit queues an emitter initstring ("moniker:spec"). The emitter is constructed when Build is called, after the required types are registered.

func (*Publisher) Build

func (p *Publisher) Build() error

Build constructs the queued emitter initstrings into emitters. It must be called after the required emitter types are registered (see the publisher/drivers package's LoadDefaultEmitterTypes).

func (*Publisher) LoadsDefaults

func (p *Publisher) LoadsDefaults() bool

LoadsDefaults reports whether the default emitter types should be registered before the queued emitters are built.

func (*Publisher) PublishResults

func (p *Publisher) PublishResults(ctx context.Context, results papi.Results) error

PublishResults emits the results through all configured emitters and returns the joined emitter errors. Every emitter is always invoked; a failing one does not stop the others. The verifier treats publishing as best-effort and ignores the returned error.

func (*Publisher) SetLoadDefaults

func (p *Publisher) SetLoadDefaults(load bool)

SetLoadDefaults controls whether Build expects the default emitter types to be registered. It is enabled by default.

Directories

Path Synopsis
Package drivers wires the built-in emitter drivers into the publisher registry.
Package drivers wires the built-in emitter drivers into the publisher registry.
Package stdout implements a mock emitter that writes the evaluation results as JSON to a writer (os.Stdout by default).
Package stdout implements a mock emitter that writes the evaluation results as JSON to a writer (os.Stdout by default).
Package webhook implements an emitter that POSTs the evaluation results as JSON to an HTTP(S) endpoint.
Package webhook implements an emitter that POSTs the evaluation results as JSON to an HTTP(S) endpoint.

Jump to

Keyboard shortcuts

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