guardrailsclient

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken            = errors.New("invalid token, please provide a valid GuardRails CLI token, available from dashboard -> settings")
	ErrRepositoryNotFound      = errors.New("invalid repository, please provide an existing repository from the git provider account linked with GuardRails, available from dashboard -> repositories")
	ErrScanProcessNotCompleted = errors.New("scan process is not completed")
)

Functions

func GetCVSSSeverityAbbreviation

func GetCVSSSeverityAbbreviation(value string) string

GetCVSSSeverityAbbreviation returns abbreviations of CVSSSeverity value.

Types

type CVSSSeverityAbbr

type CVSSSeverityAbbr int
const (
	Informational CVSSSeverityAbbr = iota
	Low
	Medium
	High
	Critical
	NotAvailable
)

func (CVSSSeverityAbbr) String

func (c CVSSSeverityAbbr) String() string

type CreateUploadURLReq

type CreateUploadURLReq struct {
	CLIToken string `json:"clitoken"`
	File     string `json:"file"`
}

CreateUploadURLReq is CreateUploadURL http request body.

type CreateUploadURLResp

type CreateUploadURLResp struct {
	SignedURL string `json:"signedUrl"`
}

CreateUploadURLResp is CreateUploadURL http response body.

type ErrorResp

type ErrorResp struct {
	StatusCode int    `json:"statusCode"`
	Error      string `json:"error"`
	Message    string `json:"message"`
}

ErrorResp is general error body returned from guardrails client.

type GetScanDataCountResp

type GetScanDataCountResp struct {
	Total    int `json:"total"`
	New      int `json:"new"`
	Open     int `json:"open"`
	Resolved int `json:"resolved"`
	Fixed    int `json:"fixed"`
	Findings int `json:"findings"`
}

type GetScanDataReq

type GetScanDataReq struct {
	ScanID string
}

GetScanDataReq contains GetScanData parameters required to call GetScanData API.

type GetScanDataResp

type GetScanDataResp struct {
	ScanID  string `json:"idScan"`
	Type    string `json:"type"`
	Branch  string `json:"branch"`
	SHA     string `json:"sha"`
	OK      bool   `json:"ok"`
	Results struct {
		Count *GetScanDataCountResp `json:"count"`
		Rules []GetScanDataRuleResp `json:"rules"`
	} `json:"results"`
	Repository struct {
		RepositoryID  int64     `json:"idRepository"`
		Name          string    `json:"name"`
		DefaultBranch string    `json:"defaultBranch"`
		Provider      string    `json:"provider"`
		FullName      string    `json:"fullName"`
		Description   string    `json:"description"`
		Language      string    `json:"language"`
		IsPrivate     bool      `json:"isPrivate"`
		IsEnabled     bool      `json:"isEnabled"`
		CreatedAt     time.Time `json:"createdAt"`
		UpdatedAt     time.Time `json:"updatedAt"`
	} `json:"repository"`
	Report     string    `json:"report"`
	QueuedAt   time.Time `json:"queuedAt"`
	ScanningAt time.Time `json:"scanningAt"`
	FinishedAt time.Time `json:"finishedAt"`
}

GetScanDataResp is GetScanData http response body.

type GetScanDataRuleResp

type GetScanDataRuleResp struct {
	Rule struct {
		RuleID int64  `json:"idRule"`
		Title  string `json:"title"`
		Name   string `json:"name"`
		Docs   string `json:"docs"`
	} `json:"rule"`
	Languages       []string                       `json:"language"`
	Count           *GetScanDataCountResp          `json:"count"`
	Vulnerabilities []GetScanDataVulnerabilityResp `json:"vulnerabilities"`
}

type GetScanDataVulnerabilityMetadataResp

type GetScanDataVulnerabilityMetadataResp struct {
	DependencyName  string   `json:"dependencyName"`
	CurrentVersion  string   `json:"currentVersion"`
	PatchedVersions string   `json:"patchedVersions"`
	References      []string `json:"references"`
	CvssSeverity    string   `json:"cvssSeverity"`
	CvssScore       string   `json:"cvssScore"`
	CvssVector      string   `json:"cvssVector"`
}

func (*GetScanDataVulnerabilityMetadataResp) IsDependencyNameContainsVersion

func (r *GetScanDataVulnerabilityMetadataResp) IsDependencyNameContainsVersion() (bool, error)

IsDependencyNameContainsVersion checks if DependencyName already contains a version

type GetScanDataVulnerabilityResp

type GetScanDataVulnerabilityResp struct {
	FindingID               string                                `json:"idFinding"`
	Status                  string                                `json:"status"`
	Language                string                                `json:"language"`
	Branch                  string                                `json:"branch"`
	Path                    string                                `json:"path"`
	PrimaryLocationLineHash string                                `json:"primaryLocationLineHash"`
	LineNumber              int64                                 `json:"lineNumber"`
	IntroducedBy            string                                `json:"introducedBy"`
	Type                    string                                `json:"type"`
	Metadata                *GetScanDataVulnerabilityMetadataResp `json:"metadata,omitempty"`
	Severity                struct {
		SeverityID int64  `json:"idSeverity"`
		Name       string `json:"name"`
	} `json:"severity"`
	EngineRule struct {
		EngineRuleID int64   `json:"idEngineRule"`
		Title        string  `json:"title"`
		Name         string  `json:"name"`
		Docs         string  `json:"docs"`
		EngineName   string  `json:"engineName"`
		CvssSeverity string  `json:"cvssSeverity"`
		CvssScore    float64 `json:"cvssScore"`
		CvssVector   string  `json:"cvssVector"`
	} `json:"engineRule"`
}

type GuardRailsClient

type GuardRailsClient interface {
	// CreateUploadURL call GuardRails API to create upload URL.
	CreateUploadURL(ctx context.Context, req *CreateUploadURLReq) (*CreateUploadURLResp, error)
	// UploadProject accepts url generated from CreateUploadURL and upload it via presigned url.
	UploadProject(ctx context.Context, req *UploadProjectReq) error
	// TriggerScan call GuardRails API to trigger scan operation.
	TriggerScan(ctx context.Context, req *TriggerScanReq) (*TriggerScanResp, error)
	// GetScanData call GuardRails API to get scan data from scan operation.
	GetScanData(ctx context.Context, req *GetScanDataReq) (*GetScanDataResp, error)
}

GuardRailsClient defines methods to interact with GuardRails API.

func New

func New(cfg *config.Config, token string) GuardRailsClient

New instantiates new GuardRailsClient.

type TriggerScanReq

type TriggerScanReq struct {
	CLIToken   string `json:"clitoken"`
	Repository string `json:"repository"`
	SHA        string `json:"sha"`
	Branch     string `json:"branch"`
	FileName   string `json:"fileName"`
}

TriggerScanReq is TriggerScan http request body.

type TriggerScanResp

type TriggerScanResp struct {
	ScanID       string `json:"idScan"`
	DashboardURL string `json:"dashboardUrl"`
}

TriggerScanResp is TriggerScan http response body.

type UploadProjectReq

type UploadProjectReq struct {
	UploadURL string
	File      io.Reader
}

UploadProjectReq is UploadProject http request body.

Directories

Path Synopsis
Package mockguardrailsclient is a generated GoMock package.
Package mockguardrailsclient is a generated GoMock package.

Jump to

Keyboard shortcuts

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