@@ -10,12 +10,12 @@ namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extract
10
10
{
11
11
public class BackendExtractor : EntityExtractor
12
12
{
13
- public async Task < string > GetBackendsAsync ( string ApiManagementName , string ResourceGroupName )
13
+ public async Task < string > GetBackendsAsync ( 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}/backends?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}/backends?$skip={4}& api-version={5 }" ,
18
+ baseUrl , azSubId , ResourceGroupName , ApiManagementName , skipNumOfRecords , GlobalConstants . APIVersion ) ;
19
19
20
20
return await CallApiManagementAsync ( azToken , requestUrl ) ;
21
21
}
@@ -43,46 +43,55 @@ public async Task<Template> GenerateBackendsARMTemplateAsync(string apimname, st
43
43
var namedValueResources = propertyResources . Where ( resource => ( resource . type == ResourceTypeConstants . Property ) ) ;
44
44
45
45
// pull all backends for service
46
- string backends = await GetBackendsAsync ( apimname , resourceGroup ) ;
47
- JObject oBackends = JObject . Parse ( backends ) ;
46
+ JObject oBackends = new JObject ( ) ;
47
+ int skipNumberOfBackends = 0 ;
48
48
49
- foreach ( var item in oBackends [ "value" ] )
49
+ do
50
50
{
51
- string backendName = ( ( JValue ) item [ "name" ] ) . Value . ToString ( ) ;
52
- string backend = await GetBackendDetailsAsync ( apimname , resourceGroup , backendName ) ;
53
-
54
- // convert returned backend to template resource class
55
- BackendTemplateResource backendTemplateResource = JsonConvert . DeserializeObject < BackendTemplateResource > ( backend ) ;
56
- backendTemplateResource . name = $ "[concat(parameters('{ ParameterNames . ApimServiceName } '), '/{ backendName } ')]";
57
- backendTemplateResource . apiVersion = GlobalConstants . APIVersion ;
58
-
59
- ////only extract the backend if this is a full extraction, or in the case of a single api, if it is referenced by one of the policies
60
- //if (singleApiName == null)
61
- //{
62
- // // if the user is extracting all apis, extract all the backends
63
- // Console.WriteLine("'{0}' Backend found", backendName);
64
- // templateResources.Add(backendTemplateResource);
65
- //}
66
- //else
67
- //{
68
- // bool isReferencedInPolicy = false;
69
- // foreach (PolicyTemplateResource policyTemplateResource in policyResources)
70
- // {
71
- // // the backend is used in a policy if the xml contains a set-backend-service policy, which will reference the backend's url or id
72
- // string policyContent = policyTemplateResource.properties.policyContent;
73
- // isReferencedInPolicy = DoesPolicyReferenceBackend(policyContent, namedValueResources, backendName, backendTemplateResource);
74
- // }
75
- // if (isReferencedInPolicy == true)
76
- // {
77
- // // backend was used in policy, extract it
78
- // Console.WriteLine("'{0}' Backend found", backendName);
79
- // templateResources.Add(backendTemplateResource);
80
- // }
81
- //}
82
-
83
- Console . WriteLine ( "'{0}' Backend found" , backendName ) ;
84
- templateResources . Add ( backendTemplateResource ) ;
51
+ string backends = await GetBackendsAsync ( apimname , resourceGroup , skipNumberOfBackends ) ;
52
+ oBackends = JObject . Parse ( backends ) ;
53
+
54
+ foreach ( var item in oBackends [ "value" ] )
55
+ {
56
+ string backendName = ( ( JValue ) item [ "name" ] ) . Value . ToString ( ) ;
57
+ string backend = await GetBackendDetailsAsync ( apimname , resourceGroup , backendName ) ;
58
+
59
+ // convert returned backend to template resource class
60
+ BackendTemplateResource backendTemplateResource = JsonConvert . DeserializeObject < BackendTemplateResource > ( backend ) ;
61
+ backendTemplateResource . name = $ "[concat(parameters('{ ParameterNames . ApimServiceName } '), '/{ backendName } ')]";
62
+ backendTemplateResource . apiVersion = GlobalConstants . APIVersion ;
63
+
64
+ ////only extract the backend if this is a full extraction, or in the case of a single api, if it is referenced by one of the policies
65
+ //if (singleApiName == null)
66
+ //{
67
+ // // if the user is extracting all apis, extract all the backends
68
+ // Console.WriteLine("'{0}' Backend found", backendName);
69
+ // templateResources.Add(backendTemplateResource);
70
+ //}
71
+ //else
72
+ //{
73
+ // bool isReferencedInPolicy = false;
74
+ // foreach (PolicyTemplateResource policyTemplateResource in policyResources)
75
+ // {
76
+ // // the backend is used in a policy if the xml contains a set-backend-service policy, which will reference the backend's url or id
77
+ // string policyContent = policyTemplateResource.properties.policyContent;
78
+ // isReferencedInPolicy = DoesPolicyReferenceBackend(policyContent, namedValueResources, backendName, backendTemplateResource);
79
+ // }
80
+ // if (isReferencedInPolicy == true)
81
+ // {
82
+ // // backend was used in policy, extract it
83
+ // Console.WriteLine("'{0}' Backend found", backendName);
84
+ // templateResources.Add(backendTemplateResource);
85
+ // }
86
+ //}
87
+
88
+ Console . WriteLine ( "'{0}' Backend found" , backendName ) ;
89
+ templateResources . Add ( backendTemplateResource ) ;
90
+ }
91
+
92
+ skipNumberOfBackends += GlobalConstants . NumOfRecords ;
85
93
}
94
+ while ( oBackends [ "nextLink" ] != null ) ;
86
95
87
96
armTemplate . resources = templateResources . ToArray ( ) ;
88
97
return armTemplate ;
@@ -92,14 +101,14 @@ public bool DoesPolicyReferenceBackend(string policyContent, IEnumerable<Templat
92
101
{
93
102
// a policy is referenced by a backend with the set-backend-service policy, which will reference use the backends name or url, or through referencing a named value that applies to the backend
94
103
var namedValueResourcesUsedByBackend = namedValueResources . Where ( resource => DoesBackendReferenceNamedValue ( resource , backendTemplateResource ) ) ;
95
- if ( ( backendName != null && policyContent . Contains ( backendName ) ) ||
96
- ( backendTemplateResource . properties . url != null && policyContent . Contains ( backendTemplateResource . properties . url ) ) ||
104
+ if ( ( backendName != null && policyContent . Contains ( backendName ) ) ||
105
+ ( backendTemplateResource . properties . url != null && policyContent . Contains ( backendTemplateResource . properties . url ) ) ||
97
106
( backendTemplateResource . properties . title != null && policyContent . Contains ( backendTemplateResource . properties . title ) ) ||
98
107
( backendTemplateResource . properties . resourceId != null && policyContent . Contains ( backendTemplateResource . properties . resourceId ) ) )
99
108
{
100
109
return true ;
101
110
}
102
- foreach ( PropertyTemplateResource namedValueResource in namedValueResourcesUsedByBackend )
111
+ foreach ( PropertyTemplateResource namedValueResource in namedValueResourcesUsedByBackend )
103
112
{
104
113
if ( policyContent . Contains ( namedValueResource . properties . displayName ) || policyContent . Contains ( namedValueResource . properties . value ) )
105
114
{
@@ -113,7 +122,7 @@ public bool DoesPolicyReferenceBackend(string policyContent, IEnumerable<Templat
113
122
public bool DoesBackendReferenceNamedValue ( TemplateResource namedValueResource , BackendTemplateResource backendTemplateResource )
114
123
{
115
124
string namedValue = ( namedValueResource as PropertyTemplateResource ) . properties . value ;
116
- return ( namedValue == backendTemplateResource . properties . url
125
+ return ( namedValue == backendTemplateResource . properties . url
117
126
|| namedValue == backendTemplateResource . properties . description
118
127
|| namedValue == backendTemplateResource . properties . title ) ;
119
128
}
0 commit comments