hub

package
v2.2.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const PolicyStatusTypeInViolation = "IN_VIOLATION"

PolicyStatusTypeInViolation denotes policy status type IN_VIOLATION

View Source
const PolicyStatusTypeInViolationOverridden = "IN_VIOLATION_OVERRIDDEN"

PolicyStatusTypeInViolationOverridden denotes policy status type IN_VIOLATION_OVERRIDDEN

View Source
const PolicyStatusTypeNotInViolation = "NOT_IN_VIOLATION"

PolicyStatusTypeNotInViolation denotes policy status type NOT_IN_VIOLATION

View Source
const RiskProfileCategoryActivity = "ACTIVITY"

RiskProfileCategoryActivity denotes the type ACTIVITY in Risk Profile category

View Source
const RiskProfileCategoryLicense = "LICENSE"

RiskProfileCategoryLicense denotes the type LICENSE in Risk Profile category

View Source
const RiskProfileCategoryOperational = "OPERATIONAL"

RiskProfileCategoryOperational denotes the type OPERATIONAL in Risk Profile category

View Source
const RiskProfileCategoryVersion = "VERSION"

RiskProfileCategoryVersion denotes the type VERSION in Risk Profile category

View Source
const RiskProfileCategoryVulnerability = "VULNERABILITY"

RiskProfileCategoryVulnerability denotes the type VULNERABILITY in Risk Profile category

View Source
const RiskProfileStatusCritical = "CRITICAL"

RiskProfileStatusCritical denotes risk profile status CRITICAL

View Source
const RiskProfileStatusHigh = "HIGH"

RiskProfileStatusHigh denotes risk profile status HIGH

View Source
const RiskProfileStatusLow = "LOW"

RiskProfileStatusLow denotes risk profile status LOW

View Source
const RiskProfileStatusMedium = "MEDIUM"

RiskProfileStatusMedium denotes risk profile status MEDIUM

View Source
const RiskProfileStatusOK = "OK"

RiskProfileStatusOK denotes risk profile status OK

View Source
const RiskProfileStatusUnknown = "UNKNOWN"

RiskProfileStatusUnknown denotes risk profile status UNKNOWN

Variables

View Source
var DefaultTimings = &Timings{
	FetchAllScansPause:     999999 * time.Hour,
	ScanCompletionPause:    1 * time.Minute,
	FetchUnknownScansPause: 30 * time.Second,
	GetMetricsPause:        15 * time.Second,
	LoginPause:             30 * time.Minute,
	RefreshScanThreshold:   1 * time.Hour,
}

DefaultTimings ...

Functions

func MinDuration

func MinDuration(left time.Duration, right time.Duration) time.Duration

MinDuration is just max.Min, except for time.Duration values

Types

type CircuitBreaker

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

CircuitBreaker .....

func NewCircuitBreaker

func NewCircuitBreaker(host string, maxBackoffDuration time.Duration) *CircuitBreaker

NewCircuitBreaker .....

func (*CircuitBreaker) IsEnabled

func (cb *CircuitBreaker) IsEnabled() bool

IsEnabled .....

func (*CircuitBreaker) IssueRequest

func (cb *CircuitBreaker) IssueRequest(description string, request func() error) error

IssueRequest synchronously:

  • checks whether it's enabled
  • runs 'request'
  • looks at the result of 'request', disabling itself on failure

func (*CircuitBreaker) Model

func (cb *CircuitBreaker) Model() *api.ModelCircuitBreaker

Model dumps the current state of the circuit breaker

func (*CircuitBreaker) Reset

func (cb *CircuitBreaker) Reset()

Reset reenables the circuit breaker regardless of its current state, and clears out ConsecutiveFailures and NextCheckTime

type CircuitBreakerState

type CircuitBreakerState int

CircuitBreakerState .....

const (
	CircuitBreakerStateDisabled CircuitBreakerState = iota
	CircuitBreakerStateEnabled  CircuitBreakerState = iota
	CircuitBreakerStateChecking CircuitBreakerState = iota
)

.....

func (CircuitBreakerState) MarshalJSON

func (state CircuitBreakerState) MarshalJSON() ([]byte, error)

MarshalJSON .....

func (CircuitBreakerState) MarshalText

func (state CircuitBreakerState) MarshalText() (text []byte, err error)

MarshalText .....

func (CircuitBreakerState) String

func (state CircuitBreakerState) String() string

String .....

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client combines a raw hub client with a circuit breaker

func NewClient

func NewClient(username string, password string, host string, rawClient RawClientInterface) *Client

NewClient returns a new Client.

func (*Client) SetTimeout

func (client *Client) SetTimeout(timeout time.Duration)

SetTimeout is currently not concurrent-safe, and should be made so TODO

func (*Client) Version

func (client *Client) Version() (string, error)

Version fetches the hub version

type ClientStatus

type ClientStatus int

ClientStatus describes the state of a hub client

const (
	ClientStatusError ClientStatus = iota
	ClientStatusUp    ClientStatus = iota
	ClientStatusDown  ClientStatus = iota
)

.....

func (ClientStatus) MarshalJSON

func (status ClientStatus) MarshalJSON() ([]byte, error)

MarshalJSON .....

func (ClientStatus) MarshalText

func (status ClientStatus) MarshalText() (text []byte, err error)

MarshalText .....

func (ClientStatus) String

func (status ClientStatus) String() string

String .....

type CodeLocation

type CodeLocation struct {
	ScanSummaries        []ScanSummary
	CreatedAt            string
	MappedProjectVersion string
	Name                 string
	CodeLocationType     string
	URL                  string
	UpdatedAt            string
}

CodeLocation .....

type DidFindScan

type DidFindScan struct {
	Name    string
	Results *ScanResults
}

DidFindScan ...

type DidFinishScan

type DidFinishScan struct {
	Name    string
	Results *ScanResults
}

DidFinishScan ...

type DidRefreshScan

type DidRefreshScan struct {
	Name    string
	Results *ScanResults
}

DidRefreshScan ...

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub stores the Black Duck configuration

func NewHub

func NewHub(username string, password string, host string, concurrentScanLimit int, rawClient RawClientInterface, timings *Timings) *Hub

NewHub returns a new Black Duck. It will not be logged in.

func (*Hub) ConcurrentScanLimit

func (hub *Hub) ConcurrentScanLimit() int

ConcurrentScanLimit return the concurrent scan limit

func (*Hub) FinishScanClient

func (hub *Hub) FinishScanClient(scanName string, scanErr error)

FinishScanClient finishes the scan client

func (*Hub) HasFetchedScans

func (hub *Hub) HasFetchedScans() <-chan bool

HasFetchedScans return whether there is any fetched scans

func (*Hub) Host

func (hub *Hub) Host() string

Host return the Host

func (*Hub) InProgressScans

func (hub *Hub) InProgressScans() <-chan []string

InProgressScans return the Inprogress scan count of the Black Duck instance

func (*Hub) Model

func (hub *Hub) Model() <-chan *api.ModelBlackDuck

Model return the model

func (*Hub) ResetCircuitBreaker

func (hub *Hub) ResetCircuitBreaker()

ResetCircuitBreaker resets the circuit breaker

func (*Hub) ScanResults

func (hub *Hub) ScanResults() <-chan map[string]*Scan

ScanResults return the scan results

func (*Hub) ScansCount

func (hub *Hub) ScansCount() <-chan int

ScansCount return the Black Duck scan count

func (*Hub) StartScanClient

func (hub *Hub) StartScanClient(scanName string)

StartScanClient starts the scan client

func (*Hub) Stop

func (hub *Hub) Stop()

Stop stops the Black Duck

func (*Hub) StopCh

func (hub *Hub) StopCh() <-chan struct{}

StopCh returns a reference to the stop channel

func (*Hub) Updates

func (hub *Hub) Updates() <-chan Update

Updates produces events for: - finding a scan for the first time - when a hub scan finishes - when a finished scan is repulled (to get any changes to its vulnerabilities, policies, etc.)

type ImageInterface added in v0.0.5

type ImageInterface interface {
	HubProjectNameSearchString() string
	HubProjectVersionNameSearchString() string
	HubScanNameSearchString() string
}

ImageInterface .....

type MockRawClient

type MockRawClient struct {
	IsLoggedIn    bool
	ShouldFail    bool
	CodeLocations map[string]ScanStage
}

MockRawClient ...

func NewMockRawClient

func NewMockRawClient(shouldFail bool, initialCodeLocationNames []string) *MockRawClient

NewMockRawClient ...

func (*MockRawClient) CurrentVersion

func (mhc *MockRawClient) CurrentVersion() (*hubapi.CurrentVersion, error)

CurrentVersion ...

func (*MockRawClient) DeleteCodeLocation

func (mhc *MockRawClient) DeleteCodeLocation(scanName string) error

DeleteCodeLocation ...

func (*MockRawClient) DeleteProjectVersion

func (mhc *MockRawClient) DeleteProjectVersion(name string) error

DeleteProjectVersion ...

func (*MockRawClient) GetProject

func (mhc *MockRawClient) GetProject(link hubapi.ResourceLink) (*hubapi.Project, error)

GetProject ...

func (*MockRawClient) GetProjectVersion

func (mhc *MockRawClient) GetProjectVersion(link hubapi.ResourceLink) (*hubapi.ProjectVersion, error)

GetProjectVersion ...

func (*MockRawClient) GetProjectVersionPolicyStatus

func (mhc *MockRawClient) GetProjectVersionPolicyStatus(link hubapi.ResourceLink) (*hubapi.ProjectVersionPolicyStatus, error)

GetProjectVersionPolicyStatus ...

func (*MockRawClient) GetProjectVersionRiskProfile

func (mhc *MockRawClient) GetProjectVersionRiskProfile(link hubapi.ResourceLink) (*hubapi.ProjectVersionRiskProfile, error)

GetProjectVersionRiskProfile ...

func (*MockRawClient) ListAllCodeLocations

func (mhc *MockRawClient) ListAllCodeLocations(options *hubapi.GetListOptions) (*hubapi.CodeLocationList, error)

ListAllCodeLocations ...

func (*MockRawClient) ListProjects

func (mhc *MockRawClient) ListProjects(options *hubapi.GetListOptions) (*hubapi.ProjectList, error)

ListProjects ...

func (*MockRawClient) ListScanSummaries

func (mhc *MockRawClient) ListScanSummaries(link hubapi.ResourceLink) (*hubapi.ScanSummaryList, error)

ListScanSummaries ...

func (*MockRawClient) Login

func (mhc *MockRawClient) Login(username string, password string) error

Login ...

func (*MockRawClient) SetTimeout

func (mhc *MockRawClient) SetTimeout(timeout time.Duration)

SetTimeout ...

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model stores the Black Duck model

func NewModel

func NewModel(host string, stop <-chan struct{}, fetchScan func(string) (*ScanResults, error)) *Model

NewModel return the Black Duck model

func (*Model) FinishScanClient

func (model *Model) FinishScanClient(scanName string, scanErr error)

FinishScanClient finishes the scan client

func (*Model) HasFetchedScans

func (model *Model) HasFetchedScans() <-chan bool

HasFetchedScans checks whether there is any has fetched scans

func (*Model) InProgressScans

func (model *Model) InProgressScans() <-chan []string

InProgressScans returns the inprogress scan count

func (*Model) Model

func (model *Model) Model() <-chan *api.ModelBlackDuck

Model returns the model

func (*Model) ScanResults

func (model *Model) ScanResults() <-chan map[string]*Scan

ScanResults returns the scan results

func (*Model) ScansCount

func (model *Model) ScansCount() <-chan int

ScansCount returns the scan count

func (*Model) StartScanClient

func (model *Model) StartScanClient(scanName string)

StartScanClient starts the scan client

func (*Model) Updates

func (model *Model) Updates() <-chan Update

Updates publish the updates

type PolicyStatus

type PolicyStatus struct {
	OverallStatus                string
	UpdatedAt                    string
	ComponentVersionStatusCounts map[string]int
}

PolicyStatus .....

func (*PolicyStatus) ViolationCount

func (ps *PolicyStatus) ViolationCount() int

ViolationCount .....

type Project

type Project struct {
	Name     string
	Source   string
	Versions []Version
}

Project .....

type RawClientInterface

type RawClientInterface interface {
	CurrentVersion() (*hubapi.CurrentVersion, error)
	SetTimeout(timeout time.Duration)
	Login(username string, password string) error
	ListAllCodeLocations(options *hubapi.GetListOptions) (*hubapi.CodeLocationList, error)
	ListProjects(options *hubapi.GetListOptions) (*hubapi.ProjectList, error)
	GetProject(link hubapi.ResourceLink) (*hubapi.Project, error)
	GetProjectVersion(link hubapi.ResourceLink) (*hubapi.ProjectVersion, error)
	ListScanSummaries(link hubapi.ResourceLink) (*hubapi.ScanSummaryList, error)
	GetProjectVersionRiskProfile(link hubapi.ResourceLink) (*hubapi.ProjectVersionRiskProfile, error)
	GetProjectVersionPolicyStatus(link hubapi.ResourceLink) (*hubapi.ProjectVersionPolicyStatus, error)
	DeleteProjectVersion(name string) error
	DeleteCodeLocation(name string) error
}

RawClientInterface provides an interface around hub-client-go's client, allowing it to be mocked for testing.

type RiskProfile

type RiskProfile struct {
	Categories       map[string]RiskProfileStatusCounts
	BomLastUpdatedAt string
}

RiskProfile .....

func (*RiskProfile) CriticalAndHighRiskVulnerabilityCount

func (rp *RiskProfile) CriticalAndHighRiskVulnerabilityCount() int

CriticalAndHighRiskVulnerabilityCount returns the combination of CRITICAL and HIGH risk profile count

type RiskProfileStatusCounts added in v0.0.8

type RiskProfileStatusCounts struct {
	StatusCounts map[string]int
}

RiskProfileStatusCounts .....

func (*RiskProfileStatusCounts) CriticalRiskVulnerabilityCount

func (r *RiskProfileStatusCounts) CriticalRiskVulnerabilityCount() int

CriticalRiskVulnerabilityCount return the CRITICAL vulnerability count

func (*RiskProfileStatusCounts) HighRiskVulnerabilityCount added in v0.0.8

func (r *RiskProfileStatusCounts) HighRiskVulnerabilityCount() int

HighRiskVulnerabilityCount .....

type Scan

type Scan struct {
	Stage       ScanStage
	ScanResults *ScanResults
}

Scan is a wrapper around a Hub code location, and full scan results. If `ScanResults` is nil, that means the ScanResults have not been fetched yet.

type ScanResults

type ScanResults struct {
	RiskProfile                      RiskProfile
	PolicyStatus                     PolicyStatus
	ScanSummaries                    []ScanSummary
	ComponentsHref                   string
	CodeLocationCreatedAt            string
	CodeLocationHref                 string
	CodeLocationMappedProjectVersion string
	CodeLocationName                 string
	CodeLocationType                 string
	CodeLocationURL                  string
	CodeLocationUpdatedAt            string
}

ScanResults models the results that we expect to get from the hub after scanning a docker image.

func (*ScanResults) IsDone

func (scan *ScanResults) IsDone() bool

IsDone returns true if at least one scan summary is successfully finished.

func (*ScanResults) OverallStatus

func (scan *ScanResults) OverallStatus() string

OverallStatus .....

func (*ScanResults) PolicyViolationCount

func (scan *ScanResults) PolicyViolationCount() int

PolicyViolationCount .....

func (*ScanResults) ScanSummaryStatus

func (scan *ScanResults) ScanSummaryStatus() ScanSummaryStatus

ScanSummaryStatus looks through all the scan summaries and:

  • 1+ success: returns success
  • 0 success, 1+ inprogress: returns inprogress
  • 0 success, 0 inprogress: returns failure

TODO: weird corner cases:

  • no scan summaries ... ? should that be inprogress, or error? or should we just assume that we'll always have at least 1?

func (*ScanResults) VulnerabilityCount

func (scan *ScanResults) VulnerabilityCount() int

VulnerabilityCount .....

type ScanStage

type ScanStage int

ScanStage describes the current stage of the scan

const (
	ScanStageUnknown    ScanStage = iota
	ScanStageScanClient ScanStage = iota
	ScanStageHubScan    ScanStage = iota
	ScanStageComplete   ScanStage = iota
	ScanStageFailure    ScanStage = iota
)

...

func (ScanStage) String

func (s ScanStage) String() string

String .....

type ScanSummary

type ScanSummary struct {
	CreatedAt string
	Status    ScanSummaryStatus
	UpdatedAt string
}

ScanSummary .....

func NewScanSummaryFromHub

func NewScanSummaryFromHub(hubScanSummary hubapi.ScanSummary) *ScanSummary

NewScanSummaryFromHub .....

type ScanSummaryStatus added in v0.0.15

type ScanSummaryStatus int

ScanSummaryStatus .....

const (
	ScanSummaryStatusInProgress ScanSummaryStatus = iota
	ScanSummaryStatusSuccess    ScanSummaryStatus = iota
	ScanSummaryStatusFailure    ScanSummaryStatus = iota
)

.....

func (ScanSummaryStatus) String added in v0.0.15

func (status ScanSummaryStatus) String() string

String .....

type Timings

type Timings struct {
	ScanCompletionPause    time.Duration
	FetchUnknownScansPause time.Duration
	FetchAllScansPause     time.Duration
	GetMetricsPause        time.Duration
	LoginPause             time.Duration
	RefreshScanThreshold   time.Duration
}

Timings ...

type Update

type Update interface {
	// contains filtered or unexported methods
}

Update ...

type Version

type Version struct {
	CodeLocations   []CodeLocation
	RiskProfile     RiskProfile
	PolicyStatus    PolicyStatus
	Distribution    string
	Nickname        string
	VersionName     string
	ReleasedOn      string
	ReleaseComments string
	Phase           string
}

Version .....

Jump to

Keyboard shortcuts

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