@@ -10,6 +10,13 @@ namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extract
10
10
{
11
11
public class APIExtractor : EntityExtractor
12
12
{
13
+ private FileWriter fileWriter ;
14
+
15
+ public APIExtractor ( FileWriter fileWriter )
16
+ {
17
+ this . fileWriter = fileWriter ;
18
+ }
19
+
13
20
public async Task < string > GetAPIOperations ( string ApiManagementName , string ResourceGroupName , string ApiName )
14
21
{
15
22
( string azToken , string azSubId ) = await auth . GetAccessToken ( ) ;
@@ -110,7 +117,7 @@ public async Task<string> GetAPISchemaDetails(string ApiManagementName, string R
110
117
return await CallApiManagement ( azToken , requestUrl ) ;
111
118
}
112
119
113
- public async Task < Template > GenerateAPIsARMTemplate ( string apimname , string resourceGroup , string fileFolder , string singleApiName , string policyXMLBaseUrl )
120
+ public async Task < Template > GenerateAPIsARMTemplate ( string apimname , string resourceGroup , string singleApiName , string policyXMLBaseUrl , string fileFolder )
114
121
{
115
122
// pull all apis from service
116
123
string apis = await GetAPIs ( apimname , resourceGroup ) ;
@@ -228,6 +235,18 @@ public async Task<Template> GenerateAPIsARMTemplate(string apimname, string reso
228
235
operationPolicyResource . scale = null ;
229
236
operationPolicyResource . dependsOn = new string [ ] { $ "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('ApimServiceName'), '{ oApiName } ', '{ operationResourceName } ')]" } ;
230
237
238
+ // write policy xml content to file and point to it if policyXMLBaseUrl is provided
239
+ if ( policyXMLBaseUrl != null )
240
+ {
241
+ string policyXMLContent = operationPolicyResource . properties . value ;
242
+ string policyFolder = String . Concat ( fileFolder , $@ "/policies") ;
243
+ string operationPolicyFileName = $@ "/{ operationName } -operationPolicy.xml";
244
+ this . fileWriter . CreateFolderIfNotExists ( policyFolder ) ;
245
+ this . fileWriter . WriteXMLToFile ( policyXMLContent , String . Concat ( policyFolder , operationPolicyFileName ) ) ;
246
+ operationPolicyResource . properties . format = "rawxml-link" ;
247
+ operationPolicyResource . properties . value = $ "[concat(parameters('PolicyXMLBaseUrl'), '{ operationPolicyFileName } ')]";
248
+ }
249
+
231
250
templateResources . Add ( operationPolicyResource ) ;
232
251
}
233
252
catch ( Exception ) { }
@@ -246,6 +265,17 @@ public async Task<Template> GenerateAPIsARMTemplate(string apimname, string reso
246
265
apiPoliciesResource . name = $ "[concat(parameters('ApimServiceName'), '/{ oApiName } /{ apiPoliciesResource . name } ')]";
247
266
apiPoliciesResource . dependsOn = new string [ ] { $ "[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), '{ apiName } ')]" } ;
248
267
268
+ // write policy xml content to file and point to it if policyXMLBaseUrl is provided
269
+ if ( policyXMLBaseUrl != null )
270
+ {
271
+ string policyXMLContent = apiPoliciesResource . properties . value ;
272
+ string policyFolder = String . Concat ( fileFolder , $@ "/policies") ;
273
+ string apiPolicyFileName = $@ "/{ apiName } -apiPolicy.xml";
274
+ this . fileWriter . CreateFolderIfNotExists ( policyFolder ) ;
275
+ this . fileWriter . WriteXMLToFile ( policyXMLContent , String . Concat ( policyFolder , apiPolicyFileName ) ) ;
276
+ apiPoliciesResource . properties . format = "rawxml-link" ;
277
+ apiPoliciesResource . properties . value = $ "[concat(parameters('PolicyXMLBaseUrl'), '{ apiPolicyFileName } ')]";
278
+ }
249
279
templateResources . Add ( apiPoliciesResource ) ;
250
280
}
251
281
catch ( Exception ) { }
0 commit comments