snyk

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package snyk provides a client for the Snyk REST API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExploitable

func IsExploitable(maturity string) bool

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

func NewAuthClient(token, site string) *Client

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 NewClient

func NewClient(creds Credentials) *Client

NewClient creates a new Snyk API client.

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

func (c *Client) GetProjectTargetMap(ctx context.Context) (map[string]string, error)

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

func (c *Client) ListOrgs(ctx context.Context) ([]Org, error)

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

func (c *Client) TestConnection(ctx context.Context) error

TestConnection verifies the Snyk credentials work.

func (*Client) WithDebug

func (c *Client) WithDebug(v bool) *Client

WithDebug toggles per-request debug logging.

func (*Client) WithDumpResponses

func (c *Client) WithDumpResponses(v bool) *Client

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.

type Org

type Org struct {
	ID   string
	Name string
}

Org represents a Snyk organization.

Jump to

Keyboard shortcuts

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