hub

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 .....

func NewClient

func NewClient(username string, password string, host string, client RawClientInterface, scanCompletionPause time.Duration, fetchUnknownScansPause time.Duration, fetchAllScansPause time.Duration) *Client

NewClient returns a new Client. It will not be logged in.

func (*Client) FinishScanClient

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

FinishScanClient ...

func (*Client) HasFetchedScans

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

HasFetchedScans ...

func (*Client) Host

func (hub *Client) Host() string

Host ...

func (*Client) InProgressScans

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

InProgressScans ...

func (*Client) Model

func (hub *Client) Model() <-chan *api.ModelHub

Model ...

func (*Client) ResetCircuitBreaker

func (hub *Client) ResetCircuitBreaker()

ResetCircuitBreaker ...

func (*Client) ScanResults

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

ScanResults ...

func (*Client) ScansCount

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

ScansCount ...

func (*Client) SetTimeout

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

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

func (*Client) StartScanClient

func (hub *Client) StartScanClient(scanName string)

StartScanClient ...

func (*Client) Stop

func (hub *Client) Stop()

Stop ...

func (*Client) StopCh

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

StopCh returns a reference to the stop channel

func (*Client) Updates

func (hub *Client) 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.)

func (*Client) Version

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

Version fetches the hub version

type ClientInterface

type ClientInterface interface {
	// commands coming in
	StartScanClient(scanName string)
	FinishScanClient(scanName string, scanErr error)
	SetTimeout(timeout time.Duration)
	ResetCircuitBreaker()
	// read-only queries
	Host() string
	Version() (string, error)
	// read-only, async queries (the channel produces a single event)
	Model() <-chan *api.ModelHub
	HasFetchedScans() <-chan bool
	ScansCount() <-chan int
	InProgressScans() <-chan []string
	ScanResults() <-chan map[string]*Scan
	Updates() <-chan Update
	// prelude to clean-up
	Stop()
	StopCh() <-chan struct{}
}

ClientInterface .....

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 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 PolicyStatus

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

PolicyStatus .....

func (*PolicyStatus) ViolationCount

func (ps *PolicyStatus) ViolationCount() int

ViolationCount .....

type PolicyStatusType added in v0.0.8

type PolicyStatusType int

PolicyStatusType .....

const (
	PolicyStatusTypeNotInViolation        PolicyStatusType = iota
	PolicyStatusTypeInViolation           PolicyStatusType = iota
	PolicyStatusTypeInViolationOverridden PolicyStatusType = iota
)

.....

func (PolicyStatusType) MarshalJSON added in v0.0.8

func (p PolicyStatusType) MarshalJSON() ([]byte, error)

MarshalJSON .....

func (PolicyStatusType) MarshalText added in v0.0.8

func (p PolicyStatusType) MarshalText() (text []byte, err error)

MarshalText .....

func (PolicyStatusType) String added in v0.0.8

func (p PolicyStatusType) String() string

String .....

func (*PolicyStatusType) UnmarshalText added in v0.0.18

func (p *PolicyStatusType) UnmarshalText(text []byte) (err error)

UnmarshalText .....

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 Result

type Result struct {
	Value interface{}
	Err   error
}

Result models computations that may succeed or fail.

type RiskProfile

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

RiskProfile .....

func (*RiskProfile) HighRiskVulnerabilityCount

func (rp *RiskProfile) HighRiskVulnerabilityCount() int

HighRiskVulnerabilityCount .....

type RiskProfileCategory added in v0.0.8

type RiskProfileCategory int

RiskProfileCategory .....

const (
	RiskProfileCategoryActivity      RiskProfileCategory = iota
	RiskProfileCategoryLicense       RiskProfileCategory = iota
	RiskProfileCategoryOperational   RiskProfileCategory = iota
	RiskProfileCategoryVersion       RiskProfileCategory = iota
	RiskProfileCategoryVulnerability RiskProfileCategory = iota
)

.....

func (RiskProfileCategory) MarshalText added in v0.0.8

func (r RiskProfileCategory) MarshalText() (text []byte, err error)

MarshalText .....

func (RiskProfileCategory) String added in v0.0.8

func (r RiskProfileCategory) String() string

String .....

func (*RiskProfileCategory) UnmarshalJSON added in v0.0.18

func (r *RiskProfileCategory) UnmarshalJSON(data []byte) error

UnmarshalJSON .....

func (*RiskProfileCategory) UnmarshalText added in v0.0.18

func (r *RiskProfileCategory) UnmarshalText(text []byte) (err error)

UnmarshalText .....

type RiskProfileStatus added in v0.0.8

type RiskProfileStatus int

RiskProfileStatus .....

const (
	RiskProfileStatusHigh    RiskProfileStatus = iota
	RiskProfileStatusMedium  RiskProfileStatus = iota
	RiskProfileStatusLow     RiskProfileStatus = iota
	RiskProfileStatusOK      RiskProfileStatus = iota
	RiskProfileStatusUnknown RiskProfileStatus = iota
)

.....

func (RiskProfileStatus) MarshalJSON added in v0.0.8

func (r RiskProfileStatus) MarshalJSON() ([]byte, error)

MarshalJSON .....

func (RiskProfileStatus) MarshalText added in v0.0.8

func (r RiskProfileStatus) MarshalText() (text []byte, err error)

MarshalText .....

func (RiskProfileStatus) String added in v0.0.8

func (r RiskProfileStatus) String() string

String .....

func (*RiskProfileStatus) UnmarshalJSON added in v0.0.18

func (r *RiskProfileStatus) UnmarshalJSON(data []byte) error

UnmarshalJSON .....

func (*RiskProfileStatus) UnmarshalText added in v0.0.18

func (r *RiskProfileStatus) UnmarshalText(text []byte) (err error)

UnmarshalText .....

type RiskProfileStatusCounts added in v0.0.8

type RiskProfileStatusCounts struct {
	StatusCounts map[RiskProfileStatus]int
}

RiskProfileStatusCounts .....

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() PolicyStatusType

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 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