@@ -47,7 +47,16 @@ public async Task<string> GetProductPolicyAsync(string ApiManagementName, string
47
47
return await CallApiManagementAsync ( azToken , requestUrl ) ;
48
48
}
49
49
50
+ public async Task < string > GetProductGroupsAsync ( string ApiManagementName , string ResourceGroupName , string ProductName )
51
+ {
52
+ ( string azToken , string azSubId ) = await auth . GetAccessToken ( ) ;
53
+
54
+ string requestUrl = string . Format ( "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/products/{4}/groups?api-version={5}" ,
55
+ baseUrl , azSubId , ResourceGroupName , ApiManagementName , ProductName , GlobalConstants . APIVersion ) ;
50
56
57
+ return await CallApiManagementAsync ( azToken , requestUrl ) ;
58
+ }
59
+
51
60
public async Task < string > GetProductTagsAsync ( string ApiManagementName , string ResourceGroupName , string ProductName )
52
61
{
53
62
( string azToken , string azSubId ) = await auth . GetAccessToken ( ) ;
@@ -57,7 +66,7 @@ public async Task<string> GetProductTagsAsync(string ApiManagementName, string R
57
66
58
67
return await CallApiManagementAsync ( azToken , requestUrl ) ;
59
68
}
60
-
69
+
61
70
public async Task < Template > GenerateProductsARMTemplateAsync ( string apimname , string resourceGroup , string singleApiName , List < TemplateResource > apiTemplateResources , string policyXMLBaseUrl , string fileFolder )
62
71
{
63
72
Console . WriteLine ( "------------------------------------------" ) ;
@@ -88,6 +97,9 @@ public async Task<Template> GenerateProductsARMTemplateAsync(string apimname, st
88
97
productsTemplateResource . name = $ "[concat(parameters('ApimServiceName'), '/{ productName } ')]";
89
98
productsTemplateResource . apiVersion = GlobalConstants . APIVersion ;
90
99
100
+ string productGroupDetails = await GetProductGroupsAsync ( apimname , resourceGroup , productName ) ;
101
+ ProductGroupsTemplateResource productGroupsDetails = JsonConvert . DeserializeObject < ProductGroupsTemplateResource > ( productGroupDetails , settings ) ;
102
+
91
103
// only extract the product if this is a full extraction, or in the case of a single api, if it is found in products associated with the api
92
104
if ( singleApiName == null || productAPIResources . SingleOrDefault ( p => p . name . Contains ( $ "/{ productName } /") ) != null )
93
105
{
@@ -97,13 +109,21 @@ public async Task<Template> GenerateProductsARMTemplateAsync(string apimname, st
97
109
// add product policy resource to template
98
110
try
99
111
{
112
+ var productResourceId = new string [ ] { $ "[resourceId('Microsoft.ApiManagement/service/products', parameters('ApimServiceName'), '{ productName } ')]" } ;
113
+ foreach ( ProductGroupsValue ProductGroup in productGroupsDetails . value )
114
+ {
115
+ ProductGroup . name = $ "[concat(parameters('ApimServiceName'), '/{ productName } /{ ProductGroup . name } ')]";
116
+ ProductGroup . apiVersion = GlobalConstants . APIVersion ;
117
+ ProductGroup . dependsOn = productResourceId ;
118
+ templateResources . Add ( ProductGroup ) ;
119
+ }
100
120
string productPolicy = await GetProductPolicyAsync ( apimname , resourceGroup , productName ) ;
101
121
Console . WriteLine ( $ " - Product policy found for { productName } product") ;
102
122
PolicyTemplateResource productPolicyResource = JsonConvert . DeserializeObject < PolicyTemplateResource > ( productPolicy ) ;
103
123
productPolicyResource . name = $ "[concat(parameters('ApimServiceName'), '/{ productName } /policy')]";
104
124
productPolicyResource . apiVersion = GlobalConstants . APIVersion ;
105
125
productPolicyResource . scale = null ;
106
- productPolicyResource . dependsOn = new string [ ] { $ "[resourceId('Microsoft.ApiManagement/service/products', parameters('ApimServiceName'), ' { productName } ')]" } ;
126
+ productPolicyResource . dependsOn = productResourceId ;
107
127
108
128
// write policy xml content to file and point to it if policyXMLBaseUrl is provided
109
129
if ( policyXMLBaseUrl != null )
0 commit comments