Documentation
¶
Overview ¶
Package scan runs the detector over every object of a repository and attributes what it finds to commits, paths and refs.
Index ¶
- func AnnotateLocal(results []Result, local map[string][]string)
- func Describe(r Result) string
- func Revoke(ctx context.Context, results []Result, tokens []Finding, ...) (int, error)
- func SortFindings(fs []Finding)
- type Finding
- type Location
- type Options
- type Result
- type Revocation
- type Rewrite
- type RunOptions
- type Stats
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnnotateLocal ¶ added in v0.2.0
AnnotateLocal marks every finding whose token is also configured on this machine, given the sources per fingerprint.
func Revoke ¶ added in v0.2.0
func Revoke(ctx context.Context, results []Result, tokens []Finding, revoker *detect.Revoker, verifier *detect.Verifier) (int, error)
Revoke asks GitHub to revoke the given tokens, checks each one again and records the outcome on every finding of that token in results. It returns the number of tokens GitHub confirmed dead.
func SortFindings ¶
func SortFindings(fs []Finding)
SortFindings orders active tokens first, then by kind and fingerprint.
Types ¶
type Finding ¶
type Finding struct {
Kind detect.Kind `json:"kind"`
Fingerprint string `json:"fingerprint"`
Token string `json:"-"`
Redacted string `json:"token"`
ChecksumVerified bool `json:"checksum_verified"`
Verification *detect.Verification `json:"verification,omitempty"`
// Revocation records what happened when patty asked GitHub to revoke the token.
Revocation Revocation `json:"revocation,omitempty"`
// Local lists where the same token is configured on this machine.
Local []string `json:"local,omitempty"`
Locations []Location `json:"locations"`
// Occurrences counts objects the token appears in, across all locations.
Occurrences int `json:"occurrences"`
}
Finding is one distinct token and everywhere it appears.
func Merge ¶ added in v0.2.0
Merge groups the findings of all results by token, so a token that leaked into several repositories is one entry with every location. Active tokens come first.
func Revocable ¶ added in v0.2.0
Revocable returns the distinct active tokens across results that GitHub's revocation endpoint accepts, active ones first.
type Location ¶
type Location struct {
Repo string `json:"repo"`
Object string `json:"object"`
ObjectType string `json:"object_type"`
Path string `json:"path,omitempty"`
Line int `json:"line"`
Commit *gitrepo.Commit `json:"commit,omitempty"`
// Refs contains the refs whose history includes the commit.
Refs []string `json:"refs,omitempty"`
// Orphaned is true when no ref reaches the commit anymore.
Orphaned bool `json:"orphaned"`
// Rewrite explains how the commit went unreachable on the server, when known.
Rewrite string `json:"rewrite,omitempty"`
}
Location is one place a token was found.
type Options ¶
type Options struct {
// Workers is the number of parallel `git cat-file` readers.
Workers int
// MaxObject skips objects larger than this many bytes.
MaxObject int64
// Ignore holds token fingerprints to leave out of the results.
Ignore map[string]bool
// Verifier, when set, checks each token against the GitHub API.
Verifier *detect.Verifier
}
Options tune a repository scan.
type Result ¶
type Result struct {
Target string `json:"target"`
Findings []Finding `json:"findings"`
Stats Stats `json:"stats"`
Notes []string `json:"notes,omitempty"`
Err error `json:"-"`
Error string `json:"error,omitempty"`
Skipped bool `json:"skipped,omitempty"`
}
Result is the outcome for one target.
type Revocation ¶ added in v0.2.0
type Revocation string
Revocation is the outcome of asking GitHub to revoke a token.
const ( // RevocationDone means GitHub accepted the request and no longer honours the token. RevocationDone Revocation = "revoked" // RevocationPending means GitHub accepted the request but still answered // the follow-up check as active; revocations are processed asynchronously. RevocationPending Revocation = "pending" // RevocationUnsupported means the token family cannot be revoked through the API. RevocationUnsupported Revocation = "unsupported" )
type Rewrite ¶
Rewrite names a commit that was fetched by SHA because a server-side ref update (force push, branch deletion) had made it unreachable.
type RunOptions ¶
type RunOptions struct {
Options
// Cache holds the mirrors of GitHub targets.
Cache *disk.Cache
// Keep leaves mirrors in the cache after the scan for faster re-runs.
Keep bool
// Auth is used for HTTPS clones; nil for anonymous.
Auth *gitrepo.Auth
// GitHub is needed for the activity feed; nil disables it.
GitHub *github.Client
// Rewrites fetches commits the activity feed reports as force-pushed or deleted.
Rewrites bool
// ActivityPages caps the activity feed pages read per type and repository.
ActivityPages int
// Parallel is the number of repositories processed at once.
Parallel int
// Progress receives phase messages; may be nil.
Progress func(target, msg string)
}
RunOptions configure a run over many targets.
type Stats ¶
type Stats struct {
Objects int `json:"objects"`
Scanned int `json:"scanned"`
Skipped int `json:"skipped_large"`
Bytes int64 `json:"bytes"`
Refs int `json:"refs"`
Orphaned int `json:"orphaned_commits"`
Rewrites int `json:"rewrites_fetched"`
Disk int64 `json:"disk_bytes,omitempty"`
Duration time.Duration `json:"-"`
}
Stats summarises one repository scan.