将 pageToken 添加到 Google Cloud API 的 curl 请求

adding pageToken to curl request to a Google Cloud API

我正在向此发送获取请求api

https://containeranalysis.googleapis.com/v1/projects/PROJECT_ID/occurrences?filter=kind%3D%22DISCOVERY%22%20AND%20resourceUrl%3D%22ENCODED_RESOURCE_URL%22

获取容器镜像的漏洞列表,但是完整列表以页面分隔,并且需要通过添加 pageToken 参数修改请求以获得除第一页之外的任何内容。我不知道如何添加该 pageToken。我试过将它添加为 header 并将其添加到 url(?pageToken=&pageToken= 以及不同的编码组合),但它们没有用。我找不到有关如何使用 curl.

执行此操作的文档

我尝试过的请求示例如下:

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud auth print-access-token)" https://containeranalysis.googleapis.com/v1beta1/projects/my_project/occurrences?filter=kind%3D%22VULNERABILITY%22%20AND%20resourceUrl%3D%22https%3A//us.gcr.io/my_project/tabulate%40sha256%3Ahash%22%26PageToken%3D%22token_number%22

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud auth print-access-token)" https://containeranalysis.googleapis.com/v1beta1/projects/my_project/occurrences?filter=kind%3D%22VULNERABILITY%22%20AND%20resourceUrl%3D%22https%3A//us.gcr.io/my_project/tabulate%40sha256%3Ahash%22?PageToken=%22token_number%22

对于这两个我得到

{
  "error": {
    "code": 500,
    "message": "Unknown Error.",
    "status": "UNKNOWN"
  }
}

我使用 python 的请求库让它工作。例如,这很有效:

url = 'https://containeranalysis.googleapis.com/v1/projects/{}/occurrences'
parameter = '?pageSize=1&pageToken={}'
response = requests.get(
    url.format(project_ID) + parameter.format(page_token),
    headers={"Authorization": f"Bearer {auth_token}"})

其中 page_token 是之前由 API

返回的任何标记