webhooksecret

package
v0.0.0-...-abcf26b Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package webhooksecret provides an in-memory store for per-API plaintext HMAC secrets used by the websub-hmac-auth policy at request validation time. Secrets are stored as plaintext (not hashed) because HMAC computation requires the raw secret bytes. The store is populated on startup from the database and kept in sync via EventHub events.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a secret is not found.
	ErrNotFound = errors.New("webhook secret not found")

	// ErrConflict is returned when a secret with the same name already exists.
	ErrConflict = errors.New("webhook secret already exists")

	// ErrInvalidInput is returned when input validation fails.
	ErrInvalidInput = errors.New("invalid input")
)

Common storage errors — implementation agnostic.

Functions

func BuildWebhookSecretEntityID

func BuildWebhookSecretEntityID(artifactUUID, secretUUID, secretName string) string

BuildWebhookSecretEntityID constructs the composite entity ID used in EventHub events. Format: "<artifactUUID>_<secretUUID>_<secretName>". The name segment allows delete-path processors to skip a DB round-trip.

func ParseWebhookSecretEntityID

func ParseWebhookSecretEntityID(entityID string) (artifactUUID, secretUUID, secretName string, err error)

ParseWebhookSecretEntityID decomposes an entity ID produced by BuildWebhookSecretEntityID back into its three components.

Types

type WebhookSecretStore

type WebhookSecretStore struct {
	// contains filtered or unexported fields
}

WebhookSecretStore holds per-API HMAC secrets in memory for fast access. The inner map uses the secret name as key and the plaintext value as value. Key: "API ID" → Value: map[name]plaintext

func GetStoreInstance

func GetStoreInstance() *WebhookSecretStore

GetStoreInstance returns the process-wide singleton store.

func NewWebhookSecretStore

func NewWebhookSecretStore() *WebhookSecretStore

NewWebhookSecretStore creates a new empty store.

func (*WebhookSecretStore) ClearAll

func (s *WebhookSecretStore) ClearAll()

ClearAll removes all secrets from the store. Primarily used in tests.

func (*WebhookSecretStore) GetAll

func (s *WebhookSecretStore) GetAll() map[string]map[string]string

GetAll returns a deep copy of the full store contents keyed by (apiId → name → plaintext). Used by snapshot managers to serialize the store for xDS delivery.

func (*WebhookSecretStore) GetAllByAPI

func (s *WebhookSecretStore) GetAllByAPI(apiId string) []string

GetAllByAPI returns the plaintext values of all active secrets for the API. The HMAC policy calls this and tries each value until one produces a matching signature, supporting multiple simultaneous active secrets (zero-downtime rotation). Returns an empty slice when no secrets exist for the API.

func (*WebhookSecretStore) Remove

func (s *WebhookSecretStore) Remove(apiId, name string) error

Remove deletes the named secret for an API. Returns ErrNotFound when absent (idempotent callers may ignore this).

func (*WebhookSecretStore) RemoveAllByAPI

func (s *WebhookSecretStore) RemoveAllByAPI(apiId string) error

RemoveAllByAPI removes every secret associated with the given API.

func (*WebhookSecretStore) ReplaceAll

func (s *WebhookSecretStore) ReplaceAll(newMap map[string]map[string]string) error

ReplaceAll atomically replaces the entire store contents with a new snapshot. Used during startup bulk-load to swap state in one critical-section operation.

func (*WebhookSecretStore) Store

func (s *WebhookSecretStore) Store(apiId, name, plaintext string) error

Store saves a plaintext secret keyed by (apiId, name). If a secret with the same name already exists for this API, its value is replaced (rotation).

Jump to

Keyboard shortcuts

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