Help us shape the future of Go! Take the 2026 Go Developer Survey

harbor

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

goharbor

package main

import (
	"context"
	"fmt"
	"github.com/XuHaoIgeneral/goharbor"
)

const (
	username = "admin"
	password = "admin"
	host     = "http://myharbor.company.com"
)

func main() {
	// create harbor client
	c, err := harbor.NewClient(nil, host, username, password, true)
	if err != nil {
		panic(err)
	}

	// list project
	ps, err := c.ListProjects(context.Background(), nil)
	if err != nil {
		panic(err)
	}

	// dump projects
	for _, p := range ps {
		fmt.Printf("%+v\n", p)
	}
}

Documentation

Index

Constants

View Source
const (
	IMAGE_GET      = "/api/repositories?project_id=%s&q=%s"
	IMAGE_NAGE_TAG = "/api/repositories/%s/tags/%s"
)
View Source
const (
	PATH_FMT_PROJECT_LIST        = "/api/projects"
	PATH_FMT_PROJECT_GET         = "/api/projects/%d"
	PATH_FMT_PROJECT_ADD_MEMBER  = "/api/projects/%d/members"
	PATH_FMT_PROJECT_DEL_MEMBER  = "/api/projects/%d/members/%d"
	PATH_FMT_PROJECT_GET_MEMBERs = "/api/projects/%d/members/?entityname="
)
View Source
const (
	PATH_FMT_REPO_LIST     = "/api/repositories"
	PATH_FMT_REPOTAGS_LIST = "/api/repositories/%s/%s/tags"
	PATH_FMT_REPOTAG       = "/api/repositories/%s/%s/tags/%s"
)
View Source
const (
	REPO_SORT_BYNAME_ASC        = "name"
	REPO_SORT_BYNAME_DESC       = "-name"
	REPO_SORT_BYCREATION_ASC    = "creation_time"
	REPO_SORT_BYCREATION_DESC   = "-creation_time"
	REPO_SORT_BYUPDATETIME_ASC  = "update_time"
	REPO_SORT_BYUPDATETIME_DESC = "-update_time"
)
View Source
const (
	PATH_FMT_USER_CREATE   = "/api/users"
	PATH_FMT_USER_LIST     = "/api/users"
	PATH_FMT_USER_SEARCH   = "/api/users/search?username=%s"
	PATH_FMT_USER_PASSWORD = "/api/users/%d/password"
	PATH_FMT_USER_DELETE   = "/api/users/%d"
)
View Source
const (
	PATH_FMT_CONFIGURE_LIST = "/api/configurations"
)
View Source
const (
	PATH_FMT_SEARCH = "/api/search"
)

Variables

View Source
var (
	NotFoundError       = fmt.Errorf("not found")
	UserNotLoginError   = fmt.Errorf("user need to login")
	CallApiError        = fmt.Errorf("call api failed")
	ServerInternalError = fmt.Errorf("server internal error")
	NotAllowError       = fmt.Errorf("not allow")
)
View Source
var (
	ERROR_THE_GINSENG     = errors.New("Passing parameters cannot nil")
	ERROR_THE_FORMAT      = errors.New("Unsatisfied with constraints of the user creation.")
	ERROR_THE_PERMISSIONS = errors.New("User registration can only be used by admin role user when self-registration is off")
	ERROR_THE_TYPE        = errors.New("The Media Type of the request is not supported, it has to be 'application/json'")
	ERROR_THE_SERVER      = errors.New("Unexpected internal errors")
	ERROR_THE_PKG         = errors.New("Running errors")
	ERROR_THE_401         = errors.New("User need to log in first.")
	ERROR_THE_409         = errors.New("Maybe existing")
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(http_client *http.Client, host, username, password string, sniffer bool) (*Client, error)

func NewClientFromEnv

func NewClientFromEnv(http_client *http.Client) (*Client, error)

func (*Client) AddMemberToProject

func (c *Client) AddMemberToProject(ctx context.Context, pm *ProjectMember) (bool, error)

func (*Client) CreateProject

func (c *Client) CreateProject(ctx context.Context, opt *ProjectInit) (bool, error)

todo : lower harbor public!!!!!!!!!!!

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, opt *UserInit) (bool, error)

func (*Client) DelMemberToProject

func (c *Client) DelMemberToProject(ctx context.Context, username, project string) (bool, error)

func (*Client) DeleteProjectById

func (c *Client) DeleteProjectById(ctx context.Context, id int64) (deleted bool, err error)

func (*Client) DeleteProjectByName

func (c *Client) DeleteProjectByName(ctx context.Context, project string) (deleted bool, err error)

func (*Client) DeleteRepoTag

func (c *Client) DeleteRepoTag(ctx context.Context, project_name, repo_name, tag_name string) (bool, error)

func (*Client) DeleteUser

func (c *Client) DeleteUser(ctx context.Context, username string) (deleted bool, err error)

func (*Client) GetImageByNameAndTag added in v1.0.1

func (c *Client) GetImageByNameAndTag(ctx context.Context, project, name, tag string) error

func (*Client) GetProjectById

func (c *Client) GetProjectById(ctx context.Context, id int64) (*models.Project, error)

func (*Client) GetProjectByName

func (c *Client) GetProjectByName(ctx context.Context, projectName string) (*models.Project, error)

func (*Client) GetProjectMetadataByUser

func (c *Client) GetProjectMetadataByUser(ctx context.Context, username, project string) ([]*models.ProjectMember, error)

func (*Client) GetProjectMetadataList

func (c *Client) GetProjectMetadataList(ctx context.Context, project string) ([]*models.ProjectMember, error)

func (*Client) GetRepoTag

func (c *Client) GetRepoTag(ctx context.Context, project_name, repo_name, tag_name string) (*models.TagDetail, error)

func (*Client) GetUserByName

func (c *Client) GetUserByName(ctx context.Context, username string) (*models.SearchUser, error)

func (*Client) Image

func (c *Client) Image(project, repo, tag string) string

func (*Client) ListConfigures

func (c *Client) ListConfigures(ctx context.Context) (map[string]interface{}, error)

func (*Client) ListProjects

func (c *Client) ListProjects(ctx context.Context, opt *ProjectOption) ([]*models.Project, error)

func (*Client) ListRepoTags

func (c *Client) ListRepoTags(ctx context.Context, project_name, repo_name string) ([]*models.TagDetail, error)

func (*Client) ListRepos

func (c *Client) ListRepos(ctx context.Context, project_id int64, opt *RepoOption) (int, []*models.Repo, error)

func (*Client) ListReposByProjectName

func (c *Client) ListReposByProjectName(ctx context.Context, name string) (total int, repos []*models.Repo, err error)

func (*Client) ListUser

func (c *Client) ListUser(ctx context.Context, opt *UserOption) ([]*models.Users, error)

func (*Client) ResetPwd

func (c *Client) ResetPwd(ctx context.Context, username string, newPassword string) (reseted bool, err error)

TODO:Harbor's pwd manage is `Chaos`,pls commit ur code!!!

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string) (*models.SearchResult, error)

func (*Client) SearchUser

func (c *Client) SearchUser(ctx context.Context, username string) ([]*models.SearchUser, error)

func (*Client) UpdateUserPwd

func (c *Client) UpdateUserPwd(ctx context.Context, username string, upwd *UserUpPwd) (bool, error)

TODO:harbor api is false. the same as update password and reset password

func (*Client) UserIsExist

func (c *Client) UserIsExist(ctx context.Context, username string) (bool, error)

type Image added in v1.0.1

type Image struct {
	Project string
	Names   string
	Tag     string
}

type PageOption

type PageOption struct {
	Page     int32
	PageSize int32
}

func (PageOption) Urls

func (opt PageOption) Urls() (v url.Values)

type ProjectInit

type ProjectInit struct {
	Public      bool
	ProjectName string
}

type ProjectMember

type ProjectMember struct {
	RoleId   int
	Username string
	Project  string
}

type ProjectOption

type ProjectOption struct {
	Name   string
	Public string
	Owner  string
	PageOption
}

func (*ProjectOption) Urls

func (opt *ProjectOption) Urls() url.Values

type RepoOption

type RepoOption struct {
	Name    string
	Sort    RepoSortType
	LabelId string
	PageOption
}

func (*RepoOption) Urls

func (opt *RepoOption) Urls() url.Values

type RepoSortType

type RepoSortType = string

type UserInit

type UserInit struct {
	Username string
	Password string
	Realname string
	Email    string
}

type UserOption

type UserOption struct {
	Username string
	Email    string
	PageOption
}

func (*UserOption) Urls

func (opt *UserOption) Urls() url.Values

type UserUpPwd

type UserUpPwd struct {
	OldPassword string `json:"old_password"`
	NewPassword string `json:"new_password"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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