Documentation
¶
Overview ¶
Package snyk provides a client for the Snyk REST API.
Index ¶
- func IsExploitable(maturity string) bool
- type Client
- func (c *Client) CountOpenIssues(ctx context.Context, filter IssueFilter) (OpenCounts, error)
- func (c *Client) GetProjectTargetMap(ctx context.Context) (map[string]string, error)
- func (c *Client) ListIssues(ctx context.Context, from, to time.Time, filter IssueFilter) ([]Issue, error)
- func (c *Client) ListOrgs(ctx context.Context) ([]Org, error)
- func (c *Client) ListResolvedIssues(ctx context.Context, from, to time.Time, filter IssueFilter) ([]Issue, error)
- func (c *Client) TestConnection(ctx context.Context) error
- func (c *Client) WithDebug(v bool) *Client
- func (c *Client) WithDumpResponses(v bool) *Client
- type Credentials
- type Issue
- type IssueFilter
- type OpenCounts
- type Org
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsExploitable ¶
IsExploitable returns true for vulnerabilities with a known exploit. Snyk exploit maturity levels that qualify: "Proof of Concept", "Attacked".
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main Snyk API client.
func NewAuthClient ¶
NewAuthClient creates a Snyk client with only token and site — no OrgID required. Use for operations that don't need an org (e.g. ListOrgs during config).
func NewClientWithHTTPDoer ¶
func NewClientWithHTTPDoer(doer httputil.HTTPDoer, creds Credentials) *Client
NewClientWithHTTPDoer creates a Snyk client with a custom HTTP doer. Intended for use in tests (e.g. pointing the client at an httptest.Server).
func (*Client) CountOpenIssues ¶
func (c *Client) CountOpenIssues(ctx context.Context, filter IssueFilter) (OpenCounts, error)
CountOpenIssues returns the current open issue counts broken down by severity, deduplicated by (target, title, severity) to match the Snyk UI's per-target grouping. Falls back to project-level deduplication if the projects endpoint is unavailable.
func (*Client) GetProjectTargetMap ¶
GetProjectTargetMap returns a map of project ID → target ID for all projects in the org.
func (*Client) ListIssues ¶
func (c *Client) ListIssues(ctx context.Context, from, to time.Time, filter IssueFilter) ([]Issue, error)
ListIssues fetches all issues for the org within the given date range.
func (*Client) ListOrgs ¶
ListOrgs lists all Snyk organizations accessible to the authenticated user.
func (*Client) ListResolvedIssues ¶
func (c *Client) ListResolvedIssues(ctx context.Context, from, to time.Time, filter IssueFilter) ([]Issue, error)
ListResolvedIssues fetches issues resolved within the given date range. It filters by update time to catch recently resolved issues, then returns only those with status "resolved" and a resolved_at within the range.
func (*Client) TestConnection ¶
TestConnection verifies the Snyk credentials work.
func (*Client) WithDumpResponses ¶
WithDumpResponses toggles full response-body dumping. Off by default.
type Credentials ¶
type Credentials struct {
Token string // Snyk API token
OrgID string // Snyk organization ID
Site string // API host (default "api.snyk.io")
}
Credentials holds Snyk authentication details.
func (*Credentials) BaseURL ¶
func (c *Credentials) BaseURL() string
BaseURL returns the Snyk API base URL.
type Issue ¶
type Issue struct {
ID string
Title string
Severity string // critical, high, medium, low
IssueType string
Status string
IsFixable bool
IsIgnored bool
Exploitability string // "Not Defined", "Proof of Concept", "Attacked"
CreatedAt time.Time
ResolvedAt time.Time
}
Issue represents a Snyk vulnerability issue.
type IssueFilter ¶
type IssueFilter struct {
// ScanItemType restricts results to a specific scan origin, e.g. "cli" for CI/CLI scans.
// Leave empty to return issues from all scan types.
ScanItemType string
}
IssueFilter holds optional filters applied when querying issues from the Snyk API.
type OpenCounts ¶
type OpenCounts struct {
Critical, High, Medium, Low, Total int
Fixable, Unfixable int
Ignored, IgnoredFixable, IgnoredUnfixable int
// Fixable counts per severity level
FixableCritical, FixableHigh, FixableMedium, FixableLow int
// Exploitable counts ("Proof of Concept" or "Attacked" maturity)
ExploitableCritical, ExploitableHigh, ExploitableMedium, ExploitableLow int
ExploitableFixable, ExploitableUnfixable int
ExploitableIgnoredFixable, ExploitableIgnoredUnfixable int
}
OpenCounts holds the current total of open issues broken down by severity and fixability.