Pivotal Knowledge Base

Follow

How to Browse and Query Harbor Registry using REST API

Environment

Pivotal Container Service (PKS) Version 1.0
VMware Harbor 1.4.x

Purpose

With the private Docker registry of Harbor, you can push and pull images for your own organization to use. While you can browse and search Docker images using Harbor WebUI. There is still no refined way to do the same in a programmatical manner. This article demonstrates how to query against a Harbor registry using RESTful API in the command line using 'curl' command.

Prerequisites

  • PKS environment with Harbor tile deployed successfully
  • Access to the Harbor registry

Procedure

Below are few example runs of the queries using the REST APIs.

1. List all projects in the registry

$ curl -i -k -X GET "https://harbor.mycompany.local/api/projects"
[
{
"project_id": 1,
"owner_id": 1,
"name": "library",
"creation_time": "2018-03-03T09:32:55Z",
"update_time": "2018-03-03T09:32:55Z",
"deleted": 0,
"owner_name": "",
"togglable": false,
"current_user_role_id": 0,
"repo_count": 5,
"metadata": {
"public": "true"
}
}
]

2. List up all Docker images and details of each image.

$ curl -i -k -X GET "https://harbor.mycompany.local/api/search?q="
{
"project": [
{
"project_id": 1,
"owner_id": 1,
"name": "library",
"creation_time": "2018-03-03T09:32:55Z",
"update_time": "2018-03-03T09:32:55Z",
"deleted": 0,
"owner_name": "",
"togglable": false,
"current_user_role_id": 0,
"repo_count": 5,
"metadata": {
"public": "true"
}
}
],
"repository": [
{
"project_id": 1,
"project_name": "library",
"project_public": true,
"pull_count": 7,
"repository_name": "library/busybox",
"tags_count": 1
},
:
:
:
{
"project_id": 1,
"project_name": "library",
"project_public": true,
"pull_count": 1,
"repository_name": "library/ubuntu",
"tags_count": 1
}
]
}

3. List up all Docker images and details of each image under the project 'library'

$ curl -i -k -X GET "https://harbor.mycompany.local/api/search?q=library/"

4. List up all Harbor registered users. This requires admin username and password.

$ curl -u admin:password -i -k -X GET "https://harbor.mycompany.local/api/users"

5. Delete a Harbor User. This requires admin username and password.

First, identify user_id of the user (in this example user1) you want to delete. 

$ curl -u admin:password -i -k -X GET "https://harbor.mycompany.local/api/users?username=user1"
{
"user_id": 4,
"username": "user1",
"email": "user1@mycompany.local",
"password": "01234530c02590d88285704369964daa",
"realname": "User1",
"comment": "N/A",
"deleted": 0,
"role_name": "",
"role_id": 0,
"has_admin_role": 0,
"reset_uuid": "",
"creation_time": "2018-03-21T11:33:50Z",
"update_time": "2018-03-21T11:33:50Z"
}

Delete the user using the identified user_id (in this example 4)

$ curl -u admin:password -i -k -X DELETE "https://harbor.mycompany.local/api/users/4

6. For thorough information over the Harbor APIs, follow these instructions.
It will provide you with WebUI which will give you easier browsing of the APIs:

 

Comments

Powered by Zendesk