harbor

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 9 Imported by: 0

README

go-harbor

A Harbor API client enabling Go programs to interact with Harbor in a simple and uniform way

GitHub license travis codecov

Coverage

This API client package covers most of the existing Harbor API calls and is updated regularly to add new and/or missing endpoints. Currently the following services are supported:

  • Users
  • Projects
  • Repositories
  • Artifacts
  • Jobs
  • Policies
  • Targets
  • SystemInfo
  • LDAP
  • Configurations

Usage

import "github.com/TimeBye/go-harbor"

Some API methods have optional parameters that can be passed. For example, to list all projects for user "haobor":

harborClient, err := harbor.NewClientSet("host", "username", "password")
if err != nil {
    panic(err)
}
query := options.ProjectsListOptions{}
projects, err := harborClient.V2.List(&query)

For complete usage of go-harbor, see the full package docs.

ToDo

  • The biggest thing this package still needs is tests 😞

Issues

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientSet

func NewClientSet(host, username, password string) (clientSet *client2.Clientset, err error)

Types

type AccessLog

type AccessLog struct {
	LogID     int       `json:"log_id"`
	Username  string    `json:"username"`
	ProjectID int64     `json:"project_id"`
	RepoName  string    `json:"repo_name"`
	RepoTag   string    `json:"repo_tag"`
	GUID      string    `json:"guid"`
	Operation string    `json:"operation"`
	OpTime    time.Time `json:"op_time"`
}

AccessLog holds information about logs which are used to record the actions that user take to the resourses.

type Artifact

type Artifact struct {
	artifact.Artifact
	Tag          map[string]interface{} `json:"tag,omitempty"`
	ScanOverview map[string]interface{} `json:"scan_overview,omitempty"`
}

type ArtifactOption

type ArtifactOption struct {
	ListOptions
	WithImmutableStatus string `json:"with_immutable_status,omitempty" url:"with_immutable_status,omitempty"`
	WithLabel           bool   `json:"with_label,omitempty" url:"with_label,omitempty"`
	WithScanOverview    bool   `json:"with_scan_overview,omitempty" url:"with_scan_overview"`
	WithSignature       bool   `json:"with_signature,omitempty" url:"with_signature,omitempty"`
	WithTag             bool   `json:"with_tag,omitempty" url:"with_tag,omitempty" `
	Q                   string `json:"q,omitempty" url:"q,omitempty"`
}

type ArtifactService

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

func (*ArtifactService) List

func (as *ArtifactService) List(project string, repositories string, opt *ArtifactOption) ([]Artifact, *gorequest.Response, []error)

List /projects/{project_name}/repositories/{repository_name}/artifacts

type Client

type Client struct {

	// User agent used when communicating with the GitLab API.
	UserAgent string
	// Services used for talking to different parts of the Harbor API.
	Projects        *ProjectsService
	Repositories    *RepositoriesService
	ArtifactService *ArtifactService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(harborClient *gorequest.SuperAgent, baseURL, username, password string) *Client

func (*Client) GetStatistics

func (c *Client) GetStatistics() (StatisticMap, *gorequest.Response, []error)

GetStatistics Get projects number and repositories number relevant to the user

This endpoint is aimed to statistic all of the projects number and repositories number relevant to the logined user, also the public projects number and repositories number. If the user is username, he can also get total projects number and total repositories number.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L631

func (*Client) NewRequest

func (c *Client) NewRequest(method, subPath string) *gorequest.SuperAgent

NewRequest creates an API request. A relative URL path can be provided in urlStr, in which case it is resolved relative to the base URL of the Client. Relative URL paths should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) Search

func (c *Client) Search() (Search, *gorequest.Response, []error)

Search for projects and repositories

The Search endpoint returns information about the projects and repositories offered at public status or related to the current logged in user. The response includes the project and repository list in a proper display order.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L17

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(urlStr string) error

SetBaseURL sets the base URL for API requests to a custom endpoint. urlStr should always be specified with a trailing slash.

type ComponentsOverview

type ComponentsOverview struct {
	Total   int                        `json:"total"`
	Summary []*ComponentsOverviewEntry `json:"summary"`
}

ComponentsOverview has the total number and a list of components number of different serverity level.

type ComponentsOverviewEntry

type ComponentsOverviewEntry struct {
	Sev   int `json:"severity"`
	Count int `json:"count"`
}

ComponentsOverviewEntry ...

type ImgScanOverview

type ImgScanOverview struct {
	ID              int64               `json:"-"`
	Digest          string              `json:"image_digest"`
	Status          string              `json:"scan_status"`
	JobID           int64               `json:"job_id"`
	Sev             int                 `json:"severity"`
	CompOverviewStr string              `json:"-"`
	CompOverview    *ComponentsOverview `json:"components,omitempty"`
	DetailsKey      string              `json:"details_key"`
	CreationTime    time.Time           `json:"creation_time,omitempty"`
	UpdateTime      time.Time           `json:"update_time,omitempty"`
}

ImgScanOverview mapped to a record of image scan overview.

type ListLogOptions

type ListLogOptions struct {
	ListOptions
	Username   string     `url:"username,omitempty"`        // the operator's username of the log
	Repository string     `url:"repository,omitempty"`      // repository name
	Tag        string     `url:"tag,omitempty"`             // tag name
	Operations []string   `url:"operation,omitempty"`       // operations
	BeginTime  *time.Time `url:"begin_timestamp,omitempty"` // the time after which the operation is done
	EndTime    *time.Time `url:"end_timestamp,omitempty"`   // the time before which the operation is doen
}

ListLogOptions LogQueryParam is used to set query conditions when listing access logs.

type ListOptions

type ListOptions struct {
	// For paginated result sets, page of results to retrieve.
	Page int `url:"page,omitempty" json:"page,omitempty"`

	// For paginated result sets, the number of results to include per page.
	PageSize int `url:"page_size,omitempty" json:"page_size,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination.

type ListProjectsOptions

type ListProjectsOptions struct {
	ListOptions
	Name   string `url:"name,omitempty" json:"name,omitempty"`
	Public bool   `url:"public,omitempty" json:"public,omitempty"`
	Owner  string `url:"owner,omitempty" json:"owner,omitempty"`
}

type ListRepositoriesOption

type ListRepositoriesOption struct {
	ListOptions
	ProjectId   int64  `url:"project_id,omitempty" json:"project_id,omitempty"`
	ProjectName string `url:"project_name,omitempty" json:"project_name,omitempty"`
	Q           string `url:"q,omitempty" json:"q,omitempty"`
	Sort        string `url:"sort,omitempty" json:"sort,omitempty"`
}

type ManifestResp

type ManifestResp struct {
	Manifest interface{} `json:"manifest"`
	Config   interface{} `json:"config,omitempty" `
}

type MemberRequest

type MemberRequest struct {
	UserName string `json:"username"`
	Roles    []int  `json:"roles"`
}

type Project

type Project struct {
	ProjectID    int64             `json:"project_id"`
	OwnerID      int               `json:"owner_id"`
	Name         string            `json:"name"`
	CreationTime time.Time         `json:"creation_time"`
	UpdateTime   time.Time         `json:"update_time"`
	Deleted      int               `json:"deleted"`
	OwnerName    string            `json:"owner_name"`
	Togglable    bool              `json:"togglable"`
	Role         int               `json:"current_user_role_id"`
	RepoCount    int64             `json:"repo_count"`
	Metadata     map[string]string `json:"metadata"`
}

Project holds the details of a project.

type ProjectMetadata

type ProjectMetadata struct {
	ID           int64     `json:"id"`
	ProjectID    int64     `json:"project_id"`
	Name         string    `json:"name"`
	Value        string    `json:"value"`
	CreationTime time.Time `json:"creation_time"`
	UpdateTime   time.Time `json:"update_time"`
	Deleted      int       `json:"deleted"`
}

ProjectMetadata holds the metadata of a project.

type ProjectRequest

type ProjectRequest struct {
	Name     string            `url:"name,omitempty" json:"project_name"`
	Public   *int              `url:"public,omitempty" json:"public"` //deprecated, reserved for project creation in replication
	Metadata map[string]string `url:"-" json:"metadata"`
}

ProjectRequest holds informations that need for creating project API

type ProjectsService

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

ProjectsService handles communication with the user related methods of the Harbor API.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L45

func (*ProjectsService) AddProjectMember

func (s *ProjectsService) AddProjectMember(pid int64, member MemberRequest) (*gorequest.Response, []error)

Add project role member accompany with relevant project and user.

This endpoint is for user to add project role member accompany with relevant project and user.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L483

func (*ProjectsService) AddProjectMetadata

func (s *ProjectsService) AddProjectMetadata(pid int64, metadata map[string]string) (*gorequest.Response, []error)

Add metadata for the project.

This endpoint is aimed to add metadata of a project.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L329

func (*ProjectsService) CheckProject

func (s *ProjectsService) CheckProject(projectName string) (*gorequest.Response, []error)

CheckProject Check if the project name user provided already exists.

This endpoint is used to check if the project name user provided already exist.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L100

func (*ProjectsService) CreateProject

func (s *ProjectsService) CreateProject(p ProjectRequest) (*gorequest.Response, []error)

Create a new project.

This endpoint is for user to create a new project.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L122

func (*ProjectsService) DeleteProject

func (s *ProjectsService) DeleteProject(pid int64) (*gorequest.Response, []error)

Delete project by projectID.

This endpoint is aimed to delete project by project ID.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L203

func (*ProjectsService) DeleteProjectMember

func (s *ProjectsService) DeleteProjectMember(pid, uid int) (*gorequest.Response, []error)

Delete project role members accompany with relevant project and user.

This endpoint is aimed to remove project role members already added to the relevant project and user.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L597

func (*ProjectsService) DeleteProjectMetadata

func (s *ProjectsService) DeleteProjectMetadata(pid int64, metadataName string) (*gorequest.Response, []error)

Delete metadata of a project

This endpoint is aimed to delete metadata of a project.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L422

func (*ProjectsService) GetProjectByID

func (s *ProjectsService) GetProjectByID(pid int64) (Project, *gorequest.Response, []error)

Return specific project detail information.

This endpoint returns specific project information by project ID.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L149

func (*ProjectsService) GetProjectLogByID

func (s *ProjectsService) GetProjectLogByID(pid int64, opt ListLogOptions) ([]AccessLog, *gorequest.Response, []error)

Get access logs accompany with a relevant project.

This endpoint let user search access logs filtered by operations and date time ranges.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L230

func (*ProjectsService) GetProjectMemberRole

func (s *ProjectsService) GetProjectMemberRole(pid, uid int) (Role, *gorequest.Response, []error)

Return role members accompany with relevant project and user.

This endpoint is for user to get role members accompany with relevant project and user.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L522

func (*ProjectsService) GetProjectMembers

func (s *ProjectsService) GetProjectMembers(pid int64) ([]User, *gorequest.Response, []error)

Return a project's relevant role members.

This endpoint is for user to search a specified project’s relevant role members.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L452

func (*ProjectsService) GetProjectMetadata

func (s *ProjectsService) GetProjectMetadata(pid int64, specified string) (map[string]string, *gorequest.Response, []error)

Get project metadata

This endpoint returns specified metadata of a project.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L364

func (*ProjectsService) GetProjectMetadataById

func (s *ProjectsService) GetProjectMetadataById(pid int64) (map[string]string, *gorequest.Response, []error)

Get project all metadata.

This endpoint returns metadata of the project specified by project ID.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L307

func (*ProjectsService) ListProject

func (s *ProjectsService) ListProject(opt *ListProjectsOptions) ([]Project, *gorequest.Response, []error)

ListProject List projects

This endpoint returns all projects created by Harbor, and can be filtered by project name.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L46

func (*ProjectsService) UpdateProject

func (s *ProjectsService) UpdateProject(pid int64, p Project) (*gorequest.Response, []error)

Update properties for a selected project.

This endpoint is aimed to update the properties of a project.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L171

func (*ProjectsService) UpdateProjectMemberRole

func (s *ProjectsService) UpdateProjectMemberRole(pid, uid int, role MemberRequest) (*gorequest.Response, []error)

Update project role members accompany with relevant project and user.

This endpoint is for user to update current project role members accompany with relevant project and user.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L559

func (*ProjectsService) UpdateProjectMetadata

func (s *ProjectsService) UpdateProjectMetadata(pid int64, metadataName string) (*gorequest.Response, []error)

Update metadata of a project.

This endpoint is aimed to update the metadata of a project.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L391

type RepoResp

type RepoResp struct {
	ID           int64     `json:"id"`
	Name         string    `json:"name"`
	ProjectID    int64     `json:"project_id"`
	Description  string    `json:"description"`
	PullCount    int64     `json:"pull_count"`
	StarCount    int64     `json:"star_count"`
	TagsCount    int64     `json:"tags_count"`
	CreationTime time.Time `json:"creation_time"`
	UpdateTime   time.Time `json:"update_time"`
}

type RepositoriesService

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

RepositoriesService handles communication with the user related methods of the Harbor API.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L891

func (*RepositoriesService) DeleteRepository

func (s *RepositoriesService) DeleteRepository(repoName string) (*gorequest.Response, []error)

Delete a repository.

This endpoint let user delete a repository with name.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L948

func (*RepositoriesService) DeleteRepositoryTag

func (s *RepositoriesService) DeleteRepositoryTag(repoName, tag string) (*gorequest.Response, []error)

Delete a tag in a repository.

This endpoint let user delete tags with repo name and tag.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L1025

func (*RepositoriesService) GetImageDetails

func (s *RepositoriesService) GetImageDetails(repoName, tag string) ([]VulnerabilityItem, *gorequest.Response, []error)

Get vulnerability details of the image.

Call Clair API to get the vulnerability based on the previous successful scan.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L1177

func (*RepositoriesService) GetRepositorySignature

func (s *RepositoriesService) GetRepositorySignature(repoName string) ([]Signature, *gorequest.Response, []error)

Get signature information of a repository.

This endpoint aims to retrieve signature information of a repository, the data is from the nested notary instance of Harbor. If the repository does not have any signature information in notary, this API will return an empty list with response code 200, instead of 404

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L1211

func (*RepositoriesService) GetRepositoryTag

func (s *RepositoriesService) GetRepositoryTag(repoName, tag string) (TagResp, *gorequest.Response, []error)

Get the tag of the repository.

This endpoint aims to retrieve the tag of the repository. If deployed with Notary, the signature property of response represents whether the image is singed or not. If the property is null, the image is unsigned.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L999

func (*RepositoriesService) GetRepositoryTagManifests

func (s *RepositoriesService) GetRepositoryTagManifests(repoName, tag string, version string) (ManifestResp, *gorequest.Response, []error)

Get manifests of a relevant repository.

This endpoint aims to retreive manifests from a relevant repository.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L1079

func (*RepositoriesService) GetRepositoryTop

func (s *RepositoriesService) GetRepositoryTop(top interface{}) ([]RepoResp, *gorequest.Response, []error)

Get public repositories which are accessed most.

This endpoint aims to let users see the most popular public repositories.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L1241

func (*RepositoriesService) ListRepository

ListRepository Get repositories accompany with relevant project and repo name.

This endpoint let user search repositories accompanying with relevant project ID and repo name.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L892

func (*RepositoriesService) ListRepositoryTags

func (s *RepositoriesService) ListRepositoryTags(repoName string) ([]TagResp, *gorequest.Response, []error)

Get tags of a relevant repository.

This endpoint aims to retrieve tags from a relevant repository. If deployed with Notary, the signature property of response represents whether the image is singed or not. If the property is null, the image is unsigned.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L1054

func (*RepositoriesService) ScanImage

func (s *RepositoriesService) ScanImage(repoName, tag string) (*gorequest.Response, []error)

Scan the image.

Trigger jobservice to call Clair API to scan the image identified by the repo_name and tag. Only project usernames have permission to scan images under the project.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L1113

func (*RepositoriesService) UpdateRepository

func (s *RepositoriesService) UpdateRepository(repoName string, d RepositoryDescription) (*gorequest.Response, []error)

Update description of the repository.

This endpoint is used to update description of the repository.

Harbor API docs: https://github.com/vmware/harbor/blob/release-1.4.0/docs/swagger.yaml#L971

type RepositoryDescription

type RepositoryDescription struct {
	Description string `url:"description,omitempty" json:"description,omitempty"`
}

type Role

type Role struct {
	RoleID   int    `json:"role_id"`
	RoleCode string `json:"role_code"`
	Name     string `json:"role_name"`
	RoleMask int    `json:"role_mask"`
}

Role holds the details of a role.

type Search struct {
	// Search results of the projects that matched the filter keywords.
	Projects Project `json:"project,omitempty"`
	// Search results of the repositories that matched the filter keywords.
	Repositories []SearchRepository `json:"repository,omitempty"`
}

type SearchRepository

type SearchRepository struct {
	// The ID of the project that the repository belongs to
	ProjectId int32 `json:"project_id,omitempty"`
	// The name of the project that the repository belongs to
	ProjectName string `json:"project_name,omitempty"`
	// The flag to indicate the publicity of the project that the repository belongs to
	ProjectPublic bool `json:"project_public,omitempty"`
	// The name of the repository
	RepositoryName string `json:"repository_name,omitempty"`
	PullCount      int32  `json:"pull_count,omitempty"`
	TagsCount      int32  `json:"tags_count,omitempty"`
}

type Signature

type Signature struct {
	Tag    string            `json:"tag"`
	Hashes map[string][]byte `json:"hashes"`
}

type StatisticMap

type StatisticMap struct {
	// The count of the private projects which the user is a member of.
	PrivateProjectCount int `json:"private_project_count,omitempty"`
	// The count of the private repositories belonging to the projects which the user is a member of.
	PrivateRepoCount int `json:"private_repo_count,omitempty"`
	// The count of the public projects.
	PublicProjectCount int `json:"public_project_count,omitempty"`
	// The count of the public repositories belonging to the public projects which the user is a member of.
	PublicRepoCount int `json:"public_repo_count,omitempty"`
	// The count of the total projects, only be seen when the is username.
	TotalProjectCount int `json:"total_project_count,omitempty"`
	// The count of the total repositories, only be seen when the user is username.
	TotalRepoCount int `json:"total_repo_count,omitempty"`
}

type TagResp

type TagResp struct {
	Signature    *Signature       `json:"signature"`
	ScanOverview *ImgScanOverview `json:"scan_overview,omitempty"`
	// contains filtered or unexported fields
}

type User

type User struct {
	UserID       int       `json:"user_id"`
	Username     string    `json:"username"`
	Email        string    `json:"email"`
	Password     string    `json:"password"`
	Realname     string    `json:"realname"`
	Comment      string    `json:"comment"`
	Deleted      int       `json:"deleted"`
	Rolename     string    `json:"role_name"`
	Role         int       `json:"role_id"`
	RoleList     []Role    `json:"role_list"`
	HasAdminRole int       `json:"has_username_role"`
	ResetUUID    string    `json:"reset_uuid"`
	Salt         string    `json:"-"`
	CreationTime time.Time `json:"creation_time"`
	UpdateTime   time.Time `json:"update_time"`
}

User holds the details of a user.

type VulnerabilityItem

type VulnerabilityItem struct {
	ID          string `json:"id"`
	Severity    int64  `json:"severity"`
	Pkg         string `json:"package"`
	Version     string `json:"version"`
	Description string `json:"description"`
	Link        string `json:"link"`
	Fixed       string `json:"fixedVersion,omitempty"`
}

VulnerabilityItem is an item in the vulnerability result returned by vulnerability details API.

Jump to

Keyboard shortcuts

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