简体   繁体   English

GCP - 如何在 API 网关中更新 api 规范

[英]GCP - How to update api specification in API Gateway

I have created an API Gateway and created an API config as well associated with it which lists a set of APIs.我已经创建了一个 API 网关并创建了一个 API 配置以及与之关联的列出一组 API 的配置。 Now I want to add/modify a set of APIs.现在我想添加/修改一组 API。 How do I update the same API config of this gateway?如何更新此网关的相同 API 配置?

I did it using gcloud CLI.我是使用 gcloud CLI 完成的。

First create a new config using your updated open api spec file:首先使用更新后的打开 api 规范文件创建一个新配置:

gcloud api-gateway api-configs create NEW_CONFIG_ID --api=MY_API --openapi-spec=openapi2-functions.yaml 

Then update your api gateway with new config:然后使用新配置更新您的 api 网关:

gcloud api-gateway gateways update MY-GATEWAY --api=MY-API --api-config=NEW_CONFIG_ID --location=YOUR_LOCATION

Referencing the official documentation , it states that:参考官方文档,它指出:

NOTE: Only the name and labels may be updated on an API config.注意:只有名称和标签可以在 API 配置上更新。

Therefore, you would need to create a new API config if you want to add/modify a set of APIs.因此,如果要添加/修改一组 API,则需要创建一个新的 API 配置

The GCP documentation mentions you cannot update an existing API config, only its display name and labels, and you cannot delete an existing API config that is in use by a gateway; GCP 文档提到您无法更新现有的 API 配置,只能更新其显示名称和标签,并且您无法删除网关正在使用的现有 API 配置 meaning you need to create a new API config altogether if your config file has changed.这意味着如果您的配置文件已更改,您需要完全创建一个新的 API 配置。

A workaround I found for this was to:我为此找到的解决方法是:

  1. Create new API config, point to gateway:新建API 配置,指向网关:
gcloud api-gateway api-configs create NEW_CONFIG_ID --api=MY_API --openapi-spec=openapi2-functions.yaml 
gcloud api-gateway gateways update MY-GATEWAY --api=MY-API --api-config=NEW_CONFIG_ID --location=YOUR_LOCATION
  1. Delete original config:删除原来的配置:
gcloud api-gateway api-configs delete OLD_CONFIG_ID --api=MY_API
  1. Redeploy new API config with name of original config, using your updated config file, point to gateway:使用原始配置的名称重新部署的 API 配置,使用更新后的配置文件,指向网关:
gcloud api-gateway api-configs create OLD_CONFIG_ID --api=MY_API --openapi-spec=openapi2-functions.yaml 
gcloud api-gateway gateways update MY-GATEWAY --api=MY-API --api-config=OLD_CONFIG_ID --location=YOUR_LOCATION
  1. Delete new config:删除配置:
gcloud api-gateway api-configs delete NEW_CONFIG_ID --api=MY_API

An awkward workaround but it allows for an automated redeployment of a similarly named API config file in a gateway.一个笨拙的解决方法,但它允许在网关中自动重新部署名称相似的 API 配置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM