enhancers

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package enhancers holds the built-in pkg/enhance implementations: googlecloud (repository resolution from a Google Cloud resource's ownership labels, with dynamicgooglecloud reading its configuration off the google-cloud Integration per enhancement) and staticfile (a YAML-backed repo→ownership map that doubles as the fake CMDB for development and e2e). The real CMDB integration implements the same pkg/enhance.Enhancer seam later.

Index

Constants

View Source
const (
	DefaultOrgLabel      = "scm-repository-org"
	DefaultNameLabel     = "scm-repository-name"
	DefaultProviderLabel = "scm-repository-provider"
	DefaultURLLabel      = "scm-repository-url"
)

Default label keys. A cloud resource says who owns it by carrying these; they are the bridge between an infrastructure finding and the repository whose code provisions the thing that is wrong.

Google Cloud label values are lowercase alphanumerics, hyphens and underscores, capped at 63 characters — which a URL cannot survive. Hence the triple: an org and a name both fit comfortably, and the URL form is there for security marks, whose values are far less constrained.

View Source
const AWSTagsID = "aws-resource-tags"

AWSTagsID is the enhancer's id.

View Source
const AzureTagsID = "azure-resource-tags"

AzureTagsID is the enhancer's id.

View Source
const GoogleCloudLabelsID = "google-cloud-labels"

GoogleCloudLabelsID is the enhancer's id.

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSConfigSource added in v0.9.0

type AWSConfigSource func(ctx context.Context) (*AWSTagsConfig, error)

AWSConfigSource yields the current capability configuration: nil when the capability is off (the enhancer stands aside), an error when it cannot be read (the finding is held and retried rather than advanced without its enrichment).

type AWSInventory added in v0.9.0

type AWSInventory interface {
	TagsFor(ctx context.Context, arn string) (*awsinv.Tags, error)
}

AWSInventory reads a cloud resource's tags. Declared here, next to its only consumer, so the enhancer's tests need no AWS client.

type AWSTags added in v0.9.0

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

AWSTags is the cloudTags engine configured for AWS: ARN-shaped identifiers, awsinv's not-found sentinel, the aws-account attribute.

func NewAWSTags added in v0.9.0

func NewAWSTags(inventory AWSInventory, o TagsOptions) (*AWSTags, error)

NewAWSTags builds the enhancer.

func (*AWSTags) Enhance added in v0.9.0

func (c *AWSTags) Enhance(ctx context.Context, issue enhance.Issue) (*enhance.Enrichment, error)

Enhance implements enhance.Enhancer.

A resource that exists but carries no ownership tags returns an enrichment with no repository rather than an error: that is a final answer, and reporting it as a failure would hold the finding out of sight instead of handing it to a human. Only a lookup that might succeed next time errors.

func (*AWSTags) ID added in v0.9.0

func (c *AWSTags) ID() string

ID implements enhance.Enhancer.

type AWSTagsConfig added in v0.9.0

type AWSTagsConfig struct {
	// Backend selects and configures the inventory queried.
	Backend awsinv.Config
	// RepositoryHost is the forge host composed into resolved URLs; empty
	// means github.com.
	RepositoryHost string
	// Keys overrides the ownership tag names.
	Keys LabelKeys
}

AWSTagsConfig is one snapshot of the resourceTags capability, as read off the aws Integration at enhance time.

type AssetConfig added in v0.9.0

type AssetConfig struct {
	// Scope bounds the asset search.
	Scope string
	// RepositoryHost is the forge host composed into resolved URLs; empty
	// means github.com.
	RepositoryHost string
	// Keys overrides the ownership label names.
	Keys LabelKeys
}

AssetConfig is one snapshot of the cloudAssetInventory capability, as read off the google-cloud Integration at enhance time.

type AssetLabels added in v0.8.0

type AssetLabels interface {
	LabelsFor(ctx context.Context, resourceName, displayName string) (*gcpasset.Labels, error)
}

AssetLabels reads a cloud resource's labels. Declared here, next to its only consumer, so the enhancer's tests need no Google Cloud client. The display name rides along for the lookup's fallback: an identifier a source could not spell the Asset Inventory way still has a second chance.

type AttributedEnrichment added in v0.9.1

type AttributedEnrichment struct {
	// ID attributes the enrichment — the label on the sticky comment and
	// the tie-breaker in attribute precedence.
	ID string
	// Enrichment is the contribution; never nil.
	Enrichment *enhance.Enrichment
}

AttributedEnrichment is one enrichment with its own attribution: what a multi-instance enhancer yields, because one chain entry can speak for several identities.

type AzureConfigSource added in v0.9.0

type AzureConfigSource func(ctx context.Context) (*AzureTagsConfig, error)

AzureConfigSource yields the current capability configuration: nil when the capability is off (the enhancer stands aside), an error when it cannot be read (the finding is held and retried rather than advanced without its enrichment).

type AzureInventory added in v0.9.0

type AzureInventory interface {
	TagsFor(ctx context.Context, id string) (*azureinv.Tags, error)
}

AzureInventory reads a cloud resource's tags. Declared here, next to its only consumer, so the enhancer's tests need no Azure client.

type AzureTags added in v0.9.0

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

AzureTags is the cloudTags engine configured for Azure: ARM resource IDs (the "/" prefix admits /subscriptions/... and the tenant-level /providers/...), azureinv's not-found sentinel, the azure-subscription attribute.

func NewAzureTags added in v0.9.0

func NewAzureTags(inventory AzureInventory, o TagsOptions) (*AzureTags, error)

NewAzureTags builds the enhancer.

func (*AzureTags) Enhance added in v0.9.0

func (c *AzureTags) Enhance(ctx context.Context, issue enhance.Issue) (*enhance.Enrichment, error)

Enhance implements enhance.Enhancer.

A resource that exists but carries no ownership tags returns an enrichment with no repository rather than an error: that is a final answer, and reporting it as a failure would hold the finding out of sight instead of handing it to a human. Only a lookup that might succeed next time errors.

func (*AzureTags) ID added in v0.9.0

func (c *AzureTags) ID() string

ID implements enhance.Enhancer.

type AzureTagsConfig added in v0.9.0

type AzureTagsConfig struct {
	// ManagementGroup narrows the Resource Graph scope; empty means every
	// subscription the ambient identity can read.
	ManagementGroup string
	// RepositoryHost is the forge host composed into resolved URLs; empty
	// means github.com.
	RepositoryHost string
	// Keys overrides the ownership tag names.
	Keys LabelKeys
}

AzureTagsConfig is one snapshot of the resourceTags capability, as read off the azure Integration at enhance time.

type ConfigSource added in v0.9.0

type ConfigSource func(ctx context.Context) (*AssetConfig, error)

ConfigSource yields the current capability configuration: nil when the capability is off (the enhancer stands aside), an error when it cannot be read (the finding is held and retried rather than advanced without its enrichment).

type DynamicAWS added in v0.9.0

type DynamicAWS struct {
	// Config reads the capability. Required.
	Config AWSConfigSource
	// NewInventory builds an inventory client for a backend; nil means
	// awsinv.New. The seam exists for tests, which must not dial AWS.
	NewInventory func(ctx context.Context, backend awsinv.Config) (AWSInventory, func() error, error)
	// contains filtered or unexported fields
}

DynamicAWS is AWSTags with its configuration read from the Integration CR per enhancement instead of captured at process start. A config change — a different aggregator, a new view — takes effect on the next reconcile without a restart. Only the inventory client is stateful — building one verifies the backend remotely — so it is memoized by backend and swapped (closing the old one) when the backend changes.

func (*DynamicAWS) Close added in v0.9.0

func (d *DynamicAWS) Close() error

Close releases the memoized client, for shutdown.

func (*DynamicAWS) Enhance added in v0.9.0

func (d *DynamicAWS) Enhance(ctx context.Context, issue enhance.Issue) (*enhance.Enrichment, error)

Enhance implements enhance.Enhancer.

func (*DynamicAWS) ID added in v0.9.0

func (*DynamicAWS) ID() string

ID implements enhance.Enhancer. It deliberately reuses AWSTagsID: this is the same enhancer to everything downstream (enrichment attribution, sticky comments, attribute precedence), only its configuration plumbing differs.

type DynamicAzure added in v0.9.0

type DynamicAzure struct {
	// Config reads the capability. Required.
	Config AzureConfigSource
	// NewInventory builds an inventory client for a scope; nil means
	// azureinv.New. The seam exists for tests, which must not dial Azure.
	NewInventory func(ctx context.Context, cfg azureinv.Config) (AzureInventory, func() error, error)
	// contains filtered or unexported fields
}

DynamicAzure is AzureTags with its configuration read from the Integration CR per enhancement instead of captured at process start. A config change — a different management group — takes effect on the next reconcile without a restart. Only the inventory client is stateful — building one verifies the scope remotely — so it is memoized by management group and swapped (closing the old one) when the scope changes.

func (*DynamicAzure) Close added in v0.9.0

func (d *DynamicAzure) Close() error

Close releases the memoized client, for shutdown.

func (*DynamicAzure) Enhance added in v0.9.0

func (d *DynamicAzure) Enhance(ctx context.Context, issue enhance.Issue) (*enhance.Enrichment, error)

Enhance implements enhance.Enhancer.

func (*DynamicAzure) ID added in v0.9.0

func (*DynamicAzure) ID() string

ID implements enhance.Enhancer. It deliberately reuses AzureTagsID: this is the same enhancer to everything downstream (enrichment attribution, sticky comments, attribute precedence), only its configuration plumbing differs.

type DynamicGeneric added in v0.9.1

type DynamicGeneric struct {
	// Configs reads the enabled endpoints. Required.
	Configs GenericConfigSource
	// Limit bounds the outbound calls in flight at once. It is shared across
	// every concurrent enhancement — the reconciler may run several findings
	// in parallel, and each fans out to every endpoint, so the bound must be
	// global rather than per-EnhanceAll (which is why this is a semaphore and
	// not errgroup.SetLimit). Nil means unbounded.
	Limit *semaphore.Weighted
	// Do performs one enhancement call; nil means the internal/generic
	// client. The seam exists for tests, which must not dial anything.
	Do func(ctx context.Context, cfg GenericConfig, req pkggeneric.EnhanceRequest) (*pkggeneric.EnhanceResponse, error)
}

DynamicGeneric fans one enhancement out to every enabled generic integration's endpoint, each call signed with that integration's secret and bounded by its own timeout. Configuration is read per enhancement, the same rule as the cloud wrappers; unlike them there is no client state to memoize — a signed POST is built from scratch every time — so there is no Close.

func (*DynamicGeneric) Enhance added in v0.9.1

Enhance implements enhance.Enhancer vacuously: the chain runner prefers EnhanceAll on anything implementing MultiEnhancer, so this never runs.

func (*DynamicGeneric) EnhanceAll added in v0.9.1

func (d *DynamicGeneric) EnhanceAll(ctx context.Context, issue enhance.Issue) ([]AttributedEnrichment, error)

EnhanceAll implements MultiEnhancer: one signed POST per enabled integration, in parallel under Limit, results ordered by integration name so precedence (first repository wins, first attribute wins) is deterministic rather than list-order or completion-order luck. Per-endpoint failures are joined and returned beside the successes — one slow or broken endpoint must not discard the others' work, only bound it.

func (*DynamicGeneric) ID added in v0.9.1

func (*DynamicGeneric) ID() string

ID implements enhance.Enhancer. The id never attributes an enrichment — EnhanceAll attributes each to its integration — it only names the chain entry in logs.

type DynamicGoogleCloud added in v0.9.0

type DynamicGoogleCloud struct {
	// Config reads the capability. Required.
	Config ConfigSource
	// NewAssets builds an asset client for a scope; nil means gcpasset.New.
	// The seam exists for tests, which must not dial Google.
	NewAssets func(ctx context.Context, scope string) (AssetLabels, func() error, error)
	// contains filtered or unexported fields
}

DynamicGoogleCloud is GoogleCloudLabels with its configuration read from the Integration CR per enhancement instead of captured at process start. A config change — a new scope, different label keys — takes effect on the next reconcile without a restart. Only the asset client is stateful: it holds a gRPC connection, so it is memoized by scope and swapped (closing the old one) when the scope changes.

func (*DynamicGoogleCloud) Close added in v0.9.0

func (d *DynamicGoogleCloud) Close() error

Close releases the memoized client, for shutdown.

func (*DynamicGoogleCloud) Enhance added in v0.9.0

Enhance implements enhance.Enhancer.

func (*DynamicGoogleCloud) ID added in v0.9.0

func (*DynamicGoogleCloud) ID() string

ID implements enhance.Enhancer. It deliberately reuses GoogleCloudLabelsID: this is the same enhancer to everything downstream (enrichment attribution, sticky comments, attribute precedence), only its configuration plumbing differs.

type GenericConfig added in v0.9.1

type GenericConfig struct {
	// Name is the Integration's name — the enrichment attribution.
	Name string
	// URL the enhancement request POSTs to.
	URL string
	// Timeout bounds the call; zero means the client default.
	Timeout time.Duration
	// Secret signs the request body. Left nil when the Secret could not be
	// read, so the failure surfaces on this integration's call rather than
	// taking the whole fan-out down.
	Secret []byte
}

GenericConfig is one generic Integration's enhancer endpoint, as read off the CR (and its Secret) at enhance time.

type GenericConfigSource added in v0.9.1

type GenericConfigSource func(ctx context.Context) ([]GenericConfig, error)

GenericConfigSource yields every enabled generic enhancer endpoint. Empty means the capability is off everywhere (the enhancer stands aside); an error means the list could not be read (the finding is held and retried).

type GoogleCloudLabels added in v0.8.0

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

GoogleCloudLabels resolves a finding's repository from the ownership labels on the Google Cloud resource it was raised against.

It answers only for Google Cloud findings, and it answers only about the repository: ownership by person is a different question, and the CMDB enhancer is the one that knows it.

func NewGoogleCloudLabels added in v0.8.0

func NewGoogleCloudLabels(o GoogleCloudOptions) (*GoogleCloudLabels, error)

NewGoogleCloudLabels builds the enhancer.

func (*GoogleCloudLabels) Enhance added in v0.8.0

Enhance implements enhance.Enhancer.

A resource that exists but carries no ownership labels returns an enrichment with no repository rather than an error: that is a final answer, and reporting it as a failure would hold the finding out of sight instead of handing it to a human. Only a lookup that might succeed next time errors.

func (*GoogleCloudLabels) ID added in v0.8.0

func (*GoogleCloudLabels) ID() string

ID implements enhance.Enhancer.

type GoogleCloudOptions added in v0.8.0

type GoogleCloudOptions struct {
	// Assets looks resources up. Required.
	Assets AssetLabels
	// Keys names the labels to read.
	Keys LabelKeys
	// DefaultHost is the forge host used when a resource names an org and a
	// repository but no host. Empty means github.com, matching the default
	// the Forge resolver already assumes.
	DefaultHost string
	// DefaultProvider is the forge family assumed when a resource names no
	// provider. Empty means github.
	DefaultProvider string
}

GoogleCloudOptions configure the enhancer.

type LabelKeys added in v0.8.0

type LabelKeys struct {
	Org      string
	Name     string
	Provider string
	URL      string
}

LabelKeys names the labels the enhancer reads. Zero values fall back to the defaults, so an operator overrides only what differs from the convention.

type MultiEnhancer added in v0.9.1

type MultiEnhancer interface {
	// EnhanceAll returns every identity's contribution, in precedence
	// order. Partial results beside a non-nil error are meaningful: the
	// runner records both, so one broken endpoint does not discard the
	// others' work.
	EnhanceAll(ctx context.Context, issue enhance.Issue) ([]AttributedEnrichment, error)
}

MultiEnhancer is the internal seam for a chain entry carrying several identities — N generic integrations behind one enhancer. The chain runner type-asserts for it and prefers it over Enhance, so each identity's enrichment stays separately attributed. It is deliberately internal: pkg/enhance stays a one-plugin-one-identity contract.

type StaticFile

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

StaticFile enhances issues from a YAML map of repositories to ownership, attributes, and optional free-form markdown — the stand-in for a CMDB:

repos:
    acme/shop:
        owners: [octocat, hubot]
        attributes:
            system: storefront
            tier: "1"
        markdown: |
            Storefront is PCI-scoped; page #payments-oncall first.

func NewStaticFile

func NewStaticFile(path string) (*StaticFile, error)

NewStaticFile loads the map from path.

func (*StaticFile) Enhance

func (s *StaticFile) Enhance(_ context.Context, issue enhance.Issue) (*enhance.Enrichment, error)

Enhance implements enhance.Enhancer; a repository absent from the map contributes nothing.

func (*StaticFile) ID

func (*StaticFile) ID() string

ID implements enhance.Enhancer.

type TagsOptions added in v0.9.0

type TagsOptions struct {
	// Keys names the tags to read.
	Keys LabelKeys
	// DefaultHost is the forge host used when a resource names an org and a
	// repository but no host. Empty means github.com, matching the default
	// the Forge resolver already assumes.
	DefaultHost string
	// DefaultProvider is the forge family assumed when a resource names no
	// provider. Empty means github.
	DefaultProvider string
}

TagsOptions configure a tag-inventory enhancer; the vocabulary is shared across clouds, so the options are too (the inventory client itself is the per-cloud part, passed beside them).

Jump to

Keyboard shortcuts

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