harbor

package
v1.22.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

* OCI Distribution Specification Client * * For more information visit below URL * https://github.com/opencontainers/distribution-spec/blob/main/spec.md#endpoints *

Index

Constants

View Source
const LabelColorRed = "#C92100"

Variables

View Source
var ErrNotHarborImage = errors.New("not a harbor suit image")

Functions

func ParseImag

func ParseImag(image string) (domain, path, name, tag string, err error)

ParseImag barbor.foo.com/project/artifact:tag -> barbor.foo.com,project,artifact,tag barbor.foo.com/project/foo/artifact:tag -> barbor.foo.com,project,foo/artifact,tag barbor.foo.com/artifact:tag -> barbor.foo.com,library,artifact,tag project/artifact:tag -> docker.io,project,artifact,tag

func TryLogin

func TryLogin(ctx context.Context, registryurl string, username, password string) error

参考OCI规范此段实现 https://github.com/opencontainers/distribution-spec/blob/main/spec.md#determining-support 目前大部分(所有)镜像仓库均实现了OCI Distribution 规范,可以使用 /v2 接口进行推断, 如果认证成功则返回200则认为实现了OCI且认证成功

Types

type AdditionLink struct {
	HREF     string `json:"href"`
	Absolute bool   `json:"absolute"` // specify the href is an absolute URL or not
}

AdditionLink is a link via that the addition can be fetched

type Artifact

type Artifact struct {
	artifact.Artifact
	Tags          []Tag                               `json:"tags"`
	AdditionLinks map[string]AdditionLink             `json:"addition_links"`
	Labels        []Label                             `json:"labels"`
	ScanOverview  map[string]vuln.NativeReportSummary `json:"scan_overview"`
}

nolint: tagliatelle

type Client

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

func NewClient

func NewClient(host string, username, password string) (*Client, error)

func (*Client) AddArtifactLabel

func (c *Client) AddArtifactLabel(ctx context.Context, image string, labelid int64) error

POST https://{host}/api/v2.0/projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/labels {"id":2}

func (*Client) AddArtifactLabelFromKey

func (c *Client) AddArtifactLabelFromKey(ctx context.Context, image string, key, desc string) error

func (*Client) CreateGlobalLabels

func (c *Client) CreateGlobalLabels(ctx context.Context, key, desc string) error

POST https://{host}/api/v2.0/projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/labels

func (*Client) CreateProjectLabels

func (c *Client) CreateProjectLabels(ctx context.Context, projectid int64, key, desc string) error

func (*Client) DeleteArtifactLabel

func (c *Client) DeleteArtifactLabel(ctx context.Context, image string, labelid int64) error

DELETE https://{host}/api/v2.0/projects/projects/{{project_name}}/repositories/{{repository_name}}/artifacts/{{reference}}/labels/{label_id}

func (*Client) DeleteArtifactLabelFromKey

func (c *Client) DeleteArtifactLabelFromKey(ctx context.Context, image string, key string) error

func (*Client) GetArtifact

func (c *Client) GetArtifact(ctx context.Context, image string, options GetArtifactOptions) (*Artifact, error)

GET https://{host}/api/v2.0/projects/{{project_name}}/repositories/{{repository_name}}/artifacts/{{reference}}?with_scan_overview=true

func (*Client) GetArtifactVulnerabilities

func (c *Client) GetArtifactVulnerabilities(ctx context.Context, image string) (*Vulnerabilities, error)

GET https://{host}/api/v2.0/projects/{project}/repositories/{repository_name}/artifacts/{reference}/additions/vulnerabilities

func (*Client) ListArtifact

func (c *Client) ListArtifact(ctx context.Context, image string, options GetArtifactOptions) ([]Artifact, error)

GET https://{host}/api/v2.0/projects/{{project_name}}/repositories/{{repository_name}}/artifacts

func (*Client) ListGlobalLabels

func (c *Client) ListGlobalLabels(ctx context.Context) ([]model.Label, error)

GET https://{host}/api/v2.0/labels?scope=g

func (*Client) ListProjectLabels

func (c *Client) ListProjectLabels(ctx context.Context, projectid int) ([]model.Label, error)

GET https://{host}/api/v2.0/labels?scope=p&project_id={id}

func (*Client) ScanArtifact

func (c *Client) ScanArtifact(ctx context.Context, image string) error

POST https://{host}/api/v2.0/projects/{{project_name}}/repositories/{{repository_name}}/artifacts/{{reference}}/scan

func (*Client) SystemInfo

func (c *Client) SystemInfo(ctx context.Context) (*SystemInfo, error)

GET https://{host}/api/v2.0/systeminfo

type GetArtifactOptions

type GetArtifactOptions struct {
	WithTag             bool
	WithScanOverview    bool
	WithLabel           bool
	WithImmutableStatus bool
	WithSignature       bool
}

type HarborAuth

type HarborAuth struct {
	Username string
	Password string
}

type Label

type Label struct {
	ID           int64     `json:"id"`
	Name         string    `json:"name"`
	Description  string    `json:"description"`
	Color        string    `json:"color"`
	Level        string    `json:"level"`
	Scope        string    `json:"scope"`
	ProjectID    int64     `json:"project_id"`
	CreationTime time.Time `json:"creation_time"`
	UpdateTime   time.Time `json:"update_time"`
	Deleted      bool      `json:"deleted"`
}

Label holds information used for a label nolint: tagliatelle

type OCIDistributionClient

type OCIDistributionClient struct {
	Server   string
	Username string
	Password string
}

func NewOCIDistributionClient

func NewOCIDistributionClient(server, username, password string) *OCIDistributionClient

func (*OCIDistributionClient) ListTags

func (c *OCIDistributionClient) ListTags(ctx context.Context, image string) (*specsv1.TagList, error)

end-8a GET /v2/<name>/tags/list

func (*OCIDistributionClient) Ping

参考OCI规范此段实现 https://github.com/opencontainers/distribution-spec/blob/main/spec.md#determining-support 目前大部分(所有)镜像仓库均实现了OCI Distribution 规范,可以使用 /v2 接口进行推断, 如果认证成功则返回200则认为实现了OCI且认证成功 end-1 GET /v2/ 200 404/401

type SystemInfo

type SystemInfo struct {
	WithNotary                  bool   `json:"with_notary"`
	AuthMode                    string `json:"auth_mode"`
	RegistryUrl                 string `json:"registry_url"`
	ExternalUrl                 string `json:"external_url"`
	ProjectCreationRestriction  string `json:"project_creation_restriction"`
	SelfRegistration            bool   `json:"self_registration"`
	HasCaRoot                   bool   `json:"has_ca_root"`
	HarborVersion               string `json:"harbor_version"`
	RegistryStorageProviderName string `json:"registry_storage_provider_name"`
	ReadOnly                    bool   `json:"read_only"`
	WithChartmuseum             bool   `json:"with_chartmuseum"`
	NotificationEnable          bool   `json:"notification_enable"`
}

nolint: tagliatelle

type Tag

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

Tag is the overall view of tag nolint: tagliatelle

type Vulnerabilities

type Vulnerabilities map[string]vuln.Report

Jump to

Keyboard shortcuts

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