Google Cloud Platform Cloud 运行:使用 REST 获取服务 API

Google Cloud Platform Cloud Run: Get Services Using the REST API

我正在尝试使用 namespaces.services.list REST 方法列出项目 $GCP_PROJECT_NAME 的所有 Google 云平台 (GCP) 运行 服务(更多关于该方法 here).

但是,当我将 {endpoint} 替换为 asia-east1-run.googleapis.com 并将 {parent} 替换为 $GCP_PROJECT_NAME 时:

curl \
--request GET "https://asia-east1-run.googleapis.com/apis/serving.knative.dev/v1/$GCP_PROJECT_NAME/services" \
--header "Authorization: Bearer $(gcloud auth print-access-token)"

#=>

<!DOCTYPE html>
<html lang=en>
  . . .
  <title>Error 404 (Not Found)!!1</title>
  . . .
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/apis/serving.knative.dev/v1/$GCP_PROJECT_NAME/services</code> was not found on this server.  <ins>That’s all we know.</ins>

我得到一个 404。我也尝试过使用 GCP 项目编号而不是项目名称,但没有成功。

如果您查看您分享的有关该问题的文档,您会看到 {parent} 是:

The namespace from which the services should be listed. For Cloud Run (fully managed), replace {namespace_id} with the project ID or number. It takes the form namespaces/{namespace_id}.

所以你的 URL 中的问题是你正在为你 {projectID} 替换 {parent} 而实际上你应该替换为 namespace/{projectID}.

此外,显而易见但不妨说一下,在添加 https://asia-east1-run.googleapis.com 端点时不要复制 https://,因为 https:// 已经包含在 URL模板。

试试看,如果这能解决问题,请告诉我。