harbor

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

harbor-go

package main

import (
	"context"
	"fmt"
	"github.com/bingbaba/harbor-go"
)

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 (
	PATH_FMT_PROJECT_LIST       = "/api/projects"
	PATH_FMT_PROJECT_GET        = "/api/projects/%d"
	PATH_FMT_PROJECT_ADD_MEMBER = "/api/projects/%d/members"
)
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"
)
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 *UserInfo) (bool, error)

func (*Client) DeleteProject

func (c *Client) DeleteProject(ctx context.Context, id int64) (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) GetProject

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

func (*Client) GetProjectByName

func (c *Client) GetProjectByName(ctx context.Context, name string) (*models.Project, 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.Users, 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) ProjectIsExist

func (c *Client) ProjectIsExist(ctx context.Context, name string) (bool, error)

func (*Client) Search

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

func (*Client) UserIsExist

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

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 UserInfo

type UserInfo 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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