harbor仓库API功能接口

一、项目管理

  • 1.1查看仓库中的项目详细信息
# 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"


  • 1.2 搜索镜像(未验证)
# curl  -u "admin:Harbor12345"  -X GET -H "Content-Type: application/json" "https://HostName/api/search?q=library"


  • 1.3 删除项目
# curl  -u "admin:Harbor12345"  -X DELETE  -H "Content-Type: application/json" "https://HostName/api/projects/{project_id}"


  • 1.4 创建项目
# 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}'


  • 1.5 查看项目日志
# 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"
}

二、账号管理

  • 2.1 创建账号
# 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

}

  • 2.2 获取用户信息
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/users"

  • 2.3 获取当前用户信息
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/users/current"

  • 2.4 删除用户
# curl -u "admin:Harbor12345" -X DELETE  -H "Content-Type: application/json" "https://HostName/api/users/{user_id}"

  • 2.5 修改用户密码
# 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"

}

三、用户权限管理

  • 3.1 查看项目相关角色
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/projects/{project_id}/members/"

  • 3.2 项目添加角色
# 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"

}

  • 3.3 删除项目中用户权限
# curl -u "admin:Harbor12345" -X DELETE -H "Content-Type: application/json" "https:/HostName6/api/projects/{project_id}/members/{user_id}"

  • 3.4 获取与用户相关的项目编号和存储库编号
# 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

}

四、镜像管理

  • 4.1 查询镜像
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/repositories?project_id={project_id}&q=dcos%2Fcentos"

  • 4.2 删除镜像
# curl -u "admin:Harbor12345" -X DELETE -H "Content-Type: application/json" "https://HostName/api/repositories?repo_name=dcos%2Fetcd "

  • 4.3 获取镜像标签
# curl -u "admin:Harbor12345" -X GET -H "Content-Type: application/json" "https://HostName/api/repositories/tags?repo_name=dcos%2Fcentos"

你可能感兴趣的:(harbor仓库API功能接口)