antony@notes:~/container$ cat "Harbor-curl-API-integration.md"
Harbor curl API integration
Harbor curl API integration
1. 先把環境資訊設成變數
# 1.1. 設定 Harbor 的 FQDN
$ HarborURL="antony-harbor.example.com"
# 1.2. 透過 base64 演算法加密使用者名稱和密碼
$ Token=$(echo -n "admin:Harbor12345" | base64)
# 1.3. Test registry connection
## 看到 {} 代表有回應
$ curl -s -k -H "Accept: application/json" \
-H "Authorization: Basic ${Token}" \
"https://${HarborURL}/v2/"
{}2. 查看 Harbor 狀態
$ curl -s -k -H 'Accept: application/json' \
"https://${HarborURL}/api/v2.0/health"執行結果 :
{
"status": "healthy",
"components": [
{
"name": "portal",
"status": "healthy"
},
{
"name": "jobservice",
"status": "healthy"
},
{
"name": "registry",
"status": "healthy"
},
{
"name": "redis",
"status": "healthy"
},
{
"name": "core",
"status": "healthy"
},
{
"name": "database",
"status": "healthy"
},
{
"name": "registryctl",
"status": "healthy"
}
]
}3. 列出全部 projects
$ curl -s -k -H "Accept: application/json" \
-H "Authorization: Basic ${Token}" \
"https://${HarborURL}/api/v2.0/projects"執行結果 :
[
{
"project_id": 1,
"owner_id": 1,
"name": "library",
"creation_time": "2024-10-04T07:26:24.756448Z",
"update_time": "2024-10-04T07:26:24.756448Z",
"deleted": false,
"owner_name": "",
"current_user_role_id": 1,
"current_user_role_ids": [
1
],
"repo_count": 0,
"chart_count": 0,
"metadata": {
"public": "true"
},
"cve_whitelist": {
"id": 0,
"project_id": 0,
"items": null,
"creation_time": "0001-01-01T00:00:00Z",
"update_time": "0001-01-01T00:00:00Z"
}
},
{
"project_id": 2,
"owner_id": 1,
"name": "neuvector",
"creation_time": "2024-10-04T07:28:14Z",
"update_time": "2024-10-04T07:28:14Z",
"deleted": false,
"owner_name": "",
"current_user_role_id": 1,
"current_user_role_ids": [
1
],
"repo_count": 5,
"chart_count": 0,
"metadata": {
"public": "true"
},
"cve_whitelist": {
"id": 0,
"project_id": 0,
"items": null,
"creation_time": "0001-01-01T00:00:00Z",
"update_time": "0001-01-01T00:00:00Z"
}
}
]4. Get all images
$ curl -s -k \
-H "Accept: application/json" \
-H "Authorization: Basic ${Token}" \
"https://${HarborURL}/v2/_catalog" | jq執行結果 :
{
"repositories": [
"library/nginx",
"neuvector/controller",
"neuvector/enforcer",
"neuvector/manager",
"neuvector/scanner",
"neuvector/updater"
]
}5. Get registry repository tag list
$ curl -s -k -H "Accept: application/json" \
-H "Authorization: Basic ${Token}" \
"https://${HarborURL}/v2/neuvector/controller/tags/list" | jq執行結果 :
{
"name": "neuvector/controller",
"tags": [
"5.4.0"
]
}