Documentation
¶
Overview ¶
Package source is the one definition of where the code of a platform code scan comes from: a repository, a branch and the exact commit to scan. The platform puts a Repository in the job it hands a sensor; the sensor fetches exactly that commit, read-only, and refuses anything this package refuses. Both sides validate with the same code, so a sensor never fetches what the platform would not have sent.
A Repository carries no secret. Credential names the credential the sensor asks the platform for when it starts the job (a short-lived, read-only token for this one repository); the token itself never travels in the job and is never stored with it.
Index ¶
Constants ¶
const ( KindGitHub = "github" KindGitLab = "gitlab" KindBitbucket = "bitbucket" KindAzure = "azure" // KindGit is any other HTTPS git server (a public repository, or one // the sensor's operator configured a credential for). KindGit = "git" )
SCM kinds.
const ( MaxURLLength = 2048 MaxBranchLength = 255 // MaxDepth bounds a history fetch. MaxDepth = 10000 )
Limits.
Variables ¶
var ErrInvalid = errors.New("source: invalid repository")
ErrInvalid wraps every validation error.
Functions ¶
func CheckCloneURL ¶
CheckCloneURL refuses anything but a plain HTTPS repository URL: scheme https, a DNS host name (an IP address is refused; the platform names the SCM host it holds a credential for), an optional port, no user information, query or fragment, and a path of ordinary segments (no "..", no segment starting with '-' or '.', which git or a server could read as an option or a hidden path).
func ValidBranch ¶
ValidBranch reports whether b is a branch name that is safe to pass to git as a ref: the rules of git check-ref-format for a branch, plus no leading '-' (an option) and at most MaxBranchLength bytes.
Types ¶
type Repository ¶
type Repository struct {
// Kind is the SCM the repository lives in (Kind* constants). It tells
// the platform how to mint the credential; the fetch is plain git over
// HTTPS for every kind.
Kind string `json:"kind"`
// CloneURL is the HTTPS URL of the repository: no user information,
// query or fragment, a host name (not an address), an optional port.
CloneURL string `json:"clone_url"`
// Branch is the branch the commit belongs to (a protected branch).
Branch string `json:"branch"`
// Commit is the full commit id (40 or 64 lower-case hex characters) to
// scan. The fetch fails when the branch head is another commit only if
// the commit itself cannot be fetched; the scan is always of Commit.
Commit string `json:"commit"`
// Depth is the history to fetch: 1 (the default, 0 means 1) or up to
// MaxDepth commits for scans that read history (secrets in history).
Depth int `json:"depth,omitempty"`
// Credential names the credential the sensor asks the platform for
// ("" for a public repository fetched anonymously). A name, never a
// value.
Credential string `json:"credential,omitempty"`
// Capabilities are the capability references to run on the checkout
// ("sast.code@1", "secrets.code@1", "sca.deps@1", "iac.misconfig@1"):
// each must take a repository as input.
Capabilities []string `json:"capabilities"`
}
Repository is the source of a code scan.
func (Repository) Host ¶
func (r Repository) Host() string
Host returns the host (and port) of CloneURL, "" when it cannot be read.
func (*Repository) Normalize ¶
func (r *Repository) Normalize()
Normalize trims the fields, lower-cases the kind, the host and the commit, and defaults Depth to 1. Validate calls it.
func (*Repository) Validate ¶
func (r *Repository) Validate() error
Validate normalizes r and checks every field. The error wraps ErrInvalid and names the field; it never echoes a URL's user information.