Documentation
¶
Index ¶
- Constants
- Variables
- func ResolveRemote(ctx context.Context, platform scm.Platform, source string) (scm.Platform, string)
- type ActionsOptions
- type DateRangeOptions
- type File
- type Files
- type Fragment
- type FragmentsFunc
- type Git
- type GitCmd
- func NewGitDiffCmd(source string, staged bool) (*GitCmd, error)deprecated
- func NewGitDiffCmdContext(ctx context.Context, source string, staged bool) (*GitCmd, error)
- func NewGitLogCmd(source string, logOpts string) (*GitCmd, error)deprecated
- func NewGitLogCmdContext(ctx context.Context, source string, logOpts string) (*GitCmd, error)
- func (c *GitCmd) DiffFilesCh() <-chan *gitdiff.File
- func (c *GitCmd) ErrCh() <-chan error
- func (c *GitCmd) NewBlobReader(commit, path string) (io.ReadCloser, error)deprecated
- func (c *GitCmd) NewBlobReaderContext(ctx context.Context, commit, path string) (io.ReadCloser, error)
- func (c *GitCmd) String() string
- func (c *GitCmd) Wait() error
- type GitHub
- type GitHubResourceSet
- type GitHubResourceType
- type GitLab
- type GitLabResourceSet
- type GitLabResourceType
- type HuggingFace
- type HuggingFaceRepoKind
- type HuggingFaceResourceSet
- type HuggingFaceResourceType
- type ParallelGit
- type ParsedGitHubURL
- type ParsedGitLabURL
- type ParsedHuggingFaceURL
- type S3
- type ScanTarget
- type SkipFunc
- type Source
- type Stdin
Constants ¶
const ( // Universal AttrPath = "path" AttrURL = "url" // Resource Key AttrResource = "resource" // Resource values — what kind of thing the fragment is. ResourceFileContent = "fs.content" ResourceGitPatchContent = "git.patch_content" ResourceGitHubRepo = "github.repository" ResourceGitHubIssue = "github.issue" ResourceGitHubPR = "github.pr" ResourceGitHubComment = "github.comment" ResourceGitHubActions = "github.actions" ResourceGitHubDiscussion = "github.discussion" ResourceGitHubRelease = "github.release" ResourceGitHubReleaseAsset = "github.release_asset" ResourceGitHubGist = "github.gist" ResourceGitLabProject = "gitlab.project" ResourceGitLabIssue = "gitlab.issue" ResourceGitLabMR = "gitlab.mr" ResourceGitLabComment = "gitlab.comment" ResourceGitLabSnippet = "gitlab.snippet" ResourceGitLabRelease = "gitlab.release" ResourceGitLabReleaseAsset = "gitlab.release_asset" ResourceGitLabCIJob = "gitlab.ci_job" ResourceGitLabCIArtifact = "gitlab.ci_artifact" ResourceHuggingFaceRepo = "huggingface.repository" ResourceHuggingFaceDiscussion = "huggingface.discussion" ResourceHuggingFacePR = "huggingface.pr" ResourceHuggingFaceComment = "huggingface.comment" ResourceHuggingFaceBucket = "huggingface.bucket" // Git AttrGitSHA = "git.sha" AttrGitAuthorName = "git.author_name" AttrGitAuthorEmail = "git.author_email" AttrGitDate = "git.date" AttrGitMessage = "git.message" AttrGitRemoteURL = "git.remote_url" AttrGitPlatform = "git.platform" // Filesystem AttrFSSymlink = "fs.symlink" // GitHub AttrGitHubOwner = "github.owner" AttrGitHubOwnerType = "github.owner_type" AttrGitHubRepo = "github.repo" AttrGitHubRepoURL = "github.repo_url" AttrGitHubVisibility = "github.visibility" AttrGitHubIssueNumber = "github.issue.number" AttrGitHubPRNumber = "github.pr.number" AttrGitHubCommentID = "github.comment.id" AttrGitHubActionsRunID = "github.actions.run_id" AttrGitHubActionsRunName = "github.actions.run_name" AttrGitHubActionsRunURL = "github.actions.run_url" AttrGitHubActionsEvent = "github.actions.event" AttrGitHubDiscussionNumber = "github.discussion.number" AttrGitHubReleaseTag = "github.release.tag" AttrGitHubReleaseAssetName = "github.release.asset_name" AttrGitHubGistID = "github.gist.id" AttrGitHubGistFilename = "github.gist.filename" AttrGitHubGistOwner = "github.gist.owner" // GitLab AttrGitLabProjectID = "gitlab.project.id" AttrGitLabProjectPath = "gitlab.project.path" AttrGitLabProjectURL = "gitlab.project.url" AttrGitLabVisibility = "gitlab.visibility" AttrGitLabNamespace = "gitlab.namespace" AttrGitLabIssueIID = "gitlab.issue.iid" AttrGitLabMRIID = "gitlab.mr.iid" AttrGitLabCommentID = "gitlab.comment.id" AttrGitLabSnippetID = "gitlab.snippet.id" AttrGitLabSnippetFilename = "gitlab.snippet.filename" AttrGitLabReleaseTag = "gitlab.release.tag" AttrGitLabReleaseAssetName = "gitlab.release.asset_name" AttrGitLabCIJobID = "gitlab.ci_job.id" AttrGitLabCIJobName = "gitlab.ci_job.name" AttrGitLabCIPipelineID = "gitlab.ci_pipeline.id" // Hugging Face AttrHuggingFaceOwner = "huggingface.owner" AttrHuggingFaceRepo = "huggingface.repo" AttrHuggingFaceRepoType = "huggingface.repo_type" AttrHuggingFaceRepoURL = "huggingface.repo_url" AttrHuggingFaceVisibility = "huggingface.visibility" AttrHuggingFaceDiscussionNumber = "huggingface.discussion.number" AttrHuggingFaceCommentID = "huggingface.comment.id" AttrHuggingFaceAuthor = "huggingface.author" AttrHuggingFaceCommunityResource = "huggingface.community.resource" AttrHuggingFaceBucket = "huggingface.bucket" AttrHuggingFaceBucketURL = "huggingface.bucket_url" AttrHuggingFaceBucketPath = "huggingface.bucket.path" AttrHuggingFaceBucketSize = "huggingface.bucket.size" AttrHuggingFaceBucketMTime = "huggingface.bucket.mtime" AttrHuggingFaceBucketXetHash = "huggingface.bucket.xet_hash" // S3 (and S3-compatible object stores) AttrS3Bucket = "s3.bucket" AttrS3Key = "s3.key" AttrS3Region = "s3.region" AttrS3Endpoint = "s3.endpoint" AttrS3LastModified = "s3.last_modified" AttrS3ETag = "s3.etag" AttrS3Size = "s3.size" AttrS3StorageClass = "s3.storage_class" ResourceS3Object = "s3.object" )
const InnerPathSeparator = "!"
Variables ¶
var AllGitHubResourceTypes = []GitHubResourceType{ GitHubResourceTypeRepos, GitHubResourceTypeForks, GitHubResourceTypePRs, GitHubResourceTypePRComments, GitHubResourceTypeIssues, GitHubResourceTypeIssueComments, GitHubResourceTypeActions, GitHubResourceTypeActionArtifacts, GitHubResourceTypeDiscussions, GitHubResourceTypeReleases, GitHubResourceTypeReleaseAssets, GitHubResourceTypeGists, }
AllGitHubResourceTypes is the canonical list of valid GitHub resource types.
var AllGitLabResourceTypes = []GitLabResourceType{ GitLabResourceTypeRepos, GitLabResourceTypeForks, GitLabResourceTypeMRs, GitLabResourceTypeMRComments, GitLabResourceTypeIssues, GitLabResourceTypeIssueComments, GitLabResourceTypeSnippets, GitLabResourceTypeReleases, GitLabResourceTypeReleaseAssets, GitLabResourceTypeCIJobs, GitLabResourceTypeCIArtifacts, }
AllGitLabResourceTypes is the canonical list of valid GitLab resource types.
var AllHuggingFaceResourceTypes = []HuggingFaceResourceType{ HuggingFaceResourceTypeRepos, HuggingFaceResourceTypeDiscussions, HuggingFaceResourceTypePRs, HuggingFaceResourceTypeBuckets, }
Functions ¶
Types ¶
type ActionsOptions ¶ added in v1.2.0
type ActionsOptions struct {
Workflows []string // filter to specific workflow file names
}
ActionsOptions controls which workflow runs and artifacts to scan.
type DateRangeOptions ¶ added in v1.2.0
type DateRangeOptions struct {
Since time.Time // only scan items created on or after this time (zero = no lower bound)
Until time.Time // only scan items created before this time (zero = no upper bound)
}
DateRangeOptions controls date-range filtering across API-backed GitHub resources.
type File ¶
type File struct {
// Content provides a reader to the file's content
Content io.Reader
// Path is the resolved real path of the file
Path string
// Symlink represents a symlink to the file if that's how it was discovered
Symlink string
// Buffer is used for reading the content in chunks
Buffer []byte
// ShouldSkip is a callback that decides whether to skip a file based on its
// attributes (e.g. path). If nil, no skipping is performed.
ShouldSkip SkipFunc
// MaxArchiveDepth limits how deep the sources will explore nested archives
MaxArchiveDepth int
// contains filtered or unexported fields
}
File is a source for yielding fragments from a file or other reader
type Files ¶
type Files struct {
ShouldSkip SkipFunc
FollowSymlinks bool
MaxFileSize int
Path string
Sema *semgroup.Group
MaxArchiveDepth int
}
Files is a source for yielding fragments from a collection of files
type Fragment ¶
type Fragment struct {
// Raw is the raw content of the fragment
Raw string
Bytes []byte
// Indicates if this fragment is inherited from a finding
InheritedFromFinding bool
// StartLine is the line number this fragment starts on
StartLine int
// Attributes holds all source-specific metadata
Attributes map[string]string
}
Fragment represents a fragment of a source with its meta data
type FragmentsFunc ¶
FragmentsFunc is the type of function called by Fragments to yield the next fragment
type Git ¶
type Git struct {
Cmd *GitCmd
ShouldSkip SkipFunc
Platform scm.Platform
RemoteURL string
Sema *semgroup.Group
MaxArchiveDepth int
}
Git is a source for yielding fragments from a git repo
type GitCmd ¶
type GitCmd struct {
// contains filtered or unexported fields
}
GitCmd helps to work with Git's output.
func NewGitDiffCmd
deprecated
NewGitDiffCmd returns `*DiffFilesCmd` with two channels: `<-chan *gitdiff.File` and `<-chan error`. Caller should read everything from channels until receiving a signal about their closure and call the `func (*DiffFilesCmd) Wait()` error in order to release resources.
Deprecated: use NewGitDiffCmdContext instead.
func NewGitDiffCmdContext ¶
NewGitDiffCmdContext is the same as NewGitDiffCmd but supports passing in a context to use for timeouts
func NewGitLogCmd
deprecated
NewGitLogCmd returns `*DiffFilesCmd` with two channels: `<-chan *gitdiff.File` and `<-chan error`. Caller should read everything from channels until receiving a signal about their closure and call the `func (*DiffFilesCmd) Wait()` error in order to release resources.
Deprecated: use NewGitLogCmdContext instead.
func NewGitLogCmdContext ¶
NewGitLogCmdContext is the same as NewGitLogCmd but supports passing in a context to use for timeouts
func (*GitCmd) DiffFilesCh ¶
DiffFilesCh returns a channel with *gitdiff.File.
func (*GitCmd) ErrCh ¶
ErrCh returns a channel that could produce an error if there is something in stderr.
func (*GitCmd) NewBlobReader
deprecated
func (c *GitCmd) NewBlobReader(commit, path string) (io.ReadCloser, error)
NewBlobReader returns an io.ReadCloser that can be used to read a blob within the git repo used to create the GitCmd.
The caller is responsible for closing the reader.
Deprecated: use NewBlobReaderContext instead.
func (*GitCmd) NewBlobReaderContext ¶
func (c *GitCmd) NewBlobReaderContext(ctx context.Context, commit, path string) (io.ReadCloser, error)
NewBlobReaderContext is the same as NewBlobReader but supports passing in a context to use for timeouts
type GitHub ¶ added in v1.2.0
type GitHub struct {
// Auth
Token string
// Filtering
ExcludeRepos []string // glob patterns matched against "owner/repo"
// Include and Exclude specify resource types by name (e.g. "repos", "prs").
// Validate applies these when Resources is empty.
Include []string
Exclude []string
// Resources controls which resource types to scan.
// Populated automatically by Validate from Include/Exclude when empty,
// or set directly by callers who want programmatic control.
Resources GitHubResourceSet
// Scan config (passed through to Git/ParallelGit per repo)
ShouldSkip SkipFunc
Sema *semgroup.Group
MaxArchiveDepth int
Workers int // git workers per repo (0 = single process)
LogOpts string
// GitHub API
BaseURL string // GitHub Enterprise base URL; empty = github.com
Actions ActionsOptions
DateRangeOpts DateRangeOptions
// Target URL (required).
URL string
// contains filtered or unexported fields
}
GitHub enumerates repositories via the GitHub API and delegates scanning to the Git source for each cloned repo.
type GitHubResourceSet ¶ added in v1.2.0
type GitHubResourceSet map[GitHubResourceType]bool
GitHubResourceSet tracks which resource types are enabled for scanning.
func (GitHubResourceSet) Has ¶ added in v1.2.0
func (rs GitHubResourceSet) Has(r GitHubResourceType) bool
Has reports whether the set contains the given resource type.
func (GitHubResourceSet) HasAnyIssueOrPR ¶ added in v1.2.0
func (rs GitHubResourceSet) HasAnyIssueOrPR() bool
HasAnyIssueOrPR reports whether any issue, PR, or comment resource is enabled (C4).
func (GitHubResourceSet) String ¶ added in v1.2.0
func (rs GitHubResourceSet) String() string
type GitHubResourceType ¶ added in v1.2.0
type GitHubResourceType string
GitHubResourceType identifies a scannable GitHub resource category.
const ( GitHubResourceTypeRepos GitHubResourceType = "repos" GitHubResourceTypeForks GitHubResourceType = "forks" GitHubResourceTypePRs GitHubResourceType = "prs" GitHubResourceTypePRComments GitHubResourceType = "pr-comments" GitHubResourceTypeIssues GitHubResourceType = "issues" GitHubResourceTypeIssueComments GitHubResourceType = "issue-comments" GitHubResourceTypeActions GitHubResourceType = "actions" GitHubResourceTypeActionArtifacts GitHubResourceType = "action-artifacts" GitHubResourceTypeDiscussions GitHubResourceType = "discussions" GitHubResourceTypeReleases GitHubResourceType = "releases" GitHubResourceTypeReleaseAssets GitHubResourceType = "release-assets" GitHubResourceTypeGists GitHubResourceType = "gists" )
type GitLab ¶ added in v1.4.0
type GitLab struct {
// Auth
Token string
// Target URL (required). A gitlab.com or self-hosted instance URL pointing
// at a project, group, user, or specific resource (issue, MR, snippet,
// release, pipeline, job).
URL string
// BaseURL is the site base for self-hosted instances (e.g.
// "https://gitlab.example.com/" or "https://corp.com/gitlab/"). Leave
// empty to infer "<scheme>://<host>/" from URL.
BaseURL string
// Filtering
ExcludeRepos []string // glob patterns matched against "group/sub/project"
Include []string
Exclude []string
Resources GitLabResourceSet
// Group enumeration knobs
AllGroups bool
IncludeSubgroups bool
// Scan config (passed through to Git/ParallelGit per project)
ShouldSkip SkipFunc
Sema *semgroup.Group
MaxArchiveDepth int
Workers int
LogOpts string
// Date-range filtering for API-backed resources
DateRangeOpts DateRangeOptions
// contains filtered or unexported fields
}
GitLab enumerates projects via the GitLab REST API and delegates scanning to the Git source for each cloned repo.
type GitLabResourceSet ¶ added in v1.4.0
type GitLabResourceSet map[GitLabResourceType]bool
GitLabResourceSet tracks which resource types are enabled for scanning.
func (GitLabResourceSet) Has ¶ added in v1.4.0
func (rs GitLabResourceSet) Has(r GitLabResourceType) bool
func (GitLabResourceSet) HasAnyIssueOrMR ¶ added in v1.4.0
func (rs GitLabResourceSet) HasAnyIssueOrMR() bool
HasAnyIssueOrMR reports whether any issue, MR, or comment resource is enabled.
func (GitLabResourceSet) String ¶ added in v1.4.0
func (rs GitLabResourceSet) String() string
type GitLabResourceType ¶ added in v1.4.0
type GitLabResourceType string
GitLabResourceType identifies a scannable GitLab resource category.
const ( GitLabResourceTypeRepos GitLabResourceType = "repos" GitLabResourceTypeForks GitLabResourceType = "forks" GitLabResourceTypeMRs GitLabResourceType = "mrs" GitLabResourceTypeMRComments GitLabResourceType = "mr-comments" GitLabResourceTypeIssues GitLabResourceType = "issues" GitLabResourceTypeIssueComments GitLabResourceType = "issue-comments" GitLabResourceTypeSnippets GitLabResourceType = "snippets" GitLabResourceTypeReleases GitLabResourceType = "releases" GitLabResourceTypeReleaseAssets GitLabResourceType = "release-assets" GitLabResourceTypeCIJobs GitLabResourceType = "ci-jobs" GitLabResourceTypeCIArtifacts GitLabResourceType = "ci-artifacts" )
type HuggingFace ¶ added in v1.4.1
type HuggingFace struct {
Token string
URL string
Include []string
Exclude []string
ExcludeRepos []string // glob patterns matched against "owner/name"
Resources HuggingFaceResourceSet
ShouldSkip SkipFunc
Sema *semgroup.Group
MaxArchiveDepth int
Workers int
LogOpts string
MaxBucketObjectSize int64
// contains filtered or unexported fields
}
HuggingFace enumerates Hugging Face model, dataset, and Space repositories via the Hub API and delegates git history scanning to the Git source.
func (*HuggingFace) Fragments ¶ added in v1.4.1
func (s *HuggingFace) Fragments(ctx context.Context, yield FragmentsFunc) error
func (*HuggingFace) Validate ¶ added in v1.4.1
func (s *HuggingFace) Validate() error
Validate checks the Hugging Face source configuration and resolves default resource selection.
type HuggingFaceRepoKind ¶ added in v1.4.1
type HuggingFaceRepoKind string
const ( HuggingFaceRepoKindModel HuggingFaceRepoKind = "model" HuggingFaceRepoKindDataset HuggingFaceRepoKind = "dataset" HuggingFaceRepoKindSpace HuggingFaceRepoKind = "space" )
type HuggingFaceResourceSet ¶ added in v1.4.1
type HuggingFaceResourceSet map[HuggingFaceResourceType]bool
func (HuggingFaceResourceSet) Has ¶ added in v1.4.1
func (rs HuggingFaceResourceSet) Has(r HuggingFaceResourceType) bool
func (HuggingFaceResourceSet) String ¶ added in v1.4.1
func (rs HuggingFaceResourceSet) String() string
type HuggingFaceResourceType ¶ added in v1.4.1
type HuggingFaceResourceType string
const ( HuggingFaceResourceTypeRepos HuggingFaceResourceType = "repos" HuggingFaceResourceTypeDiscussions HuggingFaceResourceType = "discussions" HuggingFaceResourceTypePRs HuggingFaceResourceType = "prs" HuggingFaceResourceTypeBuckets HuggingFaceResourceType = "buckets" )
type ParallelGit ¶
type ParallelGit struct {
RepoPath string
ShouldSkip SkipFunc
Platform scm.Platform
RemoteURL string
Sema *semgroup.Group
MaxArchiveDepth int
LogOpts string
Workers int // 0 means auto (min(NumCPU, 4))
}
ParallelGit scans a git repo by running multiple `git log -p` processes in parallel, each covering a distinct set of commits. Commit SHAs are enumerated once via `git rev-list` and then partitioned across workers, guaranteeing deterministic, non-overlapping coverage regardless of timestamp ties in the commit graph.
func (*ParallelGit) Fragments ¶
func (s *ParallelGit) Fragments(ctx context.Context, yield FragmentsFunc) error
Fragments implements Source by partitioning commits across multiple parallel git log workers.
type ParsedGitHubURL ¶ added in v1.2.0
type ParsedGitHubURL struct {
Owner string // repo owner, org name, user name, or gist user
Repo string // repo name (empty for owner-level or gists)
Resource string // "owner", "repo", "issue", "pr", "actions_run", "release", "discussion", "gist"
ID string // number, run ID, tag name, or gist ID (empty for owner/repo targets)
Host string // host (for GHE detection)
}
ParsedGitHubURL holds the components extracted from a GitHub target URL.
func ParseGitHubURL ¶ added in v1.2.0
func ParseGitHubURL(rawURL string) (*ParsedGitHubURL, error)
ParseGitHubURL parses a GitHub URL into its components. Supports org/user URLs, repo URLs, specific resource URLs, and gists.
type ParsedGitLabURL ¶ added in v1.4.0
type ParsedGitLabURL struct {
Scheme string // http or https
Host string // hostname[:port]
Path string // project/group/user path (everything before "/-/")
Kind string // "namespace", "project", "group", "user", "issue", "mr", "snippet", "release", "pipeline", "job"
ID string // resource ID (number, tag, snippet id)
}
ParsedGitLabURL is the result of splitting a GitLab URL into its components.
func ParseGitLabURL ¶ added in v1.4.0
func ParseGitLabURL(rawURL string) (*ParsedGitLabURL, error)
ParseGitLabURL parses a GitLab URL into namespace + optional resource segment. At this stage we cannot tell apart project / group / user — `dispatchURL` resolves that by querying the API.
type ParsedHuggingFaceURL ¶ added in v1.4.1
type ParsedHuggingFaceURL struct {
Scheme string
Host string
Kind string // "owner" or "repo"
Owner string
Name string
Type HuggingFaceRepoKind
Prefix string
}
func ParseHuggingFaceURL ¶ added in v1.4.1
func ParseHuggingFaceURL(rawURL string) (*ParsedHuggingFaceURL, error)
type S3 ¶ added in v1.3.0
type S3 struct {
// URL is the target bucket (and optional prefix). Required. Supported forms:
//
// s3://bucket/prefix
// https://bucket.s3.amazonaws.com/prefix
// https://bucket.s3.<region>.amazonaws.com/prefix
// https://s3.<region>.amazonaws.com/bucket/prefix
// https://<bucket>.<account>.r2.cloudflarestorage.com/prefix
// https://<endpoint>[:port]/bucket/prefix (MinIO, generic S3-compat)
URL string
// Region overrides whatever the URL implies. Required when the URL is a
// path-style endpoint with no inferable region (e.g. MinIO at a custom host).
Region string
// Credentials. Explicit fields win over environment variables. If both are
// empty and Anonymous is false, the source fails Validate.
AccessKey string
SecretKey string
SessionToken string
Anonymous bool
// Scan config
MaxObjectSize int64
Workers int
ShouldSkip SkipFunc
MaxArchiveDepth int
// contains filtered or unexported fields
}
S3 enumerates objects in an S3 (or S3-compatible) bucket and yields a fragment for each object's content. The target is described by a single URL passed via S3.URL.
type ScanTarget ¶
TODO: remove this in v9 and have scanTargets yield file sources
type SkipFunc ¶ added in v1.2.0
SkipFunc decides whether to skip a fragment based on its attributes. Returns true to skip (discard), false to keep. Used by sources as a callback to decouple path/commit filtering from config.
type Source ¶
type Source interface {
// Fragments provides a filepath.WalkDir like interface for scanning the
// fragments in the source
Fragments(ctx context.Context, yield FragmentsFunc) error
}
Source is a thing that can yield fragments