我正在开发一个旧的web服务,在该服务中,我使用自定义工具生成符合美洲国家组织标准的其他端点文档。使用这个美洲国家组织的json文件,我可以通过门户将API部署到Azure管理服务中,这一切都很好。但是,我需要自动化这个过程,因此需要使用ARM模板将所有web服务部署到Azure APIM。我一直在研究提供的https://learn.microsoft.com/en-us/azure/templates/microsoft.apimanagement/service/apis示例,但似乎无法理解如何在github中使用本地OAS.json文件或文件。
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"apiManagementServiceName": "price-capture"
},
"resources": [
{
"apiVersion": "2018-01-01",
"type": "Microsoft.ApiManagement/service/apis",
"name": "[variables('apiManagementServiceName')]",
"properties": {
"displayName": "Service display Name",
"apiRevision": "1",
"description": "API description",
//need help since it's not a swagger url
//wondering if there is a way to ref a local file like the option
//provided in the portal when we register api's manually.
"serviceUrl": "----",
"path": "----",
"protocols": [
"https"
],
"isCurrent": true,
"apiVersion": "v1",
"apiVersionDescription": "apiVersionDescription"
}
}
]
}
发布于 2019-06-25 17:27:49
我想出了..all必须做的答案,就是编写一个azure函数,从私有github存储库获取oas.yaml文件。
"variables":{
"swagger_json":"[concat(parameters('url_of_azurefunctionwithaccesskey'),'&&githuburi='parameter('raw_url'),'&githubaccesstoken=',parameter('personalaccesstoken')]"
},
"resources": [
{
"type": "Microsoft.ApiManagement/service/apis",
"name": "[concat(parameters('apimName') ,'/' ,parameters('serviceName'))]",
"apiVersion": "2018-06-01-preview",
"properties": {
"apiRevision": "[parameters('apiRevision')]",
"path": "pricecapture",
"contentValue": "[variables('swagger_json')]",
"contentFormat": "openapi-link"
}
}]
我不得不写的Azure函数是这样的:
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.IO;
using System.Text;
public static async Task<HttpResponseMessage> Run(HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var gitHubUri = req.Query["githuburi"];
var gitHubAccessToken = req.Query["githubaccesstoken"];
var encoding = Encoding.ASCII;
if (string.IsNullOrEmpty(gitHubUri))
{
var errorcontent = new StringContent("please pass the raw file content URI (raw.githubusercontent.com) in the request URI string", Encoding.ASCII);
return new HttpResponseMessage
{
StatusCode = HttpStatusCode.BadRequest,
Content = errorcontent
};
}
else if (string.IsNullOrEmpty(gitHubAccessToken))
{
var errorcontent = new StringContent("please pass the GitHub personal access token in the request URI string", Encoding.ASCII);
return new HttpResponseMessage
{
StatusCode = HttpStatusCode.BadRequest,
Content = errorcontent
};
}
else
{
var strAuthHeader = "token " + gitHubAccessToken;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3.raw");
client.DefaultRequestHeaders.Add("Authorization", strAuthHeader);
var response = await client.GetAsync(gitHubUri);
return response;
}
}
发布于 2018-09-04 04:12:15
您可以通过ARM模板在API管理上部署和配置整个API,但不能使用本地文件提供OpenApi/Swagger。在您的示例中,OpenApi/Swagger需要公开访问,以便资源管理器可以从中读取,因此,如果Github是可自由访问的,它应该可以工作。我通常将OpenApi/Swagger存储到存储帐户,并使用SAS令牌从ARM模板访问它。
有关APIM:https://blog.eldert.net/api-management-ci-cd-using-arm-templates-linked-template/中自动API部署的详细信息,您可以查看这个博客。
发布于 2019-01-31 02:19:40
您可以使用类型为Azure Resource Manager
的Microsoft.ApiManagement/service/apis
模板部署API,要使用Open / swagger定义,需要指定模板的contentValue
和contentFormat
参数
{
"name": "awesome-api-management/petstore",
"type": "Microsoft.ApiManagement/service/apis",
"apiVersion": "2018-06-01-preview",
"properties": {
"path": "petstore"
"contentValue": "petstore swagger file contents here", // or it's URL
"contentFormat": "swagger-json", // or swagger-link-json if externally available
}
}
https://stackoverflow.com/questions/52035173
复制相似问题