codeclient

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 8 Imported by: 2

README

code-client-go

A library that exposes scanning capabilities for Snyk Code that can be used in the Snyk CLI as well as Snyk IDE plugins using the Snyk Language Server.

Installation

$ go get github.com/snyk/code-client-go

Usage

HTTP Client

Use the HTTP client to make HTTP requests with configured retriable codes and authorisation headers for Snyk Rest APIs.

Implement the github.com/snyk/code-client-go/http.Config interface to configure the Snyk Code API client from applications.

Provide a net/http.Client factory to customize the underlying HTTP protocol behavior (timeouts, etc).

import (
    "net/http"

    "github.com/rs/zerolog"
    codehttp "github.com/snyk/code-client-go/http"
)

logger := zerlog.NewLogger(...)
config := newConfigForMyApp()
httpClient := codehttp.NewHTTPClient(logger, config, func() *http.Client { return http.DefaultClient }, codeInstrumentor, codeErrorReporter)

The HTTP client exposes a DoCall function.

Configuration

Implement the http.Config interface and to configure the Snyk Code API client from applications.

Snyk Code Client

Use the Snyk Code Client to make calls to the DeepCode API using the httpClient HTTP client created above.

snykCode := deepcode.NewSnykCodeClient(logger, httpClient, testutil.NewTestInstrumentor())

The Snyk Code Client exposes the following functions:

  • GetFilters
  • CreateBundle
  • ExtendBundle
Bundle Manager

Use the Bundle Manager to create bundles using the snykCode Snyk Code Client created above and then to extend it by uploading more files to it.

bundleManager := bundle.NewBundleManager(snykCode, testutil.NewTestInstrumentor(), testutil.NewTestCodeInstrumentor())

The Bundle Manager exposes the following functions:

  • Create
  • Upload
Code Scanner

Use the Code Scanner to trigger a scan for a Snyk Code workspace using the Bundle Manager created above:

codeScanner := codeclient.NewCodeScanner(
    bundleManager,
    testutil.NewTestInstrumentor(),
    testutil.NewTestCodeInstrumentor(),
    testutils.NewTestAnalytics(),
)

The Code Scanner exposes a UploadAndAnalyze function.

Observability

Under ./observability we have defined some observability interfaces which allows consumers of the library to inject their own observability implementations as long as they follow the defined interfaces.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCodeScanner added in v0.4.0

func NewCodeScanner(
	bundleManager bundle.BundleManager,
	instrumentor observability.Instrumentor,
	errorReporter observability.ErrorReporter,
	logger *zerolog.Logger,
) *codeScanner

NewCodeScanner creates a Code Scanner which can be used to trigger Snyk Code on a folder.

Types

type CodeScanner added in v0.4.0

type CodeScanner interface {
	UploadAndAnalyze(
		ctx context.Context,
		host string,
		path string,
		files <-chan string,
		changedFiles map[string]bool,
	) (*sarif.SarifResponse, bundle.Bundle, error)
}

Directories

Path Synopsis
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
* © 2024 Snyk Limited All rights reserved.
* © 2024 Snyk Limited All rights reserved.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package http defines the HTTP client used to interact with the Snyk Code API.
Package http defines the HTTP client used to interact with the Snyk Code API.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
internal
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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