Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit b365eef

Browse files
authored
support more than 100 items in request (#696)
Co-authored-by: Dmitrii Korolev <dmkorolev@microsoft.com>
1 parent 04ae7e5 commit b365eef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+65
-374
lines changed

src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.EntityExtractors.Abstractions;
2929
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
3030
using Microsoft.Extensions.Logging;
31-
using Newtonsoft.Json.Linq;
3231
using System;
3332
using System.Collections.Generic;
3433
using System.IO;

src/ArmTemplates/Common/API/Clients/Abstractions/ApiClientBase.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// Licensed under the MIT License.
44
// --------------------------------------------------------------------------
55

6+
using System.Collections.Generic;
67
using System.Net.Http;
78
using System.Net.Http.Headers;
89
using System.Threading.Tasks;
10+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Models;
911
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
1012
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions;
1113
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities;
@@ -20,7 +22,7 @@ public abstract class ApiClientBase
2022

2123
protected string BaseUrl { get; private set; } = GlobalConstants.BaseManagementAzureUrl;
2224

23-
protected Authentication Auth { get; private set; } = new Authentication();
25+
protected AzureCliAuthenticator Auth { get; private set; } = new AzureCliAuthenticator();
2426

2527
public ApiClientBase(string baseUrl = null)
2628
{
@@ -49,10 +51,30 @@ protected async Task<string> CallApiManagementAsync(string azToken, string reque
4951
return responseBody;
5052
}
5153

52-
protected async Task<TResponse> CallApiManagementAsync<TResponse>(string azToken, string requestUrl)
54+
protected async Task<TResponse> GetResponseAsync<TResponse>(string azToken, string requestUrl)
5355
{
5456
var stringResponse = await this.CallApiManagementAsync(azToken, requestUrl);
5557
return stringResponse.Deserialize<TResponse>();
5658
}
59+
60+
protected async Task<List<TResponse>> GetPagedResponseAsync<TResponse>(string azToken, string requestUrl)
61+
{
62+
var pageResponse = await MakePagedRequestAsync(requestUrl);
63+
64+
var responseItems = new List<TResponse>(pageResponse.Items);
65+
while (pageResponse?.NextLink is not null)
66+
{
67+
pageResponse = await MakePagedRequestAsync(pageResponse.NextLink);
68+
responseItems.AddRange(pageResponse.Items);
69+
}
70+
71+
return responseItems;
72+
73+
async Task<AzurePagedResponse<TResponse>> MakePagedRequestAsync(string requestUrl)
74+
{
75+
var stringResponse = await this.CallApiManagementAsync(azToken, requestUrl);
76+
return stringResponse.Deserialize<AzurePagedResponse<TResponse>>();
77+
}
78+
}
5779
}
5880
}

src/ArmTemplates/Common/API/Clients/ApiOperations/ApiOperationClient.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Threading.Tasks;
88
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
9-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.ApiOperations.Responses;
109
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
1110
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiOperations;
1211
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -24,8 +23,7 @@ public async Task<List<ApiOperationTemplateResource>> GetOperationsLinkedToApiAs
2423
string requestUrl = string.Format(GetOperationsLinkedToApiRequest,
2524
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, apiName, GlobalConstants.ApiVersion);
2625

27-
var response = await this.CallApiManagementAsync<GetApiOperationsResponse>(azToken, requestUrl);
28-
return response.ApiOperations;
26+
return await this.GetPagedResponseAsync<ApiOperationTemplateResource>(azToken, requestUrl);
2927
}
3028
}
3129
}

src/ArmTemplates/Common/API/Clients/ApiRevision/ApiRevisionClient.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Threading.Tasks;
88
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
9-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.ApiRevision.Responses;
109
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
1110
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiRevisions;
1211
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -24,8 +23,7 @@ public async Task<List<ApiRevisionTemplateResource>> GetApiRevisionsAsync(string
2423
string requestUrl = string.Format(GetApiRevisionsRequest,
2524
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, apiName, GlobalConstants.ApiVersion);
2625

27-
var response = await this.CallApiManagementAsync<GetApiRevisionsResponse>(azToken, requestUrl);
28-
return response.ApiRevisions;
26+
return await this.GetPagedResponseAsync<ApiRevisionTemplateResource>(azToken, requestUrl);
2927
}
3028
}
3129
}

src/ArmTemplates/Common/API/Clients/ApiRevision/Responses/GetApiRevisionsResponse.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/ArmTemplates/Common/API/Clients/ApiSchemas/ApiSchemaClient.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Threading.Tasks;
88
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
9-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.ApiSchemas.Responses;
109
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
1110
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiSchemas;
1211
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -24,8 +23,7 @@ public async Task<List<ApiSchemaTemplateResource>> GetApiSchemasAsync(string api
2423
var requestUrl = string.Format(GetAllApiSchemasRequest,
2524
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, apiName, GlobalConstants.ApiVersion);
2625

27-
var response = await this.CallApiManagementAsync<GetApiSchemasResponse>(azToken, requestUrl);
28-
return response.Schemas;
26+
return await this.GetPagedResponseAsync<ApiSchemaTemplateResource>(azToken, requestUrl);
2927
}
3028
}
3129
}

src/ArmTemplates/Common/API/Clients/ApiSchemas/Responses/GetApiSchemasResponse.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/ArmTemplates/Common/API/Clients/ApiVersionSet/ApiVersionSetClient.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Threading.Tasks;
88
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
9-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.ApiVersionSet.Responses;
109
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
1110
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiVersionSet;
1211
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -24,8 +23,7 @@ public async Task<List<ApiVersionSetTemplateResource>> GetAllAsync(ExtractorPara
2423
string requestUrl = string.Format(GetAllVersionSetsRequest,
2524
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);
2625

27-
var response = await this.CallApiManagementAsync<GetApiVersionSetsResponse>(azToken, requestUrl);
28-
return response.ApiVersionSets;
26+
return await this.GetPagedResponseAsync<ApiVersionSetTemplateResource>(azToken, requestUrl);
2927
}
3028
}
3129
}

src/ArmTemplates/Common/API/Clients/ApiVersionSet/Responses/GetApiVersionSetsResponse.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/ArmTemplates/Common/API/Clients/Apis/ApisClient.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Threading.Tasks;
88
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
9-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Apis.Responses;
109
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
1110
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Apis;
1211
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -26,17 +25,17 @@ public async Task<ApiTemplateResource> GetSingleAsync(string apiName, ExtractorP
2625
string requestUrl = string.Format(GetSingleApiRequest,
2726
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, apiName, GlobalConstants.ApiVersion);
2827

29-
return await this.CallApiManagementAsync<ApiTemplateResource>(azToken, requestUrl);
28+
return await this.GetResponseAsync<ApiTemplateResource>(azToken, requestUrl);
3029
}
3130

3231
public async Task<List<ApiTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
3332
{
3433
var (azToken, azSubId) = await this.Auth.GetAccessToken();
34+
3535
string requestUrl = string.Format(GetAllApisRequest,
3636
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);
3737

38-
var response = await this.CallApiManagementAsync<GetApisResponse>(azToken, requestUrl);
39-
return response.Apis;
38+
return await this.GetPagedResponseAsync<ApiTemplateResource>(azToken, requestUrl);
4039
}
4140

4241
public async Task<List<ApiTemplateResource>> GetAllLinkedToProductAsync(string productName, ExtractorParameters extractorParameters)
@@ -45,8 +44,7 @@ public async Task<List<ApiTemplateResource>> GetAllLinkedToProductAsync(string p
4544
string requestUrl = string.Format(GetAllApisLinkedToProductRequest,
4645
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, productName, GlobalConstants.ApiVersion);
4746

48-
var response = await this.CallApiManagementAsync<GetApisResponse>(azToken, requestUrl);
49-
return response.Apis;
47+
return await this.GetPagedResponseAsync<ApiTemplateResource>(azToken, requestUrl);
5048
}
5149

5250
public async Task<List<ApiTemplateResource>> GetAllLinkedToGatewayAsync(string gatewayName, ExtractorParameters extractorParameters)
@@ -55,8 +53,7 @@ public async Task<List<ApiTemplateResource>> GetAllLinkedToGatewayAsync(string g
5553
string requestUrl = string.Format(GetApisLinkedToGatewayRequest,
5654
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, gatewayName, GlobalConstants.ApiVersion);
5755

58-
var response = await this.CallApiManagementAsync<GetApisResponse>(azToken, requestUrl);
59-
return response.Apis;
56+
return await this.GetPagedResponseAsync<ApiTemplateResource>(azToken, requestUrl);
6057
}
6158
}
6259
}

src/ArmTemplates/Common/API/Clients/Apis/Responses/GetApisResponse.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/ArmTemplates/Common/API/Clients/AuthorizationServer/AuthorizationServerClient.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Threading.Tasks;
88
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
9-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.AuthorizationServer.Responses;
109
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
1110
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.AuthorizationServer;
1211
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -24,8 +23,7 @@ public async Task<List<AuthorizationServerTemplateResource>> GetAllAsync(Extract
2423
var requestUrl = string.Format(GetAllAuthorizationServersRequest,
2524
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);
2625

27-
var response = await this.CallApiManagementAsync<GetAuthorizationServersResponse>(azToken, requestUrl);
28-
return response.AuthorizationServers;
26+
return await this.GetPagedResponseAsync<AuthorizationServerTemplateResource>(azToken, requestUrl);
2927
}
3028
}
3129
}

src/ArmTemplates/Common/API/Clients/AuthorizationServer/Responses/GetAuthorizationServersResponse.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/ArmTemplates/Common/API/Clients/Backend/BackendClient.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Threading.Tasks;
88
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
9-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Backend.Responses;
109
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
1110
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Backend;
1211
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -24,8 +23,7 @@ public async Task<List<BackendTemplateResource>> GetAllAsync(ExtractorParameters
2423
var requestUrl = string.Format(GetAllBackendsRequest,
2524
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);
2625

27-
var response = await this.CallApiManagementAsync<GetBackendsResponse>(azToken, requestUrl);
28-
return response.Backends;
26+
return await this.GetPagedResponseAsync<BackendTemplateResource>(azToken, requestUrl);
2927
}
3028
}
3129
}

src/ArmTemplates/Common/API/Clients/Backend/Responses/GetBackendsResponse.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/ArmTemplates/Common/API/Clients/Diagnostics/DiagnosticClient.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Threading.Tasks;
88
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
9-
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Diagnostics.Responses;
109
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
1110
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.TemplateModels;
1211
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
@@ -16,16 +15,16 @@ namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clien
1615
public class DiagnosticClient : ApiClientBase, IDiagnosticClient
1716
{
1817
const string GetAllDiagnosticsRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/diagnostics?api-version={4}";
18+
const string GetDiagnosticsLinkedToApiRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/apis/{4}/diagnostics?api-version={5}";
1919

2020
public async Task<List<DiagnosticTemplateResource>> GetApiDiagnosticsAsync(string apiName, ExtractorParameters extractorParameters)
2121
{
2222
var (azToken, azSubId) = await this.Auth.GetAccessToken();
2323

24-
string requestUrl = string.Format("{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/apis/{4}/diagnostics?api-version={5}",
24+
string requestUrl = string.Format(GetDiagnosticsLinkedToApiRequest,
2525
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, apiName, GlobalConstants.ApiVersion);
2626

27-
var response = await this.CallApiManagementAsync<GetDiagnosticsResponse>(azToken, requestUrl);
28-
return response.Diagnostics;
27+
return await this.GetPagedResponseAsync<DiagnosticTemplateResource>(azToken, requestUrl);
2928
}
3029

3130
public async Task<List<DiagnosticTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
@@ -35,8 +34,7 @@ public async Task<List<DiagnosticTemplateResource>> GetAllAsync(ExtractorParamet
3534
var requestUrl = string.Format(GetAllDiagnosticsRequest,
3635
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);
3736

38-
var response = await this.CallApiManagementAsync<GetDiagnosticsResponse>(azToken, requestUrl);
39-
return response.Diagnostics;
37+
return await this.GetPagedResponseAsync<DiagnosticTemplateResource>(azToken, requestUrl);
4038
}
4139
}
4240
}

0 commit comments

Comments
 (0)