Documentation
¶
Overview ¶
Package tagging labels requests based on configurable HTTP headers. Each rule names one header whose value carries request labels; labels flow into usage tracking and audit logs, and rules can mark their header as do-not-pass so it is never forwarded to upstream providers.
Index ¶
- Constants
- func ExtractLabels(rules []Rule, headers http.Header) []string
- func IsValidationError(err error) bool
- func NormalizeRules(rules []Rule) error
- func StripHeaderSet(rules []Rule) map[string]struct{}
- type MongoDBStore
- type Result
- type Rule
- type SQLStore
- type Service
- func (s *Service) Editable() bool
- func (s *Service) ExtractLabels(headers http.Header) []string
- func (s *Service) HasRules() bool
- func (s *Service) Refresh(ctx context.Context) error
- func (s *Service) Rules() []Rule
- func (s *Service) SaveRules(ctx context.Context, rules []Rule) ([]Rule, error)
- func (s *Service) StripHeaders() map[string]struct{}
- type Store
- type ValidationError
Constants ¶
const DefaultDelimiter = ","
DefaultDelimiter separates multiple labels inside one header value.
Variables ¶
This section is empty.
Functions ¶
func ExtractLabels ¶
ExtractLabels reads every rule's header and returns the deduplicated labels in rule order. Each header value is split by the rule's delimiter and each piece is whitespace-trimmed; when the rule has a prefix, it is trimmed from pieces that carry it, and pieces without it are kept as-is.
func IsValidationError ¶
IsValidationError reports whether err stems from invalid caller input.
func NormalizeRules ¶
NormalizeRules canonicalizes header names, applies the default delimiter, and rejects invalid, credential-bearing, or duplicate entries in place. Rejections are ValidationErrors.
func StripHeaderSet ¶
StripHeaderSet returns the canonical header names marked do-not-pass.
Types ¶
type MongoDBStore ¶
type MongoDBStore struct {
// contains filtered or unexported fields
}
MongoDBStore persists tagging rules in a settings collection.
func NewMongoDBStore ¶
NewMongoDBStore creates a tagging store over the tagging_settings collection.
func (*MongoDBStore) Close ¶
func (s *MongoDBStore) Close() error
Close is a no-op: the client is managed by the storage layer.
type Result ¶
Result bundles the tagging service with its store.
type Rule ¶
type Rule struct {
// Header is the canonical HTTP header name to read labels from.
Header string `json:"header" bson:"header"`
// Prefix is optionally trimmed from the front of each label. Trimming only
// affects the extracted label, never the forwarded header value.
Prefix string `json:"prefix,omitempty" bson:"prefix,omitempty"`
// DoNotPass strips the header before forwarding the request upstream.
// Default: false (headers are passed through as-is).
DoNotPass bool `json:"do_not_pass,omitempty" bson:"do_not_pass,omitempty"`
// Delimiter splits one header value into multiple labels. Default: ",".
Delimiter string `json:"delimiter,omitempty" bson:"delimiter,omitempty"`
// Managed marks a rule declared in config/env; such rules are read-only in
// the dashboard. Never persisted.
Managed bool `json:"managed,omitempty" bson:"-"`
}
Rule configures label extraction from one request header. Managed rules come from config.yaml / TAGGING_HEADER_* env vars, override store rows with the same header name, and are read-only in the dashboard.
func ConfigRules ¶
func ConfigRules(entries []config.TaggingHeaderConfig) []Rule
ConfigRules converts declarative config.yaml / TAGGING_HEADER_* entries into managed tagging rules. Entries are already normalized by config.Load.
type SQLStore ¶ added in v0.1.60
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore persists tagging rules in a key-value settings table.
func NewSQLStore ¶ added in v0.1.60
NewSQLStore creates the tagging settings table when missing.
func (*SQLStore) Close ¶ added in v0.1.60
Close is a no-op: the connection is managed by the storage layer.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service merges declarative (config/env) tagging rules over operator rules persisted in the store and serves label extraction on the request hot path.
func NewService ¶
NewService creates a tagging service. configRules must already be normalized by config.Load; store may be nil, in which case only config rules apply and dashboard edits are unavailable.
func (*Service) ExtractLabels ¶
ExtractLabels returns the request labels for the given inbound headers.
func (*Service) Refresh ¶
Refresh reloads operator rules from the store and swaps the merged snapshot.
func (*Service) Rules ¶
Rules returns the effective rules: managed config rules first, then operator rules from the store.
func (*Service) SaveRules ¶
SaveRules validates and persists the operator-managed rule set (replacing the previous set), refreshes the snapshot, and returns the merged view. Rules whose header is declared in config/env are rejected as read-only.
func (*Service) StripHeaders ¶
StripHeaders returns the canonical header names that must not be forwarded to upstream providers. Callers must treat the returned map as read-only.
type Store ¶
type Store interface {
// GetRules returns the persisted operator rules, empty when none were saved.
GetRules(ctx context.Context) ([]Rule, error)
// SaveRules replaces the persisted operator rule set.
SaveRules(ctx context.Context, rules []Rule) error
// Close releases store resources.
Close() error
}
Store persists the operator-managed tagging rules (the dashboard-editable set). Declarative config/env rules are never stored.
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
ValidationError marks rule failures caused by caller input, so API handlers can report them as a bad request instead of a storage failure.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error