snyk

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: Apache-2.0 Imports: 10 Imported by: 9

Documentation

Overview

Package snyk provides a client for using the Snyk API.

Index

Constants

View Source
const (
	ACRIntegrationType                 = "acr"
	ArtifactoryCRIntegrationType       = "artifactory-cr"
	AzureReposIntegrationType          = "azure-repos"
	BitBucketCloudIntegrationType      = "bitbucket-cloud"
	BitBucketConnectAppIntegrationType = "bitbucket-connect-app"
	BitBucketServerIntegrationType     = "bitbucket-server"
	DigitalOceanCRIntegrationType      = "digitalocean-cr"
	DockerHubIntegrationType           = "docker-hub"
	ECRIntegrationType                 = "ecr"
	GCRIntegrationType                 = "gcr"
	GitHubIntegrationType              = "github"
	GitHubCRIntegrationType            = "github-cr"
	GitHubEnterpriseIntegrationType    = "github-enterprise"
	GitLabIntegrationType              = "gitlab"
	GitLabCRIntegrationType            = "gitlab-cr"
	GoogleArtifactCRIntegrationType    = "google-artifact-cr"
	HarborCRIntegrationType            = "harbor-cr"
	KubernetesIntegrationType          = "kubernetes"
	NexusCRIntegrationType             = "nexus-cr"
	QuayCRIntegrationType              = "quay-cr"
)

Variables

View Source
var (
	// ErrEmptyArgument indicates that mandatory argument is empty.
	ErrEmptyArgument = errors.New("snyk-sdk-go: argument cannot be empty")
	// ErrEmptyPayloadNotAllowed indicates that empty payload is not allowed.
	ErrEmptyPayloadNotAllowed = errors.New("snyk-sdk-go: empty payload is not allowed")
)

Functions

func CheckResponse

func CheckResponse(resp *Response) error

CheckResponse verifies the API responds for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range.

Types

type Client

type Client struct {
	Integrations *IntegrationsService
	Orgs         *OrgsService
	Projects     *ProjectsService
	Users        *UsersService
	// contains filtered or unexported fields
}

A Client manages communication with the Snyk API.

func NewClient

func NewClient(token string, opts ...ClientOption) *Client

NewClient creates a new Snyk API client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request.

type ClientOption

type ClientOption func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL configures Client to use a specific API endpoint.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient configures Client to use a specific http client for communication.

func WithUserAgent

func WithUserAgent(userAgent string) ClientOption

WithUserAgent configures Client to use a specific user agent.

type ErrorElement

type ErrorElement struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

ErrorElement represents a single error caused by an API request.

type ErrorResponse

type ErrorResponse struct {
	Response     *Response
	ErrorElement ErrorElement
}

An ErrorResponse reports an error caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Group

type Group struct {
	ID   string `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
}

Group represents a Snyk group.

type Integration

type Integration struct {
	Credentials *IntegrationCredentials `json:"credentials,omitempty"`
	ID          string                  `json:"id,omitempty"`
	Type        IntegrationType         `json:"type,omitempty"`
}

Integration represents a Snyk integration. Integrations are connections to places where code lives.

type IntegrationCreateRequest

type IntegrationCreateRequest struct {
	*Integration
}

IntegrationCreateRequest represents a request to create an integration.

type IntegrationCredentials

type IntegrationCredentials struct {
	Password     string `json:"password,omitempty"`
	Region       string `json:"region,omitempty"`
	RegistryBase string `json:"registryBase,omitempty"`
	RoleARN      string `json:"roleArn,omitempty"`
	Token        string `json:"token,omitempty"`
	URL          string `json:"url,omitempty"`
	Username     string `json:"username,omitempty"`
}

IntegrationCredentials represents a credentials object for the specific integration.

type IntegrationSettings added in v0.3.0

type IntegrationSettings struct {
	// DependencyAutoUpgradeEnabled can automatically raise pull requests to update out-of-date dependencies.
	DependencyAutoUpgradeEnabled *bool `json:"autoDepUpgradeEnabled,omitempty"`

	// DependencyAutoUpgradeIgnoredDependencies list of dependencies should be ignored.
	DependencyAutoUpgradeIgnoredDependencies []string `json:"autoDepUpgradeIgnoredDependencies,omitempty"`

	// DependencyAutoUpgradePullRequestLimit how many automatic dependency upgrade PRs can be opened simultaneously.
	DependencyAutoUpgradePullRequestLimit int64 `json:"autoDepUpgradeLimit,omitempty"`

	// DependencyAutoUpgradeIncludeMajorVersion includes major version in upgrade recommendation, otherwise it will be
	// minor and patch versions only.
	DependencyAutoUpgradeIncludeMajorVersion *bool `json:"isMajorUpgradeEnabled,omitempty"`

	// DockerfileDetectionEnabled will automatically detect and scan Dockerfiles in your Git repositories.
	DockerfileDetectionEnabled *bool `json:"dockerfileSCMEnabled,omitempty"`

	// PullRequestFailOnAnyIssue fails an opened pull request if any vulnerable dependencies have been detected,
	// otherwise the pull request should only fail when a dependency with issues is added.
	PullRequestFailOnAnyIssue *bool `json:"pullRequestFailOnAnyVulns,omitempty"`

	// PullRequestFailOnlyForIssuesWithFix fails an opened pull request only when issues found have a fix available.
	PullRequestFailOnlyForIssuesWithFix *bool `json:"pullRequestFailOnlyForIssuesWithFix,omitempty"`

	// PullRequestFailOnlyForHighAndCriticalSeverity fails an opened pull request if any dependencies are marked
	// as being of high or critical severity.
	PullRequestFailOnlyForHighAndCriticalSeverity *bool `json:"pullRequestFailOnlyForHighSeverity,omitempty"`

	// PullRequestTestEnabled tests any newly created pull request in your repositories for security vulnerabilities
	// and sends a status check to GitHub.
	//
	// Snyk docs: https://docs.snyk.io/integrations/git-repository-scm-integrations/github-integration#pull-request-testing
	PullRequestTestEnabled *bool `json:"pullRequestTestEnabled,omitempty"`
}

IntegrationSettings represents settings for the specific integration.

type IntegrationSettingsUpdateRequest added in v0.3.0

type IntegrationSettingsUpdateRequest struct {
	*IntegrationSettings
}

IntegrationSettingsUpdateRequest represents a request to update an integration settings.

type IntegrationType

type IntegrationType string

IntegrationType defines an integration type, e.g. "github" or "gitlab".

type IntegrationUpdateRequest

type IntegrationUpdateRequest struct {
	*Integration
}

IntegrationUpdateRequest represents a request to update an integration.

type Integrations

type Integrations map[IntegrationType]string

type IntegrationsService

type IntegrationsService service

IntegrationsService handles communication with the integration related methods of the Snyk API.

func (*IntegrationsService) Create

func (s *IntegrationsService) Create(ctx context.Context, organizationID string, createRequest *IntegrationCreateRequest) (*Integration, *Response, error)

Create makes a new integration with given payload.

func (*IntegrationsService) DeleteCredentials

func (s *IntegrationsService) DeleteCredentials(ctx context.Context, organizationID, integrationID string) (*Response, error)

DeleteCredentials removes any credentials set for the given integration. If this is a brokered connection the operation will have no effect.

func (*IntegrationsService) GetByType

func (s *IntegrationsService) GetByType(ctx context.Context, organizationID string, integrationType IntegrationType) (*Integration, *Response, error)

GetByType retrieves information about an integration identified by type.

func (*IntegrationsService) GetSettings added in v0.3.0

func (s *IntegrationsService) GetSettings(ctx context.Context, organizationID, integrationID string) (*IntegrationSettings, *Response, error)

GetSettings retrieves information about a settings for the given integration.

func (*IntegrationsService) List

func (s *IntegrationsService) List(ctx context.Context, organizationID string) (Integrations, *Response, error)

List provides a list of all integrations for the given organization.

func (*IntegrationsService) Update

func (s *IntegrationsService) Update(ctx context.Context, organizationID, integrationID string, updateRequest *IntegrationUpdateRequest) (*Integration, *Response, error)

Update edits an integration.

func (*IntegrationsService) UpdateSettings added in v0.3.0

func (s *IntegrationsService) UpdateSettings(ctx context.Context, organizationID, integrationID string, updateRequest *IntegrationSettingsUpdateRequest) (*IntegrationSettings, *Response, error)

UpdateSettings edits an integration settings.

type Organization

type Organization struct {
	Group *Group `json:"group,omitempty"`
	ID    string `json:"id,omitempty"`
	Name  string `json:"name,omitempty"`
	Slug  string `json:"slug,omitempty"`
	URL   string `json:"url,omitempty"`
}

Organization represents a Snyk organization.

type OrganizationCreateRequest

type OrganizationCreateRequest struct {
	Name        string `json:"name,omitempty"`
	GroupID     string `json:"groupId,omitempty"`
	SourceOrgID string `json:"sourceOrgId,omitempty"` // id of the organization to copy settings from.
}

OrganizationCreateRequest represents a request to create an organization.

type OrgsService

type OrgsService service

OrgsService handles communication with the organization related methods of the Snyk API.

func (*OrgsService) Create

func (s *OrgsService) Create(ctx context.Context, createRequest *OrganizationCreateRequest) (*Organization, *Response, error)

Create makes a new organization with given payload.

If the [OrganizationCreateRequest.groupID] is not provided, a personal organization will be created independent of a group.

func (*OrgsService) Delete

func (s *OrgsService) Delete(ctx context.Context, organizationID string) (*Response, error)

Delete removes an organization identified by id.

func (*OrgsService) List

func (s *OrgsService) List(ctx context.Context) ([]Organization, *Response, error)

List provides a list of all organizations a user belongs to.

type Project

type Project struct {
	ID     string `json:"id,omitempty"`
	Name   string `json:"name,omitempty"`
	Origin string `json:"origin,omitempty"`
}

Project represents a Snyk project.

type ProjectsService

type ProjectsService service

ProjectsService handles communication with the project related methods of the Snyk API.

func (*ProjectsService) List

func (s *ProjectsService) List(ctx context.Context, organizationID string) ([]Project, *Response, error)

List provides a list of all projects for the given organization.

type Response

type Response struct {
	*http.Response

	SnykRequestID string // SnykRequestID returned from the API, useful to contact support.
}

Response is a Snyk response. This wraps the standard http.Response.

type User

type User struct {
	Email         string         `json:"email,omitempty"`
	ID            string         `json:"id,omitempty"`
	Name          string         `json:"name,omitempty"`
	Username      string         `json:"username,omitempty"`
	Organizations []Organization `json:"orgs,omitempty"`
}

User represents a Snyk user.

type UsersService

type UsersService service

UsersService handles communication with the user related methods of the Snyk API.

func (*UsersService) Get

func (s *UsersService) Get(ctx context.Context, userID string) (*User, *Response, error)

Get retrieves information about a user identified by id.

func (*UsersService) GetCurrent

func (s *UsersService) GetCurrent(ctx context.Context) (*User, *Response, error)

GetCurrent retrieves information about the user making the request.

Note: the retrieved user will include information about organizations that the user belongs to.

Jump to

Keyboard shortcuts

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