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

Commit

Permalink
Introduce OriginalName for templateResources with common data process…
Browse files Browse the repository at this point in the history
…or (#807)

* Introduce OriginalName for templateResources with common data processor

* Remove similiar data processors and combine with common

Co-authored-by: Farhad Alizada <[email protected]>
  • Loading branch information
f-alizada and Farhad Alizada authored Aug 31, 2022
1 parent 7a3b68f commit 5da5b31
Show file tree
Hide file tree
Showing 57 changed files with 195 additions and 349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class ApiManagementServiceClient: ApiClientBase, IApiManagementServiceCli
{
const string GetApiManagementServiceByName = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}?api-version={4}";

readonly IApiManagementServiceProcessor apiManagementServiceProcessor;
readonly ITemplateResourceDataProcessor<ApiManagementServiceResource> templateResourceDataProcessor;

public ApiManagementServiceClient(
IHttpClientFactory httpClientFactory,
IApiManagementServiceProcessor apiManagementServiceProcessor): base(httpClientFactory)
IHttpClientFactory httpClientFactory,
ITemplateResourceDataProcessor<ApiManagementServiceResource> templateResourceDataProcessor) : base(httpClientFactory)
{
this.apiManagementServiceProcessor = apiManagementServiceProcessor;
this.templateResourceDataProcessor = templateResourceDataProcessor;
}

public async Task<ApiManagementServiceResource> GetApiManagementServiceAsync(ExtractorParameters extractorParameters)
Expand All @@ -34,7 +34,7 @@ public async Task<ApiManagementServiceResource> GetApiManagementServiceAsync(Ext
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);

var apiManagementServiceResource = await this.GetResponseAsync<ApiManagementServiceResource>(azToken, requestUrl);
this.apiManagementServiceProcessor.ProcessSingleInstanceData(apiManagementServiceResource, extractorParameters);
this.templateResourceDataProcessor.ProcessSingleData(apiManagementServiceResource);

return apiManagementServiceResource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiSchemas;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities.DataProcessors.Absctraction;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.ApiSchemas
{
public class ApiSchemaClient : ApiClientBase, IApiSchemaClient
{
const string GetAllApiSchemasRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/apis/{4}/schemas?api-version={5}";

readonly ITemplateResourceDataProcessor<ApiSchemaTemplateResource> templateResourceDataProcessor;

public ApiSchemaClient(IHttpClientFactory httpClientFactory) : base(httpClientFactory)
public ApiSchemaClient(IHttpClientFactory httpClientFactory, ITemplateResourceDataProcessor<ApiSchemaTemplateResource> templateResourceDataProcessor) : base(httpClientFactory)
{
this.templateResourceDataProcessor = templateResourceDataProcessor;
}

public async Task<List<ApiSchemaTemplateResource>> GetApiSchemasAsync(string apiName, ExtractorParameters extractorParameters)
Expand All @@ -28,7 +32,9 @@ public async Task<List<ApiSchemaTemplateResource>> GetApiSchemasAsync(string api
var requestUrl = string.Format(GetAllApiSchemasRequest,
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, apiName, GlobalConstants.ApiVersion);

return await this.GetPagedResponseAsync<ApiSchemaTemplateResource>(azToken, requestUrl);
var apiSchemaTemplateResources = await this.GetPagedResponseAsync<ApiSchemaTemplateResource>(azToken, requestUrl);
this.templateResourceDataProcessor.ProcessData(apiSchemaTemplateResources);
return apiSchemaTemplateResources;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiVersionSet;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities.DataProcessors.Absctraction;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.ApiVersionSet
{
public class ApiVersionSetClient : ApiClientBase, IApiVersionSetClient
{
const string GetAllVersionSetsRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/apiVersionSets?api-version={4}";

public ApiVersionSetClient(IHttpClientFactory httpClientFactory) : base(httpClientFactory)
readonly ITemplateResourceDataProcessor<ApiVersionSetTemplateResource> templateResourceDataProcessor;

public ApiVersionSetClient(IHttpClientFactory httpClientFactory, ITemplateResourceDataProcessor<ApiVersionSetTemplateResource> templateResourceDataProcessor) : base(httpClientFactory)
{
this.templateResourceDataProcessor = templateResourceDataProcessor;
}

public async Task<List<ApiVersionSetTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
Expand All @@ -28,7 +32,9 @@ public async Task<List<ApiVersionSetTemplateResource>> GetAllAsync(ExtractorPara
string requestUrl = string.Format(GetAllVersionSetsRequest,
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);

return await this.GetPagedResponseAsync<ApiVersionSetTemplateResource>(azToken, requestUrl);
var apiVersionSetTemplateresources = await this.GetPagedResponseAsync<ApiVersionSetTemplateResource>(azToken, requestUrl);
this.templateResourceDataProcessor.ProcessData(apiVersionSetTemplateresources);
return apiVersionSetTemplateresources;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.AuthorizationServer;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities.DataProcessors.Absctraction;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.AuthorizationServer
{
public class AuthorizationServerClient : ApiClientBase, IAuthorizationServerClient
{
const string GetAllAuthorizationServersRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/authorizationServers?api-version={4}";

public AuthorizationServerClient(IHttpClientFactory httpClientFactory) : base(httpClientFactory)
readonly ITemplateResourceDataProcessor<AuthorizationServerTemplateResource> templateResourceDataProcessor;

public AuthorizationServerClient(IHttpClientFactory httpClientFactory, ITemplateResourceDataProcessor<AuthorizationServerTemplateResource> templateResourceDataProcessor) : base(httpClientFactory)
{
this.templateResourceDataProcessor = templateResourceDataProcessor;
}

public async Task<List<AuthorizationServerTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
Expand All @@ -28,7 +32,9 @@ public async Task<List<AuthorizationServerTemplateResource>> GetAllAsync(Extract
var requestUrl = string.Format(GetAllAuthorizationServersRequest,
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);

return await this.GetPagedResponseAsync<AuthorizationServerTemplateResource>(azToken, requestUrl);
var authServerTemplateResources = await this.GetPagedResponseAsync<AuthorizationServerTemplateResource>(azToken, requestUrl);
this.templateResourceDataProcessor.ProcessData(authServerTemplateResources);
return authServerTemplateResources;
}
}
}
11 changes: 9 additions & 2 deletions src/ArmTemplates/Common/API/Clients/Backend/BackendClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Backend;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities.DataProcessors.Absctraction;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Backend
{
public class BackendClient : ApiClientBase, IBackendClient
{
const string GetAllBackendsRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/backends?api-version={4}";

public BackendClient(IHttpClientFactory httpClientFactory) : base(httpClientFactory)
readonly ITemplateResourceDataProcessor<BackendTemplateResource> templateResourceDataProcessor;

public BackendClient(IHttpClientFactory httpClientFactory, ITemplateResourceDataProcessor<BackendTemplateResource> templateResourceDataProcessor) : base(httpClientFactory)
{
this.templateResourceDataProcessor = templateResourceDataProcessor;
}

public async Task<List<BackendTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
Expand All @@ -28,7 +32,10 @@ public async Task<List<BackendTemplateResource>> GetAllAsync(ExtractorParameters
var requestUrl = string.Format(GetAllBackendsRequest,
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);

return await this.GetPagedResponseAsync<BackendTemplateResource>(azToken, requestUrl);
var backendTemplateResources = await this.GetPagedResponseAsync<BackendTemplateResource>(azToken, requestUrl);
this.templateResourceDataProcessor.ProcessData(backendTemplateResources);

return backendTemplateResources;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.TemplateModels;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities.DataProcessors.Absctraction;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Diagnostics
{
Expand All @@ -18,8 +19,11 @@ public class DiagnosticClient : ApiClientBase, IDiagnosticClient
const string GetAllDiagnosticsRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/diagnostics?api-version={4}";
const string GetDiagnosticsLinkedToApiRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/apis/{4}/diagnostics?api-version={5}";

public DiagnosticClient(IHttpClientFactory httpClientFactory) : base(httpClientFactory)
readonly ITemplateResourceDataProcessor<DiagnosticTemplateResource> templateResourceDataProcessor;

public DiagnosticClient(IHttpClientFactory httpClientFactory, ITemplateResourceDataProcessor<DiagnosticTemplateResource> templateResourceDataProcessor) : base(httpClientFactory)
{
this.templateResourceDataProcessor = templateResourceDataProcessor;
}

public async Task<List<DiagnosticTemplateResource>> GetApiDiagnosticsAsync(string apiName, ExtractorParameters extractorParameters)
Expand All @@ -29,7 +33,9 @@ public async Task<List<DiagnosticTemplateResource>> GetApiDiagnosticsAsync(strin
string requestUrl = string.Format(GetDiagnosticsLinkedToApiRequest,
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, apiName, GlobalConstants.ApiVersion);

return await this.GetPagedResponseAsync<DiagnosticTemplateResource>(azToken, requestUrl);
var diagnosticTemplateResources = await this.GetPagedResponseAsync<DiagnosticTemplateResource>(azToken, requestUrl);
this.templateResourceDataProcessor.ProcessData(diagnosticTemplateResources);
return diagnosticTemplateResources;
}

public async Task<List<DiagnosticTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
Expand All @@ -39,7 +45,9 @@ public async Task<List<DiagnosticTemplateResource>> GetAllAsync(ExtractorParamet
var requestUrl = string.Format(GetAllDiagnosticsRequest,
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);

return await this.GetPagedResponseAsync<DiagnosticTemplateResource>(azToken, requestUrl);
var diagnosticTemplateResources = await this.GetPagedResponseAsync<DiagnosticTemplateResource>(azToken, requestUrl);
this.templateResourceDataProcessor.ProcessData(diagnosticTemplateResources);
return diagnosticTemplateResources;
}
}
}
12 changes: 9 additions & 3 deletions src/ArmTemplates/Common/API/Clients/Gateway/GatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Gateway;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities.DataProcessors.Absctraction;
using Microsoft.Extensions.Logging;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Gateway
Expand All @@ -22,15 +23,18 @@ public class GatewayClient : ApiClientBase, IGatewayClient

readonly ILogger<GatewayClient> logger;
readonly IApisClient apisClient;
readonly ITemplateResourceDataProcessor<GatewayTemplateResource> templateResourceDataProcessor;

public GatewayClient(
IHttpClientFactory httpClientFactory,
ILogger<GatewayClient> logger,
IApisClient apisClient
): base(httpClientFactory)
IApisClient apisClient,
ITemplateResourceDataProcessor<GatewayTemplateResource> templateResourceDataProcessor
) : base(httpClientFactory)
{
this.logger = logger;
this.apisClient = apisClient;
this.templateResourceDataProcessor = templateResourceDataProcessor;
}

public async Task<List<GatewayTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
Expand All @@ -40,7 +44,9 @@ public async Task<List<GatewayTemplateResource>> GetAllAsync(ExtractorParameters
string requestUrl = string.Format(GetAllGatewaysRequest,
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);

return await this.GetPagedResponseAsync<GatewayTemplateResource>(azToken, requestUrl);
var gatewatTemplateResources = await this.GetPagedResponseAsync<GatewayTemplateResource>(azToken, requestUrl);
this.templateResourceDataProcessor.ProcessData(gatewatTemplateResources);
return gatewatTemplateResources;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class IdentityProviderClient : ApiClientBase, IIdentityProviderClient
const string GetAllIdentityProvidersRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/identityProviders?api-version={4}";
const string ListIdentyProviderSecret = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/identityProviders/{4}/listSecrets?api-version={5}";

readonly IIdentityProviderProcessor identityProviderProcessor;
readonly ITemplateResourceDataProcessor<IdentityProviderResource> templateResourceDataProcessor;

public IdentityProviderClient(
IHttpClientFactory httpClientFactory,
IIdentityProviderProcessor identityProviderProcessor): base(httpClientFactory)
ITemplateResourceDataProcessor<IdentityProviderResource> templateResourceDataProcessor) : base(httpClientFactory)
{
this.identityProviderProcessor = identityProviderProcessor;
this.templateResourceDataProcessor = templateResourceDataProcessor;
}

public async Task<List<IdentityProviderResource>> GetAllAsync(ExtractorParameters extractorParameters)
Expand All @@ -37,7 +37,7 @@ public async Task<List<IdentityProviderResource>> GetAllAsync(ExtractorParameter
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);

var identityProviderTemplates = await this.GetPagedResponseAsync<IdentityProviderResource>(azToken, requestUrl);
this.identityProviderProcessor.ProcessData(identityProviderTemplates, extractorParameters);
this.templateResourceDataProcessor.ProcessData(identityProviderTemplates);

return identityProviderTemplates;
}
Expand Down
11 changes: 8 additions & 3 deletions src/ArmTemplates/Common/API/Clients/Loggers/LoggerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Logger;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities.DataProcessors;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities.DataProcessors.Absctraction;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Loggers
{
public class LoggerClient : ApiClientBase, ILoggerClient
{
const string GetAllLoggersRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/loggers?api-version={4}";

public LoggerClient(IHttpClientFactory httpClientFactory) : base(httpClientFactory)
readonly ITemplateResourceDataProcessor<LoggerTemplateResource> templateResourceDataProcessor;
public LoggerClient(IHttpClientFactory httpClientFactory, ITemplateResourceDataProcessor<LoggerTemplateResource> templateResourceDataProcessor) : base(httpClientFactory)
{
this.templateResourceDataProcessor = templateResourceDataProcessor;
}

public async Task<List<LoggerTemplateResource>> GetAllAsync(ExtractorParameters extractorParameters)
Expand All @@ -28,8 +32,9 @@ public async Task<List<LoggerTemplateResource>> GetAllAsync(ExtractorParameters
string requestUrl = string.Format(GetAllLoggersRequest,
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);

return await this.GetPagedResponseAsync<LoggerTemplateResource>(azToken, requestUrl);

var loggerTemplateResources = await this.GetPagedResponseAsync<LoggerTemplateResource>(azToken, requestUrl);
this.templateResourceDataProcessor.ProcessData(loggerTemplateResources);
return loggerTemplateResources;
}
}
}
Loading

0 comments on commit 5da5b31

Please sign in to comment.