harbor icon indicating copy to clipboard operation
harbor copied to clipboard

Add document on how to call REST API through curl

Open stonezdj opened this issue 3 years ago • 1 comments

There is a doc section "View and Test the Harbor REST API via Swagger", but some users still don't know how to call it through curl.

There are three approaches that can be used in the curl command,

Basic auth with username password

curl -k -u <username>:<password> 'https://<harbor_host>/api/v2.0/users' 

Basic auth with robot account/secret

# Create a robot account with create project permission
curl -k --location --request POST 'https://<hostname>/api/v2.0/robots' \
-u <username>:<password> \
--header 'Content-Type: application/json' \
--data-raw '{
   "name":"test",
   "duration":30,
   "description":"test",
   "disable":false,
   "level":"system",
   "permissions":[
      {
         "kind":"system",
         "namespace":"/",
         "access":[
            {
               "resource":"project",
               "action":"create"
            }
         ]
      }
   ]
}'

For the system resource definition, go to https://github.com/goharbor/harbor/blob/main/src/common/rbac/const.go to get details.

# Create a project with the robot account
curl -k -u <robot_acocunt>:<secret> \
--location --request POST 'https://<hostname>/api/v2.0/projects' \
--header 'Content-Type: application/json' \
--data-raw '{"project_name":"sample2","metadata":{"public":"false"},"storage_limit":-1}'

Bearer token Refer this link: https://github.com/goharbor/harbor/wiki/Harbor-FAQs#api

Note: The basic auth can apply to the REST API defined in swagger.yaml and registry API, the bearer token is used to access registry API. (API start with /v2/)

stonezdj avatar Jul 21 '22 02:07 stonezdj

This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.

github-actions[bot] avatar Sep 19 '22 09:09 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. If this issue is still relevant, please re-open a new issue.

github-actions[bot] avatar Oct 19 '22 09:10 github-actions[bot]