@@ -30,6 +30,16 @@ public async Task<string> GetProductDetails(string ApiManagementName, string Res
30
30
return await CallApiManagement ( azToken , requestUrl ) ;
31
31
}
32
32
33
+ public async Task < string > GetProductPolicy ( string ApiManagementName , string ResourceGroupName , string ProductName )
34
+ {
35
+ ( string azToken , string azSubId ) = await auth . GetAccessToken ( ) ;
36
+
37
+ string requestUrl = string . Format ( "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/products/{4}/policies/policy?api-version={5}" ,
38
+ baseUrl , azSubId , ResourceGroupName , ApiManagementName , ProductName , GlobalConstants . APIVersion ) ;
39
+
40
+ return await CallApiManagement ( azToken , requestUrl ) ;
41
+ }
42
+
33
43
public async Task < Template > GenerateProductsARMTemplate ( string apimname , string resourceGroup , string singleApiName , List < TemplateResource > apiTemplateResources )
34
44
{
35
45
Console . WriteLine ( "------------------------------------------" ) ;
@@ -65,6 +75,21 @@ public async Task<Template> GenerateProductsARMTemplate(string apimname, string
65
75
{
66
76
Console . WriteLine ( "'{0}' Product found" , productName ) ;
67
77
templateResources . Add ( productsTemplateResource ) ;
78
+
79
+ // add product policy resource to template
80
+ try
81
+ {
82
+ string productPolicy = await GetProductPolicy ( apimname , resourceGroup , productName ) ;
83
+ Console . WriteLine ( $ " - Product policy found for { productName } product") ;
84
+ PolicyTemplateResource productPolicyResource = JsonConvert . DeserializeObject < PolicyTemplateResource > ( productPolicy ) ;
85
+ productPolicyResource . name = $ "[concat(parameters('ApimServiceName'), '/{ productName } /policy')]";
86
+ productPolicyResource . apiVersion = GlobalConstants . APIVersion ;
87
+ productPolicyResource . scale = null ;
88
+ productPolicyResource . dependsOn = new string [ ] { $ "[resourceId('Microsoft.ApiManagement/service/products', parameters('ApimServiceName'), '{ productName } ')]" } ;
89
+
90
+ templateResources . Add ( productPolicyResource ) ;
91
+ }
92
+ catch ( Exception ) { }
68
93
}
69
94
}
70
95
0 commit comments