首页 > 解决方案 > 上次部署的 API 和实际使用的 API 之间似乎不匹配

问题描述

根据 Google Cloud Console > Endpoints > Services > Deployment History,这是当前部署的 API 规范:

swagger: "2.0"
info:
  title: "JSON Ingester"
  description: "Receive JSON files, transform and load them."
  version: "1.0.0"

host: "project-id-123.appspot.com"
schemes:
  - "https"

paths:
  "/upload":
    post:
      summary: "ETL JSON file."
      security:
        - api_key: []
      operationId: "upload"
      consumes:
        - multipart/form-data
      parameters:
        - in: formData
          name: file
          type: string
      responses:
        200:
          description: "File uploaded."
          schema:
            type: string
        400:
          description: "Error during file upload."

securityDefinitions:
  api_key:
    type: "apiKey"
    name: "apikey"
    in: "query"

但是不接受密钥“apikey”-相反,它需要在我几个小时前部署的 openapi.yaml 中指定的“密钥”。

这有效,但它不应该:

$ curl -X POST -F "file=@data/file_6.json" https://project-id-123.appspot.com/upload\?key\=AIzaS...Eaoog

这不起作用,而它应该:

$ curl -X POST -F "file=@data/file_6.json" https://project-id-123.appspot.com/upload\?apikey\=AIzaS...Eaoog
{
 "code": 16,
 "message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.",
 "details": [
  {
   "@type": "type.googleapis.com/google.rpc.DebugInfo",
   "stackEntries": [],
   "detail": "service_control"
  }
 ]
}

我必须清除缓存还是什么?

为了部署我使用的 API:

gcloud endpoints services deploy "./openapi.yaml"

有任何想法吗?

标签: google-cloud-endpointsswagger-2.0openapi

解决方案


您在部署 ESP 时使用了什么rollout_strategy?如果未指定,默认为“固定”。您应该使用“托管”

另请通过 CLI“gcloud endpoints configs describe”检查生成的服务配置。检查其 system_parameters 文件以查看您的新“apikey”是否已正确创建。


推荐阅读