在Google Clould Endpoint中将多个版本部署到相同配置时,如何为所有版本启用api-key auth

时间:2017-08-30 13:24:15

标签: google-app-engine authentication google-cloud-platform google-cloud-endpoints google-cloud-endpoints-v2

我使用Cloud Endpoint的版本控制功能(即gcloud service-management deploy openapi_v1.yaml openapi_v2.yaml)将2个版本的openapi.yaml文件部署到Google Cloud Endpoint。每个版本的yaml文件都包含与另一个版本号不同的版本号和基本路径,一个使用api-key身份验证的端点,以及api-key身份验证标记的定义。部署到Endpoint后,配置显示两个yaml文件,但是使用此配置将api部署到GAE只会为较新版本启用api-key身份验证。

有谁知道这是否是一个已知的错误,或者我还需要做些什么才能为所有版本启用身份验证?

.yaml文件如下所示。我用来测试的两个版本是相同的,除了版本和bathpath:

swagger: "2.0"
info:
  description: "This API is used to connect 3rd-party ids to a common user identity"
  version: "0.0.1"
  title: "****"
host: "uie-dot-user-id-exchange.appspot.com"
basePath: "/v0"

...

- "https"
x-google-allow: all

paths:

  ...

  /ids/search:
    get:
      operationId: "id_search"
      produces:
      - "application/json"
      security:
      - api_key: []
      tags:
      - "Ids"
      summary: "Privileged endpoint. Provide any id (3rd party or otherwise) and get a hash of all ids associated with it."
      parameters:
      - in: "query"
        name: "id_type"
        description: "Type of id to search"
        required: true
        type: string
      - in: "query"
        name: "id_value"
        description: "Value of id to search"
        required: true
        type: string
      responses:
        200:
          description: "AssociatedIdsHash"
          schema:
            $ref: '#/definitions/AssociatedIdsHash'
        400:
          description: "Bad request. Requires both id_type and id_value query parameters."
        401:
          description: "Unauthorized. Please provide a valid api-key in the \"api-key\" header."
        404:
          description: "Not found - no entry found for key provided"

...

################ SECURITY DEFINITIONS ################
securityDefinitions:
  # This section configures basic authentication with an API key.
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"

1 个答案:

答案 0 :(得分:0)

我可以复制这个问题,但这似乎是一个错误。

在两个版本而不是在每个路径级别的全局级别上添加API密钥限制的工作原理是什么。也许这种解决方法足以满足您的使用案例。

...
security:
- api_key: []
path:
...