Documentation
¶
Overview ¶
Package publish delivers rendered reports (report.Artifact) to destinations. A Publisher is the "where" of reporting, separate from the Reporter (the "what", pkg/report). So a scan can render several formats once and deliver them to several destinations.
Each publisher is configured from a saga.PublisherConfig and named by its kind; Kinds lists the built-in set.
Index ¶
- Constants
- Variables
- func APIPublishers(cfgs []saga.PublisherConfig) []saga.PublisherConfig
- func Accepts(kind string) ([]string, bool)
- func Distinguishes(kind string) string
- func DistinguishingValue(cfg saga.PublisherConfig) string
- func IssueKind(kind string) bool
- func Kinds() []string
- func Local(kind string) bool
- func Reads(kind string) []string
- func Renders(kind string) []string
- func Requires(kind string) []string
- func Run(ctx context.Context, publishers []saga.PublisherConfig, data report.Data) error
- func Unread(cfg saga.PublisherConfig) []string
- func Untracked(model *saga.Model) []string
- type APIDestination
- type PolicyClient
- type Publisher
- type RunPublisher
Constants ¶
const DiffMarker = defaultDiffPRMarker
DiffMarker identifies the sticky comment `draugr diff --publish` maintains.
Exported so the diff command asks for it by name rather than restating the string. It is deliberately not the marker a Saga's PR-comment publisher uses: a run that posts both a report and a delta wants two comments, not one that overwrites the other.
const ReportMarker = defaultPRMarker
ReportMarker identifies the sticky comment a Saga's PR-comment publisher maintains.
Variables ¶
var ErrNoPolicyCheck = errors.New("the server checks no organization policy")
ErrNoPolicyCheck is a server that answers the run API and judges no policy. It is not a failure of the run: there is nothing to check against.
var GitLabIssueTypes = []string{"issue", "incident", "task"}
GitLabIssueTypes are the values `item.type` takes on a gitlab-issue entry. GitLab's fourth, test_case, needs Ultimate.
Functions ¶
func APIPublishers ¶ added in v0.149.0
func APIPublishers(cfgs []saga.PublisherConfig) []saga.PublisherConfig
APIPublishers are the draugr-api destinations a descriptor publishes to.
func Accepts ¶ added in v0.151.0
Accepts returns the report formats kind delivers, and whether it delivers only those. A kind that delivers any format returns nil and false.
func Distinguishes ¶ added in v0.117.0
Distinguishes returns the field that makes a second entry of kind a second destination, empty for a kind this build does not have.
func DistinguishingValue ¶ added in v0.117.0
func DistinguishingValue(cfg saga.PublisherConfig) string
DistinguishingValue returns what cfg wrote in the field that tells two entries of its kind apart.
What the descriptor wrote, not what it resolves to. `repo`, `pr` and `url` all default from the environment, so two entries that write nothing are the same entry twice however they resolve, and that is the case worth catching.
func IssueKind ¶ added in v0.140.0
IssueKind reports whether kind keeps a tracking item, and so reads the issue fields (see issueFields).
func Local ¶ added in v0.135.0
Local reports whether kind delivers to this machine. A kind this build does not have is not local.
func Reads ¶ added in v0.151.0
Reads returns the descriptor fields kind reads besides `kind`, nil for a kind this build does not have.
func Renders ¶ added in v0.118.0
Renders returns the formats kind produces for itself, nil for a kind with none and for one this build does not have.
func Run ¶
Run renders each configured report format once, then delivers every rendered artifact to every configured publisher. It returns the first error encountered; a publisher that fails does not prevent the others from being attempted.
func Unread ¶ added in v0.151.0
func Unread(cfg saga.PublisherConfig) []string
Unread returns the fields cfg writes that its kind does not read, in the order PublisherConfig declares them.
func Untracked ¶ added in v0.140.0
Untracked lists the declared components that no issue entry's selection covers, in declaration order, and nil when the descriptor has no issue entry or every entry covers every component.
A component left out of every selection has findings that fail the gate and open no item, which looks the same from the forge as a component with nothing to report.
Types ¶
type APIDestination ¶ added in v0.149.0
APIDestination is the server a draugr-api publisher sends a run to, and the token it sends.
func ResolveAPI ¶ added in v0.149.0
func ResolveAPI(cfg saga.PublisherConfig) (dest APIDestination, skip string, err error)
ResolveAPI finds where a draugr-api publisher would send a run, the way the publisher does.
Neither an endpoint nor a token is somebody running the descriptor locally, which is not a mistake: skip says why there is nowhere to send. One without the other is a mistake, and an error.
type PolicyClient ¶ added in v0.149.0
type PolicyClient struct {
// contains filtered or unexported fields
}
PolicyClient asks a draugr-api server what the organization's policy makes of a descriptor.
func NewPolicyClient ¶ added in v0.149.0
func NewPolicyClient() PolicyClient
NewPolicyClient is a client that retries the way the publisher does.
func (PolicyClient) Check ¶ added in v0.149.0
func (c PolicyClient) Check(ctx context.Context, dest APIDestination, effective string) (skald.PolicyOutcome, error)
Check sends the effective descriptor to the server's pre-flight and returns its outcome.
The server judges and words every verdict, so this carries no rule logic. A server with no policy check answers 404, and that is ErrNoPolicyCheck rather than an error of the run.
type Publisher ¶
type Publisher interface {
// Kind is the publisher's config selector, e.g. "file".
Kind() string
// Publish delivers the artifacts. A publisher may use only the artifacts it cares about
// (e.g. a code-scanning publisher would take the SARIF one), ignoring the rest.
Publish(ctx context.Context, artifacts []report.Artifact) error
}
Publisher delivers rendered report artifacts to one destination.
type RunPublisher ¶ added in v0.140.0
type RunPublisher interface {
Publisher
// PublishRun delivers from the run's data, with the same artifacts Publish would receive.
PublishRun(ctx context.Context, data report.Data, artifacts []report.Artifact) error
}
RunPublisher is a Publisher whose delivery depends on the run itself, not only on what was rendered from it. An issue publisher is one: whether to open, update or close an item follows the gate, and what the item lists follows the findings.
Run calls PublishRun in place of Publish when the built publisher implements it.