publish

package
v0.181.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 38 Imported by: 1 module, 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 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

View Source
const DefaultPolicyWait = 5 * time.Minute

DefaultPolicyWait is how long a scan waits, by default, for the servers' verdict on the run it published.

View Source
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.

View Source
const ReportMarker = defaultPRMarker

ReportMarker identifies the sticky comment a Saga's PR-comment publisher maintains.

Variables

View Source
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.

View Source
var ErrOriginRefused = errors.New("not an allowed origin")

ErrOriginRefused is a url, written in the descriptor or in the project's draugr.config.yaml, that names a server the environment does not allow.

View Source
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 APIURLSet added in v0.155.1

func APIURLSet() bool

APIURLSet reports whether the environment names a draugr-api server.

func Accepts added in v0.151.0

func Accepts(kind string) ([]string, bool)

Accepts returns the report formats kind delivers, and whether it delivers only those. A kind that delivers any format returns nil and false.

func CheckCredential added in v0.155.1

func CheckCredential(cfg saga.PublisherConfig) error

CheckCredential reports whether the environment refuses a publisher entry its credential: a `tokenEnv` it does not list, or, for draugr-api, a url it does not allow or a destination that is half configured. Nothing is sent, so a scan can ask before any scanner runs rather than learn it at the end.

func Distinguishes added in v0.117.0

func Distinguishes(kind string) string

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 ExceptAPI added in v0.158.0

func ExceptAPI(cfgs []saga.PublisherConfig) []saga.PublisherConfig

ExceptAPI is every publisher Judge does not deliver to.

func IssueKind added in v0.140.0

func IssueKind(kind string) bool

IssueKind reports whether kind keeps a tracking item, and so reads the issue fields (see issueFields).

func Judge added in v0.158.0

func Judge(ctx context.Context, publishers []saga.PublisherConfig, data report.Data, wait time.Duration) (*skald.PolicyCheck, error)

Judge delivers the run to each draugr-api publisher, and waits up to wait, in all, for the servers' verdict on the run's findings. One limit rather than one per server, so the time a pipeline spends waiting is the time the flag says, however many servers the descriptor names. The verdicts are combined the way the pre-flight combines its checks: the strongest outcome, every verdict, and every reason a server could not be asked.

A server decides a policy over findings only once they arrive, so these publishers go before every other: what they answer is what the console, the artifacts and the rest of the publishers then report. The check is nil where no server that judges policy received the run.

The error is a publishing failure only. A policy that fails the run is in the check, and the caller decides what it does to the gate, so the failure is not reported twice.

func Kinds

func Kinds() []string

Kinds lists the available publisher kinds, sorted.

func Local added in v0.135.0

func Local(kind string) bool

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

func Reads(kind string) []string

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

func Renders(kind string) []string

Renders returns the formats kind produces for itself, nil for a kind with none and for one this build does not have.

func Requires added in v0.116.0

func Requires(kind string) []string

Requires returns the fields kind cannot run without.

func Run

func Run(ctx context.Context, publishers []saga.PublisherConfig, data report.Data) error

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

func Untracked(model *saga.Model) []string

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

type APIDestination struct {
	Endpoint string
	Token    string
	// Login is the person's login the token came from, nil for a token from the environment. Only
	// ResolvePolicyAPI sets it, so only a policy check carries one.
	Login *login.Login
	// Project is the descriptor's project, which a login's policy check names in its path. A
	// token from the environment is an ingest token, bound to one project by the server, and the
	// check it makes names none.
	Project string
}

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.

The server comes from the environment: $DRAUGR_API_URL, else publish.apiUrl in the machine's configuration. A url written in the descriptor, or in the project's own draugr.config.yaml, is a value that changes by pull request in the repository being scanned, so it is used only where its origin is the environment's, or one $DRAUGR_API_ORIGINS lists. Otherwise the token would go to whichever server the most recent change to the repository named.

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. So is a token bound for a url the environment does not allow, an *OriginRefusedError, and a token bound for a server reached without TLS.

func ResolvePolicyAPI added in v0.158.0

func ResolvePolicyAPI(cfg saga.PublisherConfig, logins login.Store, now time.Time) (dest APIDestination, skip string, err error)

ResolvePolicyAPI finds where a policy check is sent and the token it carries, the way ResolveAPI does, with one addition: where the environment holds no token, the person's login for the server's origin, from logins, takes its place.

A token in the environment is the pipeline's, and wins whenever it is set. A login's token goes only to the origin that issued it, so a url the descriptor names is allowed where logins holds a login for its origin: the token it would carry is that server's own. A nil logins, which is what a pipeline passes, is ResolveAPI.

The draugr-api publisher resolves with ResolveAPI and never reads logins. A login is check-only, and a person's sign-in must not be able to publish a run.

type OriginRefusedError added in v0.155.1

type OriginRefusedError struct {
	// Field says where the refused url was written.
	Field string
	// URL is the refused address.
	URL string
	// Endpoint is the address the environment names, and EndpointFrom where it was read. Both are
	// empty where the environment names none.
	Endpoint, EndpointFrom string
}

OriginRefusedError is a url the token may not be sent to, and what it was compared with.

func (*OriginRefusedError) Error added in v0.155.1

func (e *OriginRefusedError) Error() string

func (*OriginRefusedError) Is added in v0.155.1

func (e *OriginRefusedError) Is(target error) bool

Is makes the error match ErrOriginRefused.

func (*OriginRefusedError) Reason added in v0.155.1

func (e *OriginRefusedError) Reason() string

Reason is the refusal as a policy check's "not checked" reason.

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 pipeline's ingest token is bound to its own project, so its check goes to the ingest route and names none, and a server with no policy check answers it 404, which is ErrNoPolicyCheck rather than an error of the run. A person's token, from a login or set in the environment, is accepted only on the route naming a project, where a 404 is a project the token cannot reach: an error naming it, never a server with nothing to check.

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.

func For

func For(cfg saga.PublisherConfig) (Publisher, error)

For resolves a configured publisher, validating its kind and required fields. The constructor is given only the fields its kind reads (see reads).

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.

Jump to

Keyboard shortcuts

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