8
8
9
9
namespace Microsoft . Azure . Management . ApiManagement . ArmTemplates . Extract
10
10
{
11
- public class TagExtractor : EntityExtractor
11
+ public class TagExtractor : EntityExtractor
12
12
{
13
- public async Task < string > GetTagsAsync ( string ApiManagementName , string ResourceGroupName )
13
+ public async Task < string > GetTagsAsync ( string ApiManagementName , string ResourceGroupName , int skipNumOfRecords )
14
14
{
15
15
( string azToken , string azSubId ) = await auth . GetAccessToken ( ) ;
16
16
17
- string requestUrl = string . Format ( "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/Tags?api-version={4 }" ,
18
- baseUrl , azSubId , ResourceGroupName , ApiManagementName , GlobalConstants . APIVersion ) ;
17
+ string requestUrl = string . Format ( "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/Tags?$skip={4}& api-version={5 }" ,
18
+ baseUrl , azSubId , ResourceGroupName , ApiManagementName , skipNumOfRecords , GlobalConstants . APIVersion ) ;
19
19
20
20
return await CallApiManagementAsync ( azToken , requestUrl ) ;
21
21
}
@@ -28,7 +28,7 @@ public async Task<Template> GenerateTagsTemplateAsync(string apimname, string re
28
28
29
29
// isolate tag and api operation associations in the case of a single api extraction
30
30
var apiOperationTagResources = apiTemplateResources . Where ( resource => resource . type == ResourceTypeConstants . APIOperationTag ) ;
31
-
31
+
32
32
// isolate tag and api associations in the case of a single api extraction
33
33
var apiTagResources = apiTemplateResources . Where ( resource => resource . type == ResourceTypeConstants . APITag ) ;
34
34
@@ -41,34 +41,44 @@ public async Task<Template> GenerateTagsTemplateAsync(string apimname, string re
41
41
List < TemplateResource > templateResources = new List < TemplateResource > ( ) ;
42
42
43
43
// pull all named values (Tags) for service
44
- string Tags = await GetTagsAsync ( apimname , resourceGroup ) ;
45
- JObject oTags = JObject . Parse ( Tags ) ;
44
+ JObject oTags = new JObject ( ) ;
45
+ int skipNumOfTags = 0 ;
46
46
47
- foreach ( var extractedTag in oTags [ "value" ] )
47
+ do
48
48
{
49
- string TagName = ( ( JValue ) extractedTag [ "name" ] ) . Value . ToString ( ) ;
50
-
51
- // convert returned named value to template resource class
52
- TagTemplateResource TagTemplateResource = JsonConvert . DeserializeObject < TagTemplateResource > ( extractedTag . ToString ( ) ) ;
53
- TagTemplateResource . name = $ "[concat(parameters('{ ParameterNames . ApimServiceName } '), '/{ TagName } ')]";
54
- TagTemplateResource . type = ResourceTypeConstants . Tag ;
55
- TagTemplateResource . apiVersion = GlobalConstants . APIVersion ;
56
- TagTemplateResource . scale = null ;
57
-
58
- // only extract the tag if this is a full extraction,
59
- // or in the case of a single api, if it is found in tags associated with the api operations
60
- // or if it is found in tags associated with the api
61
- // or if it is found in tags associated with the products associated with the api
62
- if ( singleApiName == null
63
- || apiOperationTagResources . Any ( t => t . name . Contains ( $ "/{ TagName } '") )
64
- || apiTagResources . Any ( t => t . name . Contains ( $ "/{ TagName } '") )
65
- || ( productAPIResources . Any ( t => t . name . Contains ( $ "/{ singleApiName } ") )
66
- && productTagResources . Any ( t => t . name . Contains ( $ "/{ TagName } '") ) ) )
49
+ string Tags = await GetTagsAsync ( apimname , resourceGroup , skipNumOfTags ) ;
50
+ oTags = JObject . Parse ( Tags ) ;
51
+
52
+ foreach ( var extractedTag in oTags [ "value" ] )
67
53
{
68
- Console . WriteLine ( "'{0}' Tag found" , TagName ) ;
69
- templateResources . Add ( TagTemplateResource ) ;
54
+ string TagName = ( ( JValue ) extractedTag [ "name" ] ) . Value . ToString ( ) ;
55
+
56
+ // convert returned named value to template resource class
57
+ TagTemplateResource TagTemplateResource = JsonConvert . DeserializeObject < TagTemplateResource > ( extractedTag . ToString ( ) ) ;
58
+ TagTemplateResource . name = $ "[concat(parameters('{ ParameterNames . ApimServiceName } '), '/{ TagName } ')]";
59
+ TagTemplateResource . type = ResourceTypeConstants . Tag ;
60
+ TagTemplateResource . apiVersion = GlobalConstants . APIVersion ;
61
+ TagTemplateResource . scale = null ;
62
+
63
+ // only extract the tag if this is a full extraction,
64
+ // or in the case of a single api, if it is found in tags associated with the api operations
65
+ // or if it is found in tags associated with the api
66
+ // or if it is found in tags associated with the products associated with the api
67
+ if ( singleApiName == null
68
+ || apiOperationTagResources . Any ( t => t . name . Contains ( $ "/{ TagName } '") )
69
+ || apiTagResources . Any ( t => t . name . Contains ( $ "/{ TagName } '") )
70
+ || ( productAPIResources . Any ( t => t . name . Contains ( $ "/{ singleApiName } ") )
71
+ && productTagResources . Any ( t => t . name . Contains ( $ "/{ TagName } '") ) ) )
72
+ {
73
+ Console . WriteLine ( "'{0}' Tag found" , TagName ) ;
74
+ templateResources . Add ( TagTemplateResource ) ;
75
+ }
70
76
}
77
+
78
+ skipNumOfTags += GlobalConstants . NumOfRecords ;
71
79
}
80
+ while ( oTags [ "nextLink" ] != null ) ;
81
+
72
82
73
83
armTemplate . resources = templateResources . ToArray ( ) ;
74
84
return armTemplate ;
0 commit comments