一、项目管理
# curl -k -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/projects/{project_id}"
# curl -k -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/projects?project_name=library"
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/search?q=library"
# curl -u "admin:Harbor12345" -X DELETE -H "Content-Type: application/json" "https://HostName/api/projects/{project_id}"
# curl -u "admin:Harbor12345" -X POST -H "Content-Type: application/json" "https://HostName/api/projects" -d @createproject.json
# cat createproject.json
{
"project_name": "testrpo",
"public": 0
}
或者
# curl -u "USER:PASSWORD" -X POST -H "Content-Type:application/json" "https://HostName/api/projects" --insecure -d '{"project_name": "testrpo","public": 0}'
# curl -u "admin:Harbor12345" -X POST -H "Content-Type: application/json" "https://HostName/api/projects/{project_id}/logs/filter" -d @log.json
# cat log.json
{
"username": "admin"
}
二、账号管理
# curl -u "admin:Harbor12345" -X POST -H "Content-Type: application/json" "https://HostName/api/users" -d @user.json
# cat user.json
{
"user_id": 5,
"username": "zhangsan",
"email": "[email protected]",
"password": "Zs202005",
"realname": "zhangsan",
"role_id": 2
}
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/users"
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/users/current"
# curl -u "admin:Harbor12345" -X DELETE -H "Content-Type: application/json" "https://HostName/api/users/{user_id}"
# curl -u "admin:Harbor12345" -X PUT -H "Content-Type: application/json" "https://HostName/api/users/{user_id}/password" -d @uppwd.json
# cat uppwd.json
{
"old_password": "Harbor123456",
"new_password": "Harbor888888"
}
三、用户权限管理
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/projects/{project_id}/members/"
# curl -u "jaymarco:Harbor123456" -X POST -H "Content-Type: application/json" "https://HostName/api/projects/{project_id}/members/" -d @role.json
# cat role.json
{
"roles": [
],
"username": "guest"
}
# curl -u "admin:Harbor12345" -X DELETE -H "Content-Type: application/json" "https:/HostName6/api/projects/{project_id}/members/{user_id}"
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/statistics"
- 3.5 修改当前用户角色
has_admin_role :0 普通用户
has_admin_role :1 管理员
# curl -u "admin:Harbor12345" -X PUT -H "Content-Type: application/json" "https://HostName/api/users/{user_id}/sysadmin " -d @chgrole.json
# cat >chgrole.json
{
"has_admin_role": 1
}
四、镜像管理
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/repositories?project_id={project_id}&q=dcos%2Fcentos"
# curl -u "admin:Harbor12345" -X DELETE -H "Content-Type: application/json" "https://HostName/api/repositories?repo_name=dcos%2Fetcd "
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/repositories/tags?repo_name=dcos%2Fcentos"