Documentation
¶
Overview ¶
Package provider defines the Provider interface that every CI platform must implement, along with a global registry so the analyze command can dispatch to the right implementation without hard-coded if/switch chains.
Adding a new provider requires:
- Implement Provider in a new file (e.g. provider/bitbucket.go)
- Call Register(&BitbucketProvider{}) in an init() function
- Declare applicable controls in configuration/registry.go
- Add a Controls() implementation in control/catalog.go
- Add a ProviderConfig field in configuration/plumberconfig.go
Index ¶
- Variables
- func BuildControlStats(providerName, controlName string, result *control.AnalysisResult, ...) []control.StatLine
- func Names() []string
- func Register(p Provider)
- func RegisterStatsBuilder(providerName string, b StatsBuilder)
- type CIEnvMapping
- type GitHubProvider
- func (p *GitHubProvider) BlobURLInfix() string
- func (p *GitHubProvider) CIEnvVars() CIEnvMapping
- func (p *GitHubProvider) ComputeCompliance(result *control.AnalysisResult, conf *configuration.Configuration) (float64, int)
- func (p *GitHubProvider) Controls(pc *configuration.PlumberConfig) []control.ControlEntry
- func (p *GitHubProvider) Name() string
- func (p *GitHubProvider) PostAnalysisActions(_ *cobra.Command, _ *control.AnalysisResult, _ *configuration.Configuration, ...) error
- func (p *GitHubProvider) Run(conf *configuration.Configuration) (*control.AnalysisResult, error)
- func (p *GitHubProvider) RunRemote(conf *configuration.Configuration) (*control.AnalysisResult, error)
- func (p *GitHubProvider) WritePBOM(result *control.AnalysisResult, conf *configuration.Configuration, ...) error
- func (p *GitHubProvider) WritePBOMCycloneDX(result *control.AnalysisResult, conf *configuration.Configuration, ...) error
- type GitLabProvider
- func (p *GitLabProvider) BlobURLInfix() string
- func (p *GitLabProvider) CIEnvVars() CIEnvMapping
- func (p *GitLabProvider) ComputeCompliance(result *control.AnalysisResult, conf *configuration.Configuration) (float64, int)
- func (p *GitLabProvider) Controls(pc *configuration.PlumberConfig) []control.ControlEntry
- func (p *GitLabProvider) Name() string
- func (p *GitLabProvider) PostAnalysisActions(cmd *cobra.Command, result *control.AnalysisResult, ...) error
- func (p *GitLabProvider) Run(conf *configuration.Configuration) (*control.AnalysisResult, error)
- func (p *GitLabProvider) RunRemote(_ *configuration.Configuration) (*control.AnalysisResult, error)
- func (p *GitLabProvider) WritePBOM(result *control.AnalysisResult, conf *configuration.Configuration, ...) error
- func (p *GitLabProvider) WritePBOMCycloneDX(result *control.AnalysisResult, conf *configuration.Configuration, ...) error
- type PostActionSummary
- type Provider
- type StatsBuilder
Constants ¶
This section is empty.
Variables ¶
var ErrNoRemote = errors.New("provider does not support remote analysis")
ErrNoRemote is returned by RunRemote when a provider only supports local analysis (e.g. GitLab, which always fetches via its own API).
Functions ¶
func BuildControlStats ¶
func BuildControlStats(providerName, controlName string, result *control.AnalysisResult, pc *configuration.PlumberConfig, findings []opaengine.Finding) []control.StatLine
BuildControlStats invokes the registered StatsBuilder for providerName. Returns nil when no builder is registered.
func Register ¶
func Register(p Provider)
Register adds p to the global registry. It is typically called from an init() function in the provider's implementation file. Panics if a provider with the same name is already registered.
func RegisterStatsBuilder ¶
func RegisterStatsBuilder(providerName string, b StatsBuilder)
RegisterStatsBuilder associates a StatsBuilder with a provider name. It is called from cmd/ init functions to avoid import cycles.
Types ¶
type CIEnvMapping ¶
type CIEnvMapping struct {
// ServerURL is the env var that holds the base URL of the forge server
// (e.g. "CI_SERVER_URL" for GitLab, "GITHUB_SERVER_URL" for GitHub).
ServerURL string
// RepoPath is the env var that holds the project path (e.g.
// "CI_PROJECT_PATH" / "GITHUB_REPOSITORY").
RepoPath string
// CommitSHA is the env var that holds the commit SHA (e.g.
// "CI_COMMIT_SHA" / "GITHUB_SHA").
CommitSHA string
}
CIEnvMapping describes the CI environment variables a provider sets so the location linker can build stable source links anchored to the commit that triggered the analysis.
type GitHubProvider ¶
type GitHubProvider struct{}
GitHubProvider implements Provider for GitHub Actions.
func (*GitHubProvider) BlobURLInfix ¶
func (p *GitHubProvider) BlobURLInfix() string
func (*GitHubProvider) CIEnvVars ¶
func (p *GitHubProvider) CIEnvVars() CIEnvMapping
func (*GitHubProvider) ComputeCompliance ¶
func (p *GitHubProvider) ComputeCompliance(result *control.AnalysisResult, conf *configuration.Configuration) (float64, int)
func (*GitHubProvider) Controls ¶
func (p *GitHubProvider) Controls(pc *configuration.PlumberConfig) []control.ControlEntry
func (*GitHubProvider) Name ¶
func (p *GitHubProvider) Name() string
func (*GitHubProvider) PostAnalysisActions ¶
func (p *GitHubProvider) PostAnalysisActions(_ *cobra.Command, _ *control.AnalysisResult, _ *configuration.Configuration, _ PostActionSummary) error
func (*GitHubProvider) Run ¶
func (p *GitHubProvider) Run(conf *configuration.Configuration) (*control.AnalysisResult, error)
func (*GitHubProvider) RunRemote ¶
func (p *GitHubProvider) RunRemote(conf *configuration.Configuration) (*control.AnalysisResult, error)
func (*GitHubProvider) WritePBOM ¶
func (p *GitHubProvider) WritePBOM(result *control.AnalysisResult, conf *configuration.Configuration, filePath string, score *control.PlumberScoreResult, scoreMode bool) error
func (*GitHubProvider) WritePBOMCycloneDX ¶
func (p *GitHubProvider) WritePBOMCycloneDX(result *control.AnalysisResult, conf *configuration.Configuration, filePath string, score *control.PlumberScoreResult, scoreMode bool) error
type GitLabProvider ¶
type GitLabProvider struct{}
GitLabProvider implements Provider for GitLab CI/CD.
func (*GitLabProvider) BlobURLInfix ¶
func (p *GitLabProvider) BlobURLInfix() string
func (*GitLabProvider) CIEnvVars ¶
func (p *GitLabProvider) CIEnvVars() CIEnvMapping
func (*GitLabProvider) ComputeCompliance ¶
func (p *GitLabProvider) ComputeCompliance(result *control.AnalysisResult, conf *configuration.Configuration) (float64, int)
func (*GitLabProvider) Controls ¶
func (p *GitLabProvider) Controls(pc *configuration.PlumberConfig) []control.ControlEntry
func (*GitLabProvider) Name ¶
func (p *GitLabProvider) Name() string
func (*GitLabProvider) PostAnalysisActions ¶
func (p *GitLabProvider) PostAnalysisActions(cmd *cobra.Command, result *control.AnalysisResult, conf *configuration.Configuration, s PostActionSummary) error
func (*GitLabProvider) Run ¶
func (p *GitLabProvider) Run(conf *configuration.Configuration) (*control.AnalysisResult, error)
func (*GitLabProvider) RunRemote ¶
func (p *GitLabProvider) RunRemote(_ *configuration.Configuration) (*control.AnalysisResult, error)
func (*GitLabProvider) WritePBOM ¶
func (p *GitLabProvider) WritePBOM(result *control.AnalysisResult, conf *configuration.Configuration, filePath string, score *control.PlumberScoreResult, scoreMode bool) error
func (*GitLabProvider) WritePBOMCycloneDX ¶
func (p *GitLabProvider) WritePBOMCycloneDX(result *control.AnalysisResult, conf *configuration.Configuration, filePath string, score *control.PlumberScoreResult, scoreMode bool) error
type PostActionSummary ¶
type PostActionSummary struct {
Passed bool
GateLine string
Score *control.PlumberScoreResult
ScoreMode bool
ScorePoint bool
}
PostActionSummary bundles the gate outcome needed by PostAnalysisActions to avoid exceeding the parameter count limit. Passed is the active gate's verdict; GateLine is its human-readable rendering for the MR comment.
type Provider ¶
type Provider interface {
// Name returns the canonical provider identifier ("gitlab", "github", …).
Name() string
// Controls returns the ordered catalog of controls for this provider.
// The returned entries drive the compliance table and the per-control
// rendering sections.
Controls(pc *configuration.PlumberConfig) []control.ControlEntry
// ComputeCompliance derives the overall compliance percentage and the
// number of non-skipped controls that were evaluated from result.
ComputeCompliance(result *control.AnalysisResult, conf *configuration.Configuration) (compliance float64, controlCount int)
// Run executes the analysis for this provider using the local clone or
// the provider's API, depending on conf.
Run(conf *configuration.Configuration) (*control.AnalysisResult, error)
// RunRemote fetches the pipeline from a remote API and runs analysis.
// Returns ErrNoRemote when the provider does not support this mode.
RunRemote(conf *configuration.Configuration) (*control.AnalysisResult, error)
// WritePBOM writes a Pipeline Bill of Materials to filePath in the
// provider's native PBOM format.
WritePBOM(result *control.AnalysisResult, conf *configuration.Configuration, filePath string, score *control.PlumberScoreResult, scoreMode bool) error
// WritePBOMCycloneDX writes the PBOM in CycloneDX format.
WritePBOMCycloneDX(result *control.AnalysisResult, conf *configuration.Configuration, filePath string, score *control.PlumberScoreResult, scoreMode bool) error
// PostAnalysisActions runs provider-specific post-analysis side-effects
// such as posting MR comments or updating the project badge. Providers
// that have no post-analysis actions return nil.
PostAnalysisActions(cmd *cobra.Command, result *control.AnalysisResult, conf *configuration.Configuration, s PostActionSummary) error
// BlobURLInfix returns the URL segment between the repository base URL
// and the file path when building clickable source links.
// Example: GitLab "/-/blob/", GitHub "/blob/".
BlobURLInfix() string
// CIEnvVars returns the mapping of CI environment variables used to
// build stable source links when running inside a CI pipeline.
CIEnvVars() CIEnvMapping
}
Provider is the contract every CI platform must satisfy. The analyze command resolves the active provider via Get() and delegates all provider-specific logic through this interface, keeping the shared pipeline (compliance calculation, output rendering, artifact writing) provider-agnostic.
type StatsBuilder ¶
type StatsBuilder func(controlName string, result *control.AnalysisResult, pc *configuration.PlumberConfig, findings []opaengine.Finding) []control.StatLine
StatsBuilder computes the stat lines displayed above the findings block for a single control. It is registered separately from the Provider interface because the implementation often depends on cmd-internal helpers that would create import cycles if embedded in the interface. cmd/ registers the builder via RegisterStatsBuilder during init.