Harbor v2.0 API 无法获取Projects全部数量BUG复现

Posted 键客李大白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Harbor v2.0 API 无法获取Projects全部数量BUG复现相关的知识,希望对你有一定的参考价值。

BUG描述

在使用curl命令获取Harbor Projects数量时,出现了一个BUG:只能获取到前面10个Projects。

BUG复现

2.1 批量创建projects(项目)

1) 把创建的项目名称保存到指定文件

#编写批量创建测试project的脚本
[root@harbor-lidabai app]# cat  cat <<EOF > test.sh 
#!/bin/bash
for i in 1..120;do
  echo  harbor-test-$i  >>  Projects.txt
done
EOF
[root@harbor-lidabai app]#  chmod +x test.sh 
[root@harbor-lidabai app]# sh test.sh

2)编写批量创建Projects的脚本

$ vim Harbor-project-create-v1.sh 

#!/bin/bash
Harbor_Url=https://192.168.2.250:443
User=admin
Passwd=Harbor12345

# 将需要创建的项目名称填入到Projects.txt文件中
for project in `cat Projects.txt`;do
cat <<EOF >  tempharborProject.json
 
  "project_name": "$project",
  "public": false                      
 
EOF
  echo "查看文件内容:"
  cat tempharborProject.json
  echo "====================="
  curl -u "$User:$Passwd" -X POST -H "Content-Type: application/json"  $Harbor_Url/api/v2.0/projects -k -d @tempharborProject.json
done


3)执行脚本批量创建projects

$ chmod +x Harbor-project-create-v1.sh   #给脚本可执行权限
$ sh Harbor-project-create-v1.sh   #执行脚本
查看文件内容:
 
  "project_name": "lidabai-test1",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test2",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test3",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test4",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test5",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test6",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test7",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test8",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test9",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test10",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test11",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test12",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test13",
  "public": false                      
 
=====================
查看文件内容:
 
  "project_name": "lidabai-test14",
  "public": false                      
 
=====================

4)Harbor UI查看Projects数量

通过Harbor UI界面可以看到项目(Projects)的数量为136个。

2.2 API 获取Projects数量

调用Harbor v2 API 获取Projects数量。

$ curl -u admin:Harbor12345   -H "Content-Type: application/json" -X GET  https://192.168.2.250:443/api/v2.0/projects?  -k  |  python -m json.tool | grep name | awk /"name": /  | awk -F " print $4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4255    0  4255    0     0  89720      0 --:--:-- --:--:-- --:--:-- 90531
jenkins-demo
library
lidabai-test1
lidabai-test10
lidabai-test11
lidabai-test12
lidabai-test13
lidabai-test14
lidabai-test2
lidabai-test3

2.3 修改获取参数

[root@harbor-lidabai ~]#  curl -u admin:Harbor12345   -H "Content-Type: application/json" -X GET  https://192.168.2.250:443/api/v2.0/projects?page_size=100  -k  |  python -m json.tool | grep name | awk /"name": /  | awk -F " print $4 | wc  -l
100
[root@harbor-lidabai ~]#  curl -u admin:Harbor12345   -H "Content-Type: application/json" -X GET  https://192.168.2.250:443/api/v2.0/projects?page_size=120  -k  |  python -m json.tool | grep name | awk /"name": /  | awk -F " print $4 | wc  -l
0

三、结论

通过刚才的测试发现,通过Harbor API 仅可获取到最多100个Projects的数量。

以上是关于Harbor v2.0 API 无法获取Projects全部数量BUG复现的主要内容,如果未能解决你的问题,请参考以下文章

harbor部署,包括正式证书的使用

Facebook graph API V2.0 - 如何获取组上下文? (我的朋友的成员)

Graph API v2.0 之后,Apple Calendar 如何获取 Facebook 好友的生日?

Harbor版本升级:v1.8.x升级到1.10.7

Harbor私有仓库搭建

Harbor API实现镜像备份与恢复方案(2.0以上版本适用)