harbor is the enterprise-class registry server for docker distribution.
harbor-java-client
Harbor Java Client uses Spring boot and okhttpclient to expose Harbor REST API via HarborJavaClient.
Usage
/** Constructor
* public HarborClient(String baseUrl) // default verifySSL is false
* public HarborClient(String baseUrl, boolean verifySSL)
**/
//1) Creat harbor client
HarborClient harborClient = new HarborClient(baseUrl);
//2) login
harborClient.login(username, password);
//3) Call other API
//n) log out
harborClient.logout();
Implemented Harbor API
Basic
Login: post /login
Logout: get /log_out
Search: get /search
Get Logs: get /logs
Get Statistics: get /statistics
Project
Get Projects: get /projects
Check Projects: head /projects
Create Projects: post /projects
Set publicity status: put /projects/{project_id}/publicity
Search Logs: post /projects/{project_id}/logs/filter
Search role members: get /projects/{project_id}/members/
HarborResponse res = harborClient.checkProject(projectName);
参数名
是否必填
类型
说明
projectName
N
String
项目名
返回值
类型
说明
res
HarborResponse
请求结果状态(code, message)
请求结果状态如下:
HTTP Status Code
Message
200
Project name exists
401
User need to log in first
404
Project name does not exist
500
Unexpected internal errors
Other
Unknown
8. Create Projects
Project pro=new Project();
pro.setName("proname");
pro.setPublic(false);
HarborResponse res = harborClient.createProject(pro);
参数名
是否必填
类型
说明
pro
Y
Project
需要创建的项目内容
返回值
类型
说明
res
HarborResponse
请求结果状态(code, message)
请求结果状态如下:
HTTP Status Code
Message
201
Project created successfully
400
Unsatisfied with constraints of the project creation
401
User need to log in first
409
Project name already exists
500
Unexpected internal errors
Other
Unknown
9. Set Publicity
int id = 17;
Project project=new Project();
project.setPublic(true);
HarborResponse res = harborClient.setPublicity(id, project);
参数名
是否必填
类型
说明
id
Y
integer
项目ID
project
Y
Project
设置项目是否公开
返回值
类型
说明
res
HarborResponse
请求结果状态(code, message)
请求结果状态如下:
HTTP Status Code
Message
200
Updated project publicity status successfully
400
Illegal format of provided ID value
401
User need to log in first
403
User does not have permission to the project
404
Project ID does not exist
500
Unexpected internal errors
Other
Unknown
10. Search Logs With Filter
int id = 17;
Log accessLog =new Log();
accessLog.setKeywords("create/pull/push/delete/jessia");
accessLog.setProjectId(17);
List<Log> res = harborClient.filterLog(id, accessLog);
参数名
是否必填
类型
说明
id
Y
integer
项目ID
accessLog
Y
Log
查询内容
返回值
类型
说明
res
List
请求结果状态
如果有异常,会抛出HarborClientException,状态如下:
(HTTP Status) Code
HarborMessage
400
Illegal format of provided ID value
401
User need to log in first
500
Unexpected internal errors
Other
Unknown
11.Add Member
int id = 22;
MemberConf memberConf =new MemberConf();
List<Integer> role=new ArrayList<>();
role.add(3);
memberConf.setRoles(role);
memberConf.setUsername("chufuyuan");
HarborResponse res = harborClient.addMember(id, memberConf);
参数名
是否必填
类型
说明
id
Y
integer
项目ID
memberConf
Y
MemberConf
需要添加的成员信息
返回值
类型
说明
res
HarborResponse
请求结果状态
请求结果状态如下:
HTTP Status Code
Message
200
Role members added to relevant project successfully.