Documentation ¶
Index ¶
- Constants
- Variables
- func ParseHarborSuitImage(image string) (project, repository, reference string, err error)
- func ParseImag(image string) (domain, path, name, tag string, err error)
- func SplitImageNameTag(image string) (string, string)
- type Addition
- type AdditionLink
- type Artifact
- type Auth
- type Client
- func (c *Client) AddArtifactLabelFromKey(ctx context.Context, project, repository, reference string, key, desc string, ...) error
- func (c *Client) AttachArtifactLabel(ctx context.Context, project, repository, reference string, labelID int64) error
- func (c *Client) AttachChartLabel(ctx context.Context, repo, name, version string, labelID int64) error
- func (c *Client) CopyArtifact(ctx context.Context, project, repository, from string) (CopyArtifactResponse, error)
- func (c *Client) CreateArtifactTag(ctx context.Context, project, repository, reference string, tag Tag) error
- func (c *Client) CreateGlobalLabel(ctx context.Context, key, desc string, color LabelColor) error
- func (c *Client) CreateProject(ctx context.Context, project projectmodels.Project) error
- func (c *Client) CreateProjectLabel(ctx context.Context, projectID int64, key, desc string, color LabelColor) error
- func (c *Client) DeleteArtifact(ctx context.Context, project, repository, reference string) error
- func (c *Client) DeleteArtifactTag(ctx context.Context, project, repository, reference, tag string) error
- func (c *Client) DeleteLabel(ctx context.Context, id int) error
- func (c *Client) DeleteProject(ctx context.Context, projectID int) error
- func (c *Client) DeleteRepository(ctx context.Context, project, repository string) error
- func (c *Client) DettachArtifactLabel(ctx context.Context, project, repository, reference string, labelID int) error
- func (c *Client) DettachArtifactLabelFromKey(ctx context.Context, project, repository, reference string, key string) error
- func (c *Client) DettachChartLabel(ctx context.Context, repo, name, version string, labelID int64) ([]model.Label, error)
- func (c *Client) GetArtifact(ctx context.Context, project, repository, reference string, ...) (*Artifact, error)
- func (c *Client) GetArtifactadditionDependencies(ctx context.Context, project, repository, reference string) ([]chart.Dependency, error)
- func (c *Client) GetArtifactadditionVulnerabilities(ctx context.Context, project, repository, reference string) (Vulnerabilities, error)
- func (c *Client) GetArtifactadditions(ctx context.Context, project, repository, reference string, addition Addition) ([]byte, error)
- func (c *Client) GetIcon(ctx context.Context, digest string) (Icon, error)
- func (c *Client) GetLabel(ctx context.Context, id int) (model.Label, error)
- func (c *Client) GetProject(ctx context.Context, projectID int) (projectmodels.Project, error)
- func (c *Client) GetProjectDeletable(ctx context.Context, projectID int) error
- func (c *Client) GetProjectLogs(ctx context.Context, project string, options CommonListOptions) error
- func (c *Client) GetProjectSummary(ctx context.Context, projectID int) (apilib.ProjectSummary, error)
- func (c *Client) GetRepository(ctx context.Context, project, repository string) (Repository, error)
- func (c *Client) GetScanReportLog(ctx context.Context, project, repository, reference string, reportID int) ([]byte, error)
- func (c *Client) HeadProject(ctx context.Context, project string) error
- func (c *Client) ListArtifactTags(ctx context.Context, project, repository, reference string, ...) ([]Tag, error)
- func (c *Client) ListArtifacts(ctx context.Context, project, repository string, options ListArtifactsOptions) ([]Artifact, error)
- func (c *Client) ListAuditLogs(ctx context.Context, options CommonListOptions) ([]model.AuditLog, error)
- func (c *Client) ListChartLabels(ctx context.Context, repo, name, version string) ([]model.Label, error)
- func (c *Client) ListGlobalLabels(ctx context.Context) ([]model.Label, error)
- func (c *Client) ListProjectLabels(ctx context.Context, projectID int) ([]model.Label, error)
- func (c *Client) ListProjects(ctx context.Context, options ListProjectsOptions) error
- func (c *Client) ListRepositories(ctx context.Context, project string, options RepositoriesListOptions) (RepositoryList, error)
- func (c *Client) OIDCPing(ctx context.Context) (OIDCPing, error)
- func (c *Client) ScanArtifact(ctx context.Context, project, repository, reference string) error
- func (c *Client) SystemInfo(ctx context.Context) (systeminfo.Data, error)
- func (c *Client) UpdateLabel(ctx context.Context, label model.Label) error
- func (c *Client) UpdateProject(ctx context.Context, projectID int, project projectmodels.Project) error
- func (c *Client) UpdateRepository(ctx context.Context, project string, repository Repository) error
- type CommonListOptions
- type CopyArtifactResponse
- type Error
- type GetArtifactOptions
- type Icon
- type Label
- type LabelColor
- type ListArtifactsOptions
- type ListProjectsOptions
- type ListTagsOptions
- type OCIDistributionClient
- func (c *OCIDistributionClient) DeleteManifest(ctx context.Context, name, reference string) error
- func (c *OCIDistributionClient) GetManifest(ctx context.Context, name, reference string) (*imagespecv1.Manifest, error)
- func (c *OCIDistributionClient) ListTags(ctx context.Context, name string) (*distributionspecsv1.TagList, error)
- func (c *OCIDistributionClient) ListTagsPaged(ctx context.Context, name string, n, last int) (*distributionspecsv1.TagList, error)
- func (c *OCIDistributionClient) Ping(ctx context.Context) error
- type OIDCPing
- type Option
- type RepositoriesListOptions
- type Repository
- type RepositoryList
- type Tag
- type Vulnerabilities
Examples ¶
Constants ¶
const ( AdditionBuildHistory = "build_history" AdditionHelmValues = "values.yaml" AdditionHelmReadme = "readme.md" AdditionDependencies = "dependencies" AdditionVulnerabilities = "vulnerabilities" )
const ( LabelColorRed = "#C92100" LabelColorGreen = "#00AB9A" LabelColorWhite = "#FFFFFF" LabelColorYellow = "#FFDC0B" )
Variables ¶
var ErrNotHarborImage = errors.New("not a harbor suit image")
Functions ¶
func ParseHarborSuitImage ¶
ParseHarborImage parse a image and return harbor project,repository,reference
func ParseImag ¶
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 SplitImageNameTag ¶
Types ¶
type AdditionLink ¶
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"` // the list of tags that attached to the artifact AdditionLinks map[string]AdditionLink `json:"addition_links"` // the resource link for build history(image), values.yaml(chart), dependency(chart), etc Labels []Label `json:"labels"` ScanOverview map[string]vuln.NativeReportSummary `json:"scan_overview"` }
* Redefined AdditionLink,Tag,Label * To avoid import lots of useless dependencies from harbor like beego,borm etc..
type Client ¶
func NewClient ¶
Example ¶
package main import ( "context" "fmt" "log" client "github.com/cnfatal/harbor-client" ) func main() { cli, err := client.NewClient("harbor.example.com", client.WithBasicAuth("admin", "password")) if err != nil { log.Fatal(err) } sysinfo, err := cli.SystemInfo(context.Background()) if err != nil { log.Fatal(err) } fmt.Println(sysinfo) image := "harbor.example.com/library/nginx:alpine" project, repository, reference, err := client.ParseHarborSuitImage(image) if err != nil { log.Fatal(err) } artifact, err := cli.GetArtifact(context.Background(), project, repository, reference, client.GetArtifactOptions{ WithScanOverview: true, WithLabel: true, }) if err != nil { log.Fatal(err) } fmt.Println(artifact) }
Output:
func (*Client) AddArtifactLabelFromKey ¶
func (c *Client) AddArtifactLabelFromKey(ctx context.Context, project, repository, reference string, key, desc string, color LabelColor) error
AddArtifactLabelFromKey adds a label to artifact by the key. it find key name from all keys if key not exist,create and do it again
func (*Client) AttachArtifactLabel ¶
func (c *Client) AttachArtifactLabel(ctx context.Context, project, repository, reference string, labelID int64) error
POST /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/labels body: {"id":2}
func (*Client) AttachChartLabel ¶
func (c *Client) AttachChartLabel(ctx context.Context, repo, name, version string, labelID int64) error
POST /chartrepo/{repo}/charts/{name}/{version}/labels body: {"id":2}
func (*Client) CopyArtifact ¶
func (c *Client) CopyArtifact(ctx context.Context, project, repository, from string) (CopyArtifactResponse, error)
POST /projects/{project_name}/repositories/{repository_name}/artifacts from: The artifact from which the new artifact is copied from, the format should be "project/repository:tag" or "project/repository@digest".
func (*Client) CreateArtifactTag ¶
func (c *Client) CreateArtifactTag(ctx context.Context, project, repository, reference string, tag Tag) error
POST /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/tags
func (*Client) CreateGlobalLabel ¶
POST /labels
func (*Client) CreateProject ¶
POST /projects
func (*Client) CreateProjectLabel ¶
func (c *Client) CreateProjectLabel(ctx context.Context, projectID int64, key, desc string, color LabelColor) error
POST /labels
func (*Client) DeleteArtifact ¶
DELETE /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}
func (*Client) DeleteArtifactTag ¶
func (c *Client) DeleteArtifactTag(ctx context.Context, project, repository, reference, tag string) error
DELETE /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/tags/{tag_name}
func (*Client) DeleteLabel ¶
DELETE /labels/{id}
func (*Client) DeleteProject ¶
DELETE /projects/{project_id}
func (*Client) DeleteRepository ¶
DeleteRepository DELETE /projects/{project_name}/repositories/{repository_name}
func (*Client) DettachArtifactLabel ¶
func (c *Client) DettachArtifactLabel(ctx context.Context, project, repository, reference string, labelID int) error
DELETE /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/labels/{label_id}
func (*Client) DettachArtifactLabelFromKey ¶
func (*Client) DettachChartLabel ¶
func (c *Client) DettachChartLabel(ctx context.Context, repo, name, version string, labelID int64) ([]model.Label, error)
Delete /chartrepo/{repo}/charts/{name}/{version}/labels
func (*Client) GetArtifact ¶
func (c *Client) GetArtifact(ctx context.Context, project, repository, reference string, options GetArtifactOptions) (*Artifact, error)
GET /repositories/{{repository_name}}/artifacts/{{reference}}?
func (*Client) GetArtifactadditionDependencies ¶
func (*Client) GetArtifactadditionVulnerabilities ¶
func (*Client) GetArtifactadditions ¶
func (c *Client) GetArtifactadditions(ctx context.Context, project, repository, reference string, addition Addition) ([]byte, error)
GET /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/additions/{addition}
func (*Client) GetProject ¶
GET /projects/{project_id}
func (*Client) GetProjectDeletable ¶
GET /projects/{project_id}/_deletable
func (*Client) GetProjectLogs ¶
func (c *Client) GetProjectLogs(ctx context.Context, project string, options CommonListOptions) error
GET /projects/{project_name}/logs
func (*Client) GetProjectSummary ¶
func (c *Client) GetProjectSummary(ctx context.Context, projectID int) (apilib.ProjectSummary, error)
GET /projects/{project_id}/summary
func (*Client) GetRepository ¶
GetRepositories GET /projects/{project_name}/repositories/{repository_name}
func (*Client) GetScanReportLog ¶
func (c *Client) GetScanReportLog(ctx context.Context, project, repository, reference string, reportID int) ([]byte, error)
GET /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/scan/{report_id}/log
func (*Client) HeadProject ¶
HEAD /projects/{project_id}
func (*Client) ListArtifactTags ¶
func (c *Client) ListArtifactTags(ctx context.Context, project, repository, reference string, options ListTagsOptions) ([]Tag, error)
GET /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/tags
func (*Client) ListArtifacts ¶
func (c *Client) ListArtifacts(ctx context.Context, project, repository string, options ListArtifactsOptions) ([]Artifact, error)
GET /projects/{project_name}/repositories/{repository_name}/artifacts
func (*Client) ListAuditLogs ¶
func (c *Client) ListAuditLogs(ctx context.Context, options CommonListOptions) ([]model.AuditLog, error)
GET /audit-logs
func (*Client) ListChartLabels ¶
func (c *Client) ListChartLabels(ctx context.Context, repo, name, version string) ([]model.Label, error)
GET /chartrepo/{repo}/charts/{name}/{version}/labels
func (*Client) ListGlobalLabels ¶
GET /labels?scope=g
func (*Client) ListProjectLabels ¶
GET /labels?scope=p&project_id={id}
func (*Client) ListProjects ¶
func (c *Client) ListProjects(ctx context.Context, options ListProjectsOptions) error
GET /projects
func (*Client) ListRepositories ¶
func (c *Client) ListRepositories(ctx context.Context, project string, options RepositoriesListOptions) (RepositoryList, error)
ListRepositories GET /projects/{project_name}/repositories
func (*Client) ScanArtifact ¶
POST /projects/{project_name}/repositories/{repository_name}/artifacts/{reference}/scan
func (*Client) SystemInfo ¶
SystemInfo GET /systeminfo
func (*Client) UpdateLabel ¶
PUT /labels/{id}
func (*Client) UpdateProject ¶
func (c *Client) UpdateProject(ctx context.Context, projectID int, project projectmodels.Project) error
PUT /projects/{project_id}
func (*Client) UpdateRepository ¶
PutRepository PUT /projects/{project_name}/repositories/{repository_name}
type CommonListOptions ¶
type CommonListOptions struct { // The page number // Default value: 1 Page int `json:"page"` // The size of per page // Default value: 10 Size int `json:"size"` // Query string to query resources. // Supported query patterns are "exact match(k=v)", "fuzzy match(k=~v)","range(k=[min~max])", // "list with union releationship(k={v1 v2 v3})" and"list with intersetion relationship(k=(v1 v2 v3))". // The value of range and list can be string(enclosed by " or '),integer or time(in format "2020-04-09 02:36:00"). // All of these query patterns should be put in the query string "q=xxx" and splitted by ",". e.g. q=k1=v1,k2=~v2,k3=[min~max] Q string `json:"q"` }
type CopyArtifactResponse ¶
type CopyArtifactResponse struct {
Location string `json:"location"` // The location of the resource
}
type Error ¶
Error same as https://github.com/goharbor/harbor/blob/4e1f6633afb824cd16341044a0e82f4f1f230cd2/src/lib/errors/errors.go#L32
type GetArtifactOptions ¶
type Icon ¶
type Label ¶
type Label struct { ID int64 `orm:"pk;auto;column(id)" json:"id"` Name string `orm:"column(name)" json:"name"` Description string `orm:"column(description)" json:"description"` Color string `orm:"column(color)" json:"color"` Level string `orm:"column(level)" json:"-"` Scope string `orm:"column(scope)" json:"scope"` ProjectID int64 `orm:"column(project_id)" json:"project_id"` CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"` UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"` Deleted bool `orm:"column(deleted)" json:"deleted"` }
Label holds information used for a label
type ListArtifactsOptions ¶
type ListArtifactsOptions struct { CommonListOptions GetArtifactOptions }
type ListProjectsOptions ¶
type ListProjectsOptions struct { CommonListOptions Name string `json:"name,omitempty"` Public bool `json:"public,omitempty"` Owner string `json:"owner,omitempty"` }
type ListTagsOptions ¶
type ListTagsOptions struct { CommonListOptions WithImmutableStatus bool WithSignature bool }
type OCIDistributionClient ¶
func NewOCIDistributionClient ¶
func NewOCIDistributionClient(server string, auth Auth) (*OCIDistributionClient, error)
OCI Distribution Specification Client
For more information visit below URL https://github.com/opencontainers/distribution-spec/blob/main/spec.md#endpoints
Example ¶
package main import ( "context" "fmt" "log" client "github.com/cnfatal/harbor-client" ) func main() { ocicli, err := client.NewOCIDistributionClient("registry.example.com", client.BasicAuth("user", "password")) if err != nil { log.Fatal(err) } if err := ocicli.Ping(context.Background()); err != nil { log.Fatal(err) } tags, err := ocicli.ListTags(context.Background(), "library/nginx") if err != nil { log.Fatal(err) } fmt.Printf("tags: %s", tags.Tags) }
Output:
func (*OCIDistributionClient) DeleteManifest ¶
func (c *OCIDistributionClient) DeleteManifest(ctx context.Context, name, reference string) error
end-9 DELETE /v2/<name>/manifests/<reference>
func (*OCIDistributionClient) GetManifest ¶
func (c *OCIDistributionClient) GetManifest(ctx context.Context, name, reference string) (*imagespecv1.Manifest, error)
end-3 GET/HEAD /v2/<name>/manifests/<reference>
func (*OCIDistributionClient) ListTags ¶
func (c *OCIDistributionClient) ListTags(ctx context.Context, name string) (*distributionspecsv1.TagList, error)
end-8a GET /v2/<name>/tags/list
func (*OCIDistributionClient) ListTagsPaged ¶
func (c *OCIDistributionClient) ListTagsPaged(ctx context.Context, name string, n, last int) (*distributionspecsv1.TagList, error)
end-8b GET /v2/<name>/tags/list?n=<integer>&last=<integer>
func (*OCIDistributionClient) Ping ¶
func (c *OCIDistributionClient) Ping(ctx context.Context) error
see: https://github.com/opencontainers/distribution-spec/blob/main/spec.md#determining-support To check whether or not the registry implements this specification, perform a GET request to the following endpoint: /v2/ end-1. If the response is 200 OK, then the registry implements this specification. It can used to detectd server connection and auth too. end-1 GET /v2/ 200 404/401
type RepositoriesListOptions ¶
type RepositoriesListOptions struct {
CommonListOptions
}
type Repository ¶
type Repository struct { RepositoryID int64 `json:"repositoryID,omitempty"` Name string `json:"name,omitempty"` ProjectID int64 `json:"projectID,omitempty"` Description string `json:"description,omitempty"` PullCount int64 `json:"pullCount,omitempty"` StarCount int64 `json:"starCount,omitempty"` CreationTime time.Time `json:"creationTime,omitempty"` UpdateTime time.Time `json:"updateTime,omitempty"` }
type RepositoryList ¶
type RepositoryList struct { Total int `json:"total,omitempty"` Items []Repository `json:"items,omitempty"` Next string `json:"next,omitempty"` }
type Tag ¶
type Tag struct { ID int64 `orm:"pk;auto;column(id)" json:"id"` RepositoryID int64 `orm:"column(repository_id)" json:"repository_id"` // tags are the resources of repository, one repository only contains one same name tag ArtifactID int64 `orm:"column(artifact_id)" json:"artifact_id"` // the artifact ID that the tag attaches to, it changes when pushing a same name but different digest artifact Name string `orm:"column(name)" json:"name"` PushTime time.Time `orm:"column(push_time)" json:"push_time"` PullTime time.Time `orm:"column(pull_time)" json:"pull_time"` Immutable bool `json:"immutable"` Signed bool `json:"signed"` }
Tag is the overall view of tag