在 Google 云端点中将多个版本部署到相同配置时如何为所有版本启用 api-key 身份验证
How to enable api-key auth for all version when deploying multiple versions to same configuration in Google Clould Endpoint
-
authentication
-
google-app-engine
-
google-cloud-endpoints
-
google-cloud-platform
-
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"
我可以复制这个问题,它似乎是一个错误。
有效的是在全局级别为两个版本添加 API 密钥限制,而不是在每个路径级别。也许这种变通方法足以满足您的用例。
...
security:
- api_key: []
path:
...
authentication
google-app-engine
google-cloud-endpoints
google-cloud-platform
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"
我可以复制这个问题,它似乎是一个错误。
有效的是在全局级别为两个版本添加 API 密钥限制,而不是在每个路径级别。也许这种变通方法足以满足您的用例。
...
security:
- api_key: []
path:
...