harbor

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRequestTimeout = time.Second * 5

Variables

This section is empty.

Functions

func ApiGetListRepoByPage

func ApiGetListRepoByPage(schema, address, projectName string, page, pageSize int) string

func ApiGetProjectMetaInfo

func ApiGetProjectMetaInfo(schema, address string, projectId int) string

func ApiGetProjectsByName

func ApiGetProjectsByName(schema, address, projectName string) string

func ApiGetProjectsByPage

func ApiGetProjectsByPage(schema, address string, page, pageSize int) string

func ApiGetStatistics

func ApiGetStatistics(schema, address string) string

func ApiGetTagsNumWithRepo

func ApiGetTagsNumWithRepo(schema, address, projectName, repoName string) string

func ApiGetTagsWithinRepoByPage

func ApiGetTagsWithinRepoByPage(schema, address, projectName, repoName string, page, pageSize int) string

func ImageList

func ImageList(item command.OperationItem) command.RunErr

ImageList harbor镜像列表导出

Types

type Artifact

type Artifact struct {
	AdditionLinks struct {
		BuildHistory struct {
			Absolute bool   `json:"absolute"`
			Href     string `json:"href"`
		} `json:"build_history"`
		Vulnerabilities struct {
			Absolute bool   `json:"absolute"`
			Href     string `json:"href"`
		} `json:"vulnerabilities"`
	} `json:"addition_links"`
	Digest     string `json:"digest"`
	ExtraAttrs struct {
		Architecture string      `json:"architecture"`
		Author       interface{} `json:"author"`
		Created      time.Time   `json:"created"`
		Os           string      `json:"os"`
	} `json:"extra_attrs"`
	Icon              string        `json:"icon"`
	Id                int           `json:"id"`
	Labels            interface{}   `json:"labels"`
	ManifestMediaType string        `json:"manifest_media_type"`
	MediaType         string        `json:"media_type"`
	ProjectId         int           `json:"project_id"`
	PullTime          time.Time     `json:"pull_time"`
	PushTime          time.Time     `json:"push_time"`
	References        interface{}   `json:"references"`
	RepositoryId      int           `json:"repository_id"`
	Size              int           `json:"size"`
	Tags              []TagExternal `json:"tags"`
	Type              string        `json:"type"`
}

Artifact 用于反序列化制品属性

type Config

type Config struct {
	HarborSchema             string
	HarborAddress            string
	HarborDomain             string
	HarborUser               string
	HarborPassword           string
	PreserveDir              string
	TagWithDomain            bool
	ProjectsToSearch         []string
	ProjectsToSearchExcludes []string
}

Config harbor-repo对象配置,用于内部使用

type ConfigExternal

type ConfigExternal struct {
	HarborRepo struct {
		Schema        string   `yaml:"schema"`
		Address       string   `yaml:"address"`
		Domain        string   `yaml:"domain"`
		User          string   `yaml:"user"`
		Password      string   `yaml:"password"`
		PreserveDir   string   `yaml:"preserve-dir"`
		TagWithDomain bool     `yaml:"withDomain"`
		Projects      []string `yaml:"projects"`
		Excludes      []string `yaml:"excludes"`
	} `yaml:"harbor-repo"`
}

ConfigExternal 用于反序列化harbor-repo对象配置

type Executor

type Executor struct {
	Config
	Logger         *logrus.Logger
	ProjectSlice   []ProjectInternal
	ReposInProject map[string][]string // 项目下镜像repo集合
	TagsInProject  map[string][]string // 项目下镜像tag集合
	HandlerInterface
}

Executor 与harbor交互的执行器

func ParseHarborConfig

func ParseHarborConfig(b []byte, logger *logrus.Logger) (*Executor, error)

ParseHarborConfig 解析harbor配置

func (*Executor) AllProjects

func (executor *Executor) AllProjects(projectCount int) (projects []ProjectInternal, err error)

AllProjects 获取harbor所有projects

func (*Executor) FilterProjects

func (executor *Executor) FilterProjects(projects []ProjectInternal) []ProjectInternal

FilterProjects 过滤排除的project

func (*Executor) GenerateImageList

func (executor *Executor) GenerateImageList(tagsInProject map[string][]string) error

GenerateImageList 生成文件

func (*Executor) ProjectList

func (executor *Executor) ProjectList() ([]ProjectInternal, error)

ProjectList 获取所有projects

func (*Executor) ProjectsByName

func (executor *Executor) ProjectsByName(projectName string) (ProjectInternal, error)

ProjectsByName 按名称获取harbor内的项目

func (*Executor) ProjectsByNames

func (executor *Executor) ProjectsByNames(projectsName []string) ([]ProjectInternal, error)

ProjectsByNames 按名称集合获取harbor内的项目

func (*Executor) ReposWithinProject

func (executor *Executor) ReposWithinProject(projectName string, projectId int) ([]string, error)

ReposWithinProject 获取项目下repo列表

func (*Executor) ReposWithinProjects

func (executor *Executor) ReposWithinProjects(projects []ProjectInternal) (map[string][]string, error)

ReposWithinProjects 获取多个项目内repo集合

func (*Executor) TagsWithinProject

func (executor *Executor) TagsWithinProject(projectName string, repos []string) (projectMapTags, error)

TagsWithinProject 按`project name + Repository name`查询所有镜像tag

func (*Executor) TagsWithinProjects

func (executor *Executor) TagsWithinProjects(projectAndReposMap map[string][]string) (map[string][]string, error)

TagsWithinProjects 获取项目下镜像tag列表

func (*Executor) TagsWithinRepo

func (executor *Executor) TagsWithinRepo(projectName string, repoName string, tagsCount int) ([]string, error)

TagsWithinRepo 按`project name + Repository name`查询所有镜像tag

type HandlerInterface

type HandlerInterface interface {
	DoRequest(httpRequestItem request.HTTPRequestItem) ([]byte, error)
	ProjectsByPage(
		page int, pageSize int,
		logger *logrus.Logger,
		schema string,
		address string,
		user string,
		password string, timeout time.Duration,
	) ([]byte, error)
	ProjectCount(user, password, schema, address string, timeout time.Duration) ([]byte, error)
	TagsWithinRepoByPage(page, pageSize int, schema, address, projectName, repoName, user, password string, timeout time.Duration) ([]byte, error)
	TagsNumWithRepo(user, password, schema, address, projectName, repoName string, timeout time.Duration) ([]byte, error)
	RepoCount(user, password, schema, address string, projectId int, timeout time.Duration) ([]byte, error)
	ListRepoByPage(page, pageSize int, user, password, schema, address, projectName string, timeout time.Duration) ([]byte, error)
}

type ProjectExternal

type ProjectExternal struct {
	CreationTime       time.Time `json:"creation_time"`
	CurrentUserRoleId  int       `json:"current_user_role_id"`
	CurrentUserRoleIds []int     `json:"current_user_role_ids"`
	CveAllowlist       struct {
		CreationTime time.Time     `json:"creation_time"`
		Id           int           `json:"id"`
		Items        []interface{} `json:"items"`
		ProjectId    int           `json:"project_id"`
		UpdateTime   time.Time     `json:"update_time"`
	} `json:"cve_allowlist"`
	Metadata struct {
		Public               string `json:"public"`
		RetentionId          string `json:"retention_id,omitempty"`
		AutoScan             string `json:"auto_scan,omitempty"`
		EnableContentTrust   string `json:"enable_content_trust,omitempty"`
		PreventVul           string `json:"prevent_vul,omitempty"`
		ReuseSysCveAllowlist string `json:"reuse_sys_cve_allowlist,omitempty"`
		Severity             string `json:"severity,omitempty"`
	} `json:"metadata"`
	Name       string    `json:"name"`
	OwnerId    int       `json:"owner_id"`
	OwnerName  string    `json:"owner_name"`
	ProjectId  int       `json:"project_id"`
	RepoCount  int       `json:"repo_count,omitempty"`
	UpdateTime time.Time `json:"update_time"`
	ChartCount int       `json:"chart_count,omitempty"`
}

ProjectExternal harbor project外部对象,用于反序列化

type ProjectInternal

type ProjectInternal struct {
	Name      string
	ProjectId int
}

ProjectInternal harbor project内部对象,包含部分必需属性

type ProjectMeta

type ProjectMeta struct {
	CreationTime       time.Time `json:"creation_time"`
	CurrentUserRoleId  int       `json:"current_user_role_id"`
	CurrentUserRoleIds []int     `json:"current_user_role_ids"`
	CveAllowlist       struct {
		CreationTime time.Time     `json:"creation_time"`
		Id           int           `json:"id"`
		Items        []interface{} `json:"items"`
		ProjectId    int           `json:"project_id"`
		UpdateTime   time.Time     `json:"update_time"`
	} `json:"cve_allowlist"`
	Metadata struct {
		AutoScan             string `json:"auto_scan"`
		EnableContentTrust   string `json:"enable_content_trust"`
		PreventVul           string `json:"prevent_vul"`
		Public               string `json:"public"`
		RetentionId          string `json:"retention_id"`
		ReuseSysCveAllowlist string `json:"reuse_sys_cve_allowlist"`
		Severity             string `json:"severity"`
	} `json:"metadata"`
	Name       string    `json:"name"`
	OwnerId    int       `json:"owner_id"`
	OwnerName  string    `json:"owner_name"`
	ProjectId  int       `json:"project_id"`
	RepoCount  int       `json:"repo_count"`
	UpdateTime time.Time `json:"update_time"`
}

ProjectMeta project metadata

type ProjectNotFoundErr

type ProjectNotFoundErr struct {
	ProjectName string
}

func (ProjectNotFoundErr) Error

func (p ProjectNotFoundErr) Error() string

type RepoArtifactInfo

type RepoArtifactInfo struct {
	ArtifactCount int       `json:"artifact_count"`
	CreationTime  time.Time `json:"creation_time"`
	Id            int       `json:"id"`
	Name          string    `json:"name"`
	ProjectId     int       `json:"project_id"`
	PullCount     int       `json:"pull_count"`
	UpdateTime    time.Time `json:"update_time"`
}

type Repository

type Repository struct {
	Name string `json:"name"`
}

Repository harbor repo外部对象,用于反序列化

type Requester

type Requester struct{}

Requester request harbor

func (Requester) DoRequest

func (r Requester) DoRequest(httpRequestItem request.HTTPRequestItem) ([]byte, error)

func (Requester) ListRepoByPage

func (r Requester) ListRepoByPage(page, pageSize int, user, password, schema, address, projectName string, timeout time.Duration) ([]byte, error)

ListRepoByPage 调用harbor api获取project列表,根据project name获取repo列表

func (Requester) ProjectCount

func (r Requester) ProjectCount(user, password, schema, address string, timeout time.Duration) ([]byte, error)

func (Requester) ProjectsByPage

func (r Requester) ProjectsByPage(
	page int, pageSize int,
	logger *logrus.Logger,
	schema string,
	address string,
	user string,
	password string,
	timeout time.Duration,
) ([]byte, error)

ProjectsByPage 按页查询harbor内project

func (Requester) RepoCount

func (r Requester) RepoCount(user, password, schema, address string, projectId int, timeout time.Duration) ([]byte, error)

func (Requester) TagsNumWithRepo

func (r Requester) TagsNumWithRepo(user, password, schema, address, projectName, repoName string, timeout time.Duration) ([]byte, error)

func (Requester) TagsWithinRepoByPage

func (r Requester) TagsWithinRepoByPage(page, pageSize int, schema, address, projectName, repoName, user, password string, timeout time.Duration) ([]byte, error)

TagsWithinRepoByPage 获取repo的全部tag

type SearchResult

type SearchResult struct {
	Project    []ProjectExternal `json:"project"`
	Repository []struct {
	} `json:"repository"`
	Chart []struct {
		Name  string `json:"Name"`
		Score int    `json:"Score"`
		Chart struct {
			Name        string    `json:"name"`
			Version     string    `json:"version"`
			Description string    `json:"description"`
			ApiVersion  string    `json:"apiVersion"`
			AppVersion  string    `json:"appVersion"`
			Type        string    `json:"type"`
			Urls        []string  `json:"urls"`
			Created     time.Time `json:"created"`
			Digest      string    `json:"digest"`
		} `json:"Chart"`
	} `json:"chart"`
}

SearchResult 用于反序列化 查询harbor结果的对象结果集

type Statistics

type Statistics struct {
	PrivateProjectCount int `json:"private_project_count"`
	PrivateRepoCount    int `json:"private_repo_count"`
	PublicProjectCount  int `json:"public_project_count"`
	PublicRepoCount     int `json:"public_repo_count"`
	TotalProjectCount   int `json:"total_project_count"`
	TotalRepoCount      int `json:"total_repo_count"`
}

Statistics project info

type TagExternal

type TagExternal struct {
	ArtifactId   int       `json:"artifact_id"`
	Id           int       `json:"id"`
	Immutable    bool      `json:"immutable"`
	Name         string    `json:"name"`
	PullTime     time.Time `json:"pull_time"`
	PushTime     time.Time `json:"push_time"`
	RepositoryId int       `json:"repository_id"`
	Signed       bool      `json:"signed"`
}

TagExternal 用于反序列化repo tag等

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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