首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为所有版本启用api-key auth当将多个版本部署到Google Clould中的相同配置时

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

Stack Overflow用户
提问于 2017-08-30 13:24:15
回答 1查看 192关注 0票数 1

我使用Cloud的版本控制特性(即openapi.yaml )将两个版本的gcloud service-management deploy openapi_v1.yaml openapi_v2.yaml文件部署到Google。yaml文件的每个版本都包含一个与另一个版本不同的版本号和basepath,其中一个端点使用api密钥身份验证,以及api密钥身份验证标记的定义。在部署到Endpoint之后,配置显示了两个yaml文件,但是使用此配置将api部署到GAE只会打开更新版本的api密钥身份验证。

是否有人知道这是一个已知的bug,或者我还需要做一些其他的事情来启用所有版本的身份验证?

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

代码语言:javascript
复制
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"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-06 23:41:40

我可以复制这个问题,它似乎是一个bug。

真正起作用的是为这两个版本在全局级别上添加API键限制,而不是在每个路径级别。也许这个解决方案对您的用例来说就足够了。

代码语言:javascript
复制
...
security:
- api_key: []
path:
...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45961702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档