instance

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Artifact

type Artifact struct {
	Digest     string `json:"digest"`
	ExtraAttrs struct {
		Architecture string `json:"architecture"`
		Author       string `json:"author"`
		Config       struct {
			Cmd          []string          `json:"Cmd"`
			Entrypoint   []string          `json:"Entrypoint"`
			Env          []string          `json:"Env"`
			ExposedPorts map[string]any    `json:"ExposedPorts"`
			Labels       map[string]string `json:"Labels"`
			User         string            `json:"User"`
			WorkingDir   string            `json:"WorkingDir"`
		} `json:"config"`
		Created time.Time `json:"created"`
		Os      string    `json:"os"`
	} `json:"extra_attrs"`
	Icon              string                          `json:"icon"`
	ID                int64                           `json:"id"`
	ManifestMediaType string                          `json:"manifest_media_type"`
	MediaType         string                          `json:"media_type"`
	ProjectID         int64                           `json:"project_id"`
	PullTime          time.Time                       `json:"pull_time"`
	PushTime          time.Time                       `json:"push_time"`
	References        []ArtifactReference             `json:"references"`
	RepositoryID      int64                           `json:"repository_id"`
	ScanOverview      map[string]ArtifactScanOverview `json:"scan_overview"`
	Size              int64                           `json:"size"`
	Tags              []ArtifactTag                   `json:"tags"`
	Type              string                          `json:"type"`
}

Artifact is the structure of a single artifact returned by the Harbor API.

type ArtifactReference

type ArtifactReference struct {
	ChildDigest string `json:"child_digest"`
	ChildID     int64  `json:"child_id"`
	ParentID    int64  `json:"parent_id"`
	Platform    struct {
		OsFeatures   []string `json:"OsFeatures"`
		Architecture string   `json:"architecture"`
		Os           string   `json:"os"`
	} `json:"platform"`
	Urls []string `json:"urls"`
}

type ArtifactScanOverview

type ArtifactScanOverview struct {
	CompletePercent int64     `json:"complete_percent"`
	Duration        int64     `json:"duration"`
	EndTime         time.Time `json:"end_time"`
	ReportID        string    `json:"report_id"`
	ScanStatus      string    `json:"scan_status"`
	Severity        string    `json:"severity"`
	StartTime       time.Time `json:"start_time"`
}

type ArtifactTag

type ArtifactTag struct {
	ArtifactID   int64     `json:"artifact_id"`
	ID           int64     `json:"id"`
	Immutable    bool      `json:"immutable"`
	Name         string    `json:"name"`
	PullTime     time.Time `json:"pull_time"`
	PushTime     time.Time `json:"push_time"`
	RepositoryID int64     `json:"repository_id"`
	Signed       bool      `json:"signed"`
}

type ArtifactsData

type ArtifactsData struct {
	Artifacts []Artifact `json:"artifacts"`
	Total     int64      `json:"total"`
}

ArtifactsData contains all the artifacts returned by the Harbor API and the total number of artifacts for pagination.

type BuildHistoryItem

type BuildHistoryItem struct {
	Created    time.Time `json:"created"`
	CreatedBy  string    `json:"created_by"`
	EmptyLayer bool      `json:"empty_layer,omitempty"`
}

type Config

type Config struct {
	Address  string `json:"address"`
	Username string `json:"username"`
	Password string `json:"password"`
	Token    string `json:"token"`
}

Config is the structure of the configuration for a single Harbor database instance.

type Instance

type Instance interface {
	GetName() string
	GetProjects(ctx context.Context, page, pageSize string) (*ProjectsData, error)
	GetRepositories(ctx context.Context, projectName, query, page, pageSize string) (*RepositoriesData, error)
	GetArtifacts(ctx context.Context, projectName, repositoryName, query, page, pageSize string) (*ArtifactsData, error)
	GetArtifact(ctx context.Context, projectName, repositoryName, artifactReference string) (*Artifact, error)
	GetVulnerabilities(ctx context.Context, projectName, repositoryName, artifactReference string) (map[string]Vulnerability, error)
	GetBuildHistory(ctx context.Context, projectName, repositoryName, artifactReference string) ([]BuildHistoryItem, error)
}

func New

func New(name string, options map[string]any) (Instance, error)

New returns a new Harbor instance for the given configuration.

type MockInstance

type MockInstance struct {
	mock.Mock
}

MockInstance is an autogenerated mock type for the Instance type

func NewMockInstance

func NewMockInstance(t NewMockInstanceT) *MockInstance

NewMockInstance creates a new instance of MockInstance. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockInstance) GetArtifact

func (_m *MockInstance) GetArtifact(ctx context.Context, projectName string, repositoryName string, artifactReference string) (*Artifact, error)

GetArtifact provides a mock function with given fields: ctx, projectName, repositoryName, artifactReference

func (*MockInstance) GetArtifacts

func (_m *MockInstance) GetArtifacts(ctx context.Context, projectName string, repositoryName string, query string, page string, pageSize string) (*ArtifactsData, error)

GetArtifacts provides a mock function with given fields: ctx, projectName, repositoryName, query, page, pageSize

func (*MockInstance) GetBuildHistory

func (_m *MockInstance) GetBuildHistory(ctx context.Context, projectName string, repositoryName string, artifactReference string) ([]BuildHistoryItem, error)

GetBuildHistory provides a mock function with given fields: ctx, projectName, repositoryName, artifactReference

func (*MockInstance) GetName

func (_m *MockInstance) GetName() string

GetName provides a mock function with given fields:

func (*MockInstance) GetProjects

func (_m *MockInstance) GetProjects(ctx context.Context, page string, pageSize string) (*ProjectsData, error)

GetProjects provides a mock function with given fields: ctx, page, pageSize

func (*MockInstance) GetRepositories

func (_m *MockInstance) GetRepositories(ctx context.Context, projectName string, query string, page string, pageSize string) (*RepositoriesData, error)

GetRepositories provides a mock function with given fields: ctx, projectName, query, page, pageSize

func (*MockInstance) GetVulnerabilities

func (_m *MockInstance) GetVulnerabilities(ctx context.Context, projectName string, repositoryName string, artifactReference string) (map[string]Vulnerability, error)

GetVulnerabilities provides a mock function with given fields: ctx, projectName, repositoryName, artifactReference

type NewMockInstanceT

type NewMockInstanceT interface {
	mock.TestingT
	Cleanup(func())
}

type Project

type Project struct {
	Name       string `json:"name"`
	Deleted    bool   `json:"deleted"`
	RepoCount  int64  `json:"repo_count"`
	ChartCount int64  `json:"chart_count"`
	ProjectID  int64  `json:"project_id"`
	RegistryID int64  `json:"registry_id"`
	Metadata   struct {
		EnableContentTrust   string `json:"enable_content_trust"`
		AutoScan             string `json:"auto_scan"`
		Severity             string `json:"severity"`
		Public               string `json:"public"`
		ReuseSysCveAllowlist string `json:"reuse_sys_cve_allowlist"`
		PreventVul           string `json:"prevent_vul"`
		RetentionID          string `json:"retention_id"`
	} `json:"metadata"`
}

Project is the structure for a project returned by the Harbor API.

type ProjectsData

type ProjectsData struct {
	Projects []Project `json:"projects"`
	Total    int64     `json:"total"`
}

ProjectsData contains all the projects returned by the Harbor API and the total number of projects for pagination. The total number of projects is returned via the "x-total-count" header from teh API.

type RepositoriesData

type RepositoriesData struct {
	Repositories []Repository `json:"repositories"`
	Total        int64        `json:"total"`
}

RepositoriesData contains all the repositories returned by the Harbor API and the total number of repositories for pagination.

type Repository

type Repository struct {
	ArtifactCount int64     `json:"artifact_count"`
	ID            int64     `json:"id"`
	Name          string    `json:"name"`
	ProjectID     int64     `json:"project_id"`
	PullCount     int64     `json:"pull_count"`
	CreationTime  string    `json:"creation_time"`
	UpdateTime    time.Time `json:"update_time"`
}

Repository is the structure of a single repository returned by the Harbor API.

type ResponseError

type ResponseError struct {
	Errors []struct {
		Code    string `json:"code"`
		Message string `json:"message"`
	} `json:"errors"`
}

ResponseError is the structure for a failed Harbor API request.

type Vulnerability

type Vulnerability struct {
	GeneratedAt time.Time `json:"generated_at"`
	Scanner     struct {
		Name    string `json:"name"`
		Vendor  string `json:"vendor"`
		Version string `json:"version"`
	} `json:"scanner"`
	Severity        string `json:"severity"`
	Vulnerabilities []struct {
		ID              string   `json:"id"`
		Package         string   `json:"package"`
		Version         string   `json:"version"`
		FixVersion      string   `json:"fix_version"`
		Severity        string   `json:"severity"`
		Description     string   `json:"description"`
		Links           []string `json:"links"`
		ArtifactDigests []string `json:"artifact_digests"`
	} `json:"vulnerabilities"`
}

Jump to

Keyboard shortcuts

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