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
- type AWSConfigSource
- type AWSInventory
- type AWSTags
- type AWSTagsConfig
- type AssetConfig
- type AssetLabels
- type AzureConfigSource
- type AzureInventory
- type AzureTags
- type AzureTagsConfig
- type ConfigSource
- type DynamicAWS
- type DynamicAzure
- type DynamicGoogleCloud
- type GoogleCloudLabels
- type GoogleCloudOptions
- type LabelKeys
- type StaticFile
- type TagsOptions
Constants ¶
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.
const AWSTagsID = "aws-resource-tags"
AWSTagsID is the enhancer's id.
const AzureTagsID = "azure-resource-tags"
AzureTagsID is the enhancer's id.
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
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
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.
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 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
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
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.
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 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
func (d *DynamicGoogleCloud) Enhance(ctx context.Context, issue enhance.Issue) (*enhance.Enrichment, error)
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 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
func (g *GoogleCloudLabels) Enhance(ctx context.Context, issue enhance.Issue) (*enhance.Enrichment, error)
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
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 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.
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).