{"modulePath":"github.com/rossoctl/cortex/authbridge/authlib","version":"v0.0.0-20260925150928-4ef879cde00f","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugins\n\n## Functions\n\n```go\nfunc Build(entries []config.PluginEntry, opts ...pipeline.Option) (*pipeline.Pipeline, error)\n```\nBuild constructs a pipeline from an ordered list of plugin entries. For every plugin that implements pipeline.Configurable, Build calls Configure with the entry's Config bytes (nil when omitted). Passing config to a plugin that doesn't implement Configurable is rejected so stale or misplaced config blocks fail at startup instead of being silently ignored.\n\nUnknown plugin names fail fast with an error that lists every currently-registered plugin — typo-catching diagnostic.\n\nInjects nothing. A thin wrapper over BuildWithDeps, which is the single implementation; see there for the Configure and injection contract.\n\n```go\nfunc BuildWithDeps(entries []config.PluginEntry, deps Deps, opts ...pipeline.Option) (*pipeline.Pipeline, error)\n```\nBuildWithDeps constructs a pipeline from an ordered list of plugin entries, injecting each supplied dependency into the plugins that consume it.\n\nFor every plugin implementing pipeline.Configurable, Configure is called with the entry's Config bytes (nil when omitted). Passing config to a plugin that does not implement Configurable is rejected, so stale or misplaced config blocks fail at startup instead of being silently ignored. Unknown plugin names fail fast with an error listing every registered plugin.\n\nDependencies are injected BEFORE Configure runs, so configuration code can use them. That ordering is the contract, not an implementation detail: a plugin's Configure may build rate- or identity-dependent state, and an injection landing afterwards would be silently too late.\n\nA nil dependency is NOT injected, rather than injected as nil. Handing a plugin a typed-nil interface would make its own \\`!= nil\\` guard true while every call through it panicked.\n\nThis is the single builder. Build and BuildWithSPIFFE delegate here; before this they were two copies of the same forty lines, differing only in one injection.\n\n```go\nfunc BuildWithSPIFFE(entries []config.PluginEntry, p *spiffe.Provider, opts ...pipeline.Option) (*pipeline.Pipeline, error)\n```\nBuildWithSPIFFE is Build plus dependency injection of the framework SPIFFE Provider. Every plugin satisfying spiffe.ProviderConsumer receives p via SetSPIFFEProvider before its Configure is invoked, so configuration code can use the provider's sources directly.\n\nPass nil for p in builds that don't need SPIFFE; in that case the behavior is equivalent to Build for non-consuming plugins, and consumer plugins are NOT called (their SetSPIFFEProvider is skipped).\n\nPlugins that don't implement ProviderConsumer are unaffected.\n\nA thin wrapper over BuildWithDeps. It survives as a named entry point because four binaries call it; new dependencies go through Deps rather than growing a third builder.\n\n```go\nfunc CollectStats(p *pipeline.Pipeline) []*auth.Stats\n```\nCollectStats walks a pipeline and returns every \\*auth.Stats exposed by a StatsSource-implementing plugin. Order matches plugin declaration order in the pipeline, which keeps the aggregated output deterministic.\n\nReturns nil (not an empty slice) when no plugins implement StatsSource, so callers can pass the result straight to auth.MergeStats without guarding against zero-length.\n\n```go\nfunc PricingConsumerPlugins() []string\n```\nPricingConsumerPlugins lists the registered plugins whose instances implement pricing.ResolverConsumer — the plugins BuildWithDeps would inject the Registry into.\n\nCallers that gate Registry construction on actual need use this to assert their need-detection covers every consumer; a new consumer slipping past the predicate would otherwise silently receive no resolver and report its traffic as unpriced, which looks identical to having no rates configured.\n\nProbes by constructing each plugin and type-asserting, which is safe because PluginFactory is contractually a cheap, side-effect-free constructor. Mirrors SPIFFEConsumerPlugins; if a factory ever gains construction-time side effects, both switch to a static capability tag instead of a live probe.\n\n```go\nfunc RegisterPlugin(name string, factory PluginFactory)\n```\nRegisterPlugin adds a plugin factory under name. Intended to be called from package init() functions of plugin implementations:\n\n\tfunc init() {\n\t    plugins.RegisterPlugin(\"rate-limiter\", func() pipeline.Plugin {\n\t        return \u0026RateLimiter{}\n\t    })\n\t}\n\nThis is the stdlib pattern (database/sql.Register, image codec registration, log/slog handler registration): plugins live in their own package and advertise themselves by side-effect import:\n\n\timport _ \"github.com/acme/rossoctl-rate-limiter/ratelimit\"\n\nDouble-registration under the same name panics. Silent last-write- wins would let a version mismatch or deployment bug poison the registry in ways that only surface as mysterious runtime behaviour; failing loud at process start is strictly safer.\n\nEmpty name or nil factory also panics — both are programmer errors, not recoverable conditions.\n\n```go\nfunc RegisteredPlugins() []string\n```\nRegisteredPlugins returns the names of every registered plugin in sorted order. Intended for diagnostic surfaces (/config, CLI --help, Build's \"unknown plugin\" error message) and for tests that assert a plugin is visible to the builder.\n\n```go\nfunc SPIFFEConsumerPlugins() []string\n```\nSPIFFEConsumerPlugins returns the sorted names of registered plugins whose instances implement spiffe.ProviderConsumer — i.e. the plugins BuildWithSPIFFE would inject the Provider into. Callers that gate Provider construction on actual need (see cmd/authbridge-proxy's spiffeProviderNeeded) use this to assert their need-detection covers every consumer; a new consumer that slips past the predicate would otherwise silently receive a nil Provider.\n\nThis probes by constructing each plugin and type-asserting. That is safe because PluginFactory is contractually a cheap, side-effect-free constructor (see PluginFactory: no construction args; deps + goroutines are created in Configure/Init, not the factory). If a factory ever gains construction-time side effects, switch this to a static capability tag instead of a live probe.\n\n```go\nfunc UnregisterPlugin(name string) bool\n```\nUnregisterPlugin removes a plugin factory from the registry. Intended for test isolation: a test registers a fake plugin, runs, and uses t.Cleanup to unregister so parallel tests aren't poisoned by the leftover entry.\n\nDo not call from production code. The registry is intended to be written exactly once per plugin per process, at init() time; runtime deregistration has no valid use case in a running authbridge binary and would make the /config endpoint lie about pipeline composition.\n\nReturns true when the name was registered (and is now removed), false when it wasn't. Callers ignoring the return value are common and correct — Cleanup doesn't care.\n\n```go\nfunc WarmCatalog()\n```\nWarmCatalog triggers Catalog() at boot so any plugin whose factory violates the constructor contract (panics, allocates goroutines / connections / file handles) surfaces during startup rather than silently caching a faulty throwaway instance on the first /v1/plugins request. Cheap insurance — the result is already memoized, so calling this at boot moves \"first call\" out of the request hot path.\n\nIntended for the binary's main() to invoke once after all plugin init() registrations have run (typically right before sessionapi.New).\n\n## Types\n\n```go\ntype CatalogEntry struct {\n\tName         string\n\tCapabilities pipeline.PluginCapabilities\n\tFields       []pipeline.FieldSchema\n}\n```\nCatalogEntry pairs a registered plugin's name with the capabilities it advertises and the field-level schema of its config (if it implements pipeline.SchemaProvider). Surfaces in \\`abctl\\`'s catalog pane, in the /v1/plugins endpoint, and in \\`abctl edit\\`'s template renderer so operators can see what plugins exist, what each one needs, and what each field means without reading source.\n\nFields is nil for plugins without a config (or that don't implement SchemaProvider) — the wire format omits the field via \\`omitempty\\`, so existing consumers that don't know about field schemas keep working.\n\n```go\nfunc Catalog() []CatalogEntry\n```\nCatalog returns a sorted snapshot of every registered plugin's capabilities. The result is computed on first call and cached; subsequent calls return the cached slice (do not mutate it).\n\nFirst-call mechanics: each registered factory is invoked once with no config; the resulting instance's Capabilities() is the static type-level metadata that the rest of the framework also reads.\n\nCONSTRUCTOR CONTRACT: factories called from Catalog MUST NOT allocate goroutines, network connections, file handles, or other resources that need explicit teardown. Allocate the plugin struct and nothing more — heavy work belongs in Init() (after Configure()), where the framework owns the lifecycle. The throwaway instance Catalog constructs is never Shutdown'd; anything it leaks is process-wide.\n\nThe godoc on PluginCapabilities documents the parallel constraint that Capabilities() must be instance-state-independent (so the cached snapshot from one instance describes every instance the factory produces).\n\n```go\ntype Deps struct {\n\t// SPIFFE is injected into plugins implementing spiffe.ProviderConsumer.\n\tSPIFFE *spiffe.Provider\n\n\t// Pricing is injected into plugins implementing pricing.ResolverConsumer.\n\t// Long-lived: the reloader rebuilds pipelines but the resolver is swapped in\n\t// place, so a plugin from any build sees current rates. See pricing.Registry.\n\tPricing *pricing.Registry\n}\n```\nDeps are the process-wide dependencies a pipeline build can inject into plugins.\n\nPlugin factories take no construction arguments (see PluginFactory), so anything shared across the process has to arrive this way. A struct rather than a growing parameter list: BuildWithSPIFFE existed because SPIFFE needed injecting, and adding pricing the same way would have meant a third near-identical builder.\n\nEvery field is optional. A zero Deps builds exactly what Build always did.\n\n```go\ntype PluginFactory func() pipeline.Plugin\n```\nPluginFactory returns a fresh plugin instance. Plugins take no construction arguments — they receive their configuration through pipeline.Configurable.Configure during Build, and any external dependencies (JWKS cache, HTTP client, etc.) are built from that local config inside Configure.\n\n```go\ntype StatsSource interface {\n\tStats() *auth.Stats\n}\n```\nStatsSource is an optional interface a plugin implements when it maintains observability counters worth exposing on the /stats endpoint. Lives in the plugins package (rather than pipeline) because auth.Stats is the shared counter type and the pipeline package has no reason to depend on auth.\n\nPlugins that don't report stats don't implement this interface; the host skips them during aggregation.\n\n","path":"github.com/rossoctl/cortex/authbridge/authlib/plugins","name":"plugins","synopsis":"","isRedistributable":true}
