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

Commit

Permalink
Extract ApiManagement service (#760)
Browse files Browse the repository at this point in the history
* Add ApiMAnagement Service models, client, processor, extractor
* Add integration test for ApiManagementService
* Update supported resources doc file

Co-authored-by: Farhad Alizada <falizada@microsoft.com>
  • Loading branch information
f-alizada and Farhad Alizada committed Jul 4, 2022
1 parent c2a2cee commit bb99a62
Show file tree
Hide file tree
Showing 35 changed files with 813 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/SupportedResources/2021-08-01.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Some of operations could be skipped (not needed for extraction), because they ar
| API Issue Attachment || | |
| API Issue Comment || | |
| API Management Operations | - | | |
| API Management Service | | | we can load service description |
| API Management Service | | [main](https://github.com/Azure/azure-api-management-devops-resource-kit) | we can load service description |
| API Management Service Skus | - | | |
| Api Operation || [1.0.0-beta.2](https://github.com/Azure/azure-api-management-devops-resource-kit/releases/tag/1.0.0-beta.2) | |
| Api Operation Policy || [1.0.0-beta.2](https://github.com/Azure/azure-api-management-devops-resource-kit/releases/tag/1.0.0-beta.2) | |
Expand Down Expand Up @@ -40,7 +40,7 @@ Some of operations could be skipped (not needed for extraction), because they ar
| Gateway Hostname Configuration || | |
| Group || [1.0.0-beta.2](https://github.com/Azure/azure-api-management-devops-resource-kit/releases/tag/1.0.0-beta.2) | |
| Group User || | |
| Identity Provider | | | |
| Identity Provider | | [1.0.0-beta.7](https://github.com/Azure/azure-api-management-devops-resource-kit/releases/tag/1.0.0-beta.7) | |
| Issue || | |
| Logger || [1.0.0-beta.2](https://github.com/Azure/azure-api-management-devops-resource-kit/releases/tag/1.0.0-beta.2) | |
| Network Status || | |
Expand Down
30 changes: 27 additions & 3 deletions src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.FileHandlers;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Apis;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiVersionSet;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.AuthorizationServer;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class ExtractorExecutor
readonly IGatewayExtractor gatewayExtractor;
readonly IGatewayApiExtractor gatewayApiExtractor;
readonly IIdentityProviderExtractor identityProviderExtractor;
readonly IApiManagementServiceExtractor apiManagementServiceExtractor;

public ExtractorExecutor(
ILogger<ExtractorExecutor> logger,
Expand All @@ -83,7 +85,8 @@ public class ExtractorExecutor
IApiRevisionExtractor apiRevisionExtractor,
IGatewayExtractor gatewayExtractor,
IGatewayApiExtractor gatewayApiExtractor,
IIdentityProviderExtractor identityProviderExtractor)
IIdentityProviderExtractor identityProviderExtractor,
IApiManagementServiceExtractor apiManagementServiceExtractor)
{
this.logger = logger;
this.apisClient = apisClient;
Expand All @@ -105,6 +108,7 @@ public class ExtractorExecutor
this.gatewayExtractor = gatewayExtractor;
this.gatewayApiExtractor = gatewayApiExtractor;
this.identityProviderExtractor = identityProviderExtractor;
this.apiManagementServiceExtractor = apiManagementServiceExtractor;
}

/// <summary>
Expand All @@ -131,7 +135,8 @@ public class ExtractorExecutor
IApiRevisionExtractor apiRevisionExtractor = null,
IGatewayExtractor gatewayExtractor = null,
IGatewayApiExtractor gatewayApiExtractor = null,
IIdentityProviderExtractor identityProviderExtractor = null)
IIdentityProviderExtractor identityProviderExtractor = null,
IApiManagementServiceExtractor apiManagementServiceExtractor = null)
=> new ExtractorExecutor(
logger,
apisClient,
Expand All @@ -152,7 +157,8 @@ public class ExtractorExecutor
apiRevisionExtractor,
gatewayExtractor,
gatewayApiExtractor,
identityProviderExtractor);
identityProviderExtractor,
apiManagementServiceExtractor);

public void SetExtractorParameters(ExtractorParameters extractorParameters)
{
Expand Down Expand Up @@ -728,6 +734,23 @@ public async Task<Template<IdentityProviderResources>> GenerateIdentityProviderT
return gatewayApiTemplate;
}

public async Task<Template<ApiManagementServiceResources>> GenerateApiManagementServiceTemplate(string baseFilesGenerationDirectory)
{
this.logger.LogInformation("Started generation of ApiManagement service template...");
var apiManagementServiceTemplate = await this.apiManagementServiceExtractor.GenerateApiManagementServicesTemplateAsync(this.extractorParameters);

if (apiManagementServiceTemplate?.HasResources() == true)
{
await FileWriter.SaveAsJsonAsync(
apiManagementServiceTemplate,
directory: baseFilesGenerationDirectory,
fileName: this.extractorParameters.FileNames.ApiManagementService);
}

this.logger.LogInformation("Finished generation of identity providers template...");
return apiManagementServiceTemplate;
}

/// <summary>
/// Generates split api templates / folders for each api in this sourceApim
/// </summary>
Expand Down Expand Up @@ -910,6 +933,7 @@ await foreach (var apiRevision in this.apiRevisionExtractor.GetApiRevisionsAsync
var identityProviderTemplate = await this.GenerateIdentityProviderTemplateAsync(baseFilesGenerationDirectory);
await this.GenerateGatewayTemplateAsync(singleApiName, baseFilesGenerationDirectory);
await this.GenerateGatewayApiTemplateAsync(singleApiName, multipleApiNames, baseFilesGenerationDirectory);
await this.GenerateApiManagementServiceTemplate(baseFilesGenerationDirectory);
await this.GenerateParametersTemplateAsync(apisToExtract, loggerTemplate.TypedResources, backendTemplate.TypedResources, namedValueTemplate.TypedResources, identityProviderTemplate.TypedResources, baseFilesGenerationDirectory);

await this.GenerateMasterTemplateAsync(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

using System.Threading.Tasks;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions
{
public interface IApiManagementServiceClient
{
Task<ApiManagementServiceResource> GetApiManagementServiceAsync(ExtractorParameters extractorParameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService;
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.ApiManagementService
{
public class ApiManagementServiceClient: ApiClientBase, IApiManagementServiceClient
{
const string GetApiManagementServiceByName = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}?api-version={4}";

readonly IApiManagementServiceProcessor apiManagementServiceProcessor;

public ApiManagementServiceClient(
IHttpClientFactory httpClientFactory,
IApiManagementServiceProcessor apiManagementServiceProcessor): base(httpClientFactory)
{
this.apiManagementServiceProcessor = apiManagementServiceProcessor;
}

public async Task<ApiManagementServiceResource> GetApiManagementServiceAsync(ExtractorParameters extractorParameters)
{
var (azToken, azSubId) = await this.Auth.GetAccessToken();

string requestUrl = string.Format(GetApiManagementServiceByName,
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);

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

return apiManagementServiceResource;
}
}
}
1 change: 1 addition & 0 deletions src/ArmTemplates/Common/Constants/ResourceTypeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public static class ResourceTypeConstants
public const string GatewayApi = "Microsoft.ApiManagement/service/gateways/apis";
public const string ArmDeployments = "Microsoft.Resources/deployments";
public const string IdentityProviders = "Microsoft.ApiManagement/service/identityProviders";
public const string ApiManagementService = "Microsoft.ApiManagement/service";
}
}
2 changes: 1 addition & 1 deletion src/ArmTemplates/Common/Extensions/JsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions
{
static class JsonExtensions
public static class JsonExtensions
{
static readonly JsonSerializerSettings DefaultJsonSerializationSettings = new JsonSerializerSettings
{
Expand Down
1 change: 1 addition & 0 deletions src/ArmTemplates/Common/FileHandlers/FileNameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static FileNames GenerateFileNames(string baseFileName)
Gateway = $@"{baseFileName}gateways.template.json",
GatewayApi = $@"{baseFileName}gateways-apis.template.json",
IdentityProviders = $@"{baseFileName}identity-providers.template.json",
ApiManagementService = $@"{baseFileName}api-management-service.template.json",
TagApi = $@"{baseFileName}apiTags.template.json",
Parameters = $@"{baseFileName}parameters.json",
LinkedMaster = $@"{baseFileName}master.template.json",
Expand Down
2 changes: 2 additions & 0 deletions src/ArmTemplates/Common/FileHandlers/FileNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class FileNames

public string IdentityProviders { get; set; }

public string ApiManagementService { get; set; }

public string Parameters { get; set; }

// linked property outputs 1 master template
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
{
public class AdditionalLocation
{
public string DisableGateway { get; set; }

public string GatewayRegionalUrl { get; set; }

public string Location { get; set; }

public string PlatformVersion { get; set; }

public string[] PrivateIPAddresses { get; set; }

public string[] PublicIPAddresses { get; set; }

public string PublicIpAddressId { get; set; }

public ApiManagementServiceSkuProperties Sku { get; set; }

public VirtualNetworkConfiguration VirtualNetworkConfiguration { get; set; }

public string[] Zones { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

using System.Collections.Generic;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
{
public class ApiManagementServiceIdentity
{
public string PrincipalId { get; set; }

public string TenantId { get; set; }

public string Type { get; set; }

public IDictionary<string, UserIdentityProperties> UserAssignedIdentities { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

using System.Collections.Generic;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
{
public class ApiManagementServiceProperties
{
public AdditionalLocation[] AdditionalLocations { get; set; }

public ApiVersionConstraint ApiVersionConstraint { get; set; }

public CertificateConfiguration[] Certificates { get; set; }

public IDictionary<string, string> CustomProperties { get; set; }

public bool DisableGateway { get; set; }

public bool? EnableClientCertificate { get; set; }

public string NotificationSenderEmail { get; set; }

public string PlatformVersion { get; set; }

public RemotePrivateEndpointConnectionWrapper[] PrivateEndpointConnections { get; set; }

public string[] PrivateIPAddresses { get; set; }

public string ProvisioningState { get; set; }

public string PublicIpAddressId { get; set; }

public string PublicNetworkAccess { get; set; }

public string PublisherEmail { get; set; }

public string PublisherName { get; set; }

public bool Restore { get; set; }

public string TargetProvisioningState { get; set; }

public VirtualNetworkConfiguration VirtualNetworkConfiguration { get; set; }

public string VirtualNetworkType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

using System.Collections.Generic;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions;
using Newtonsoft.Json;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
{
public class ApiManagementServiceResource : TemplateResource
{
[JsonIgnore]
public string OriginalName { get; set; }

public ApiManagementServiceIdentity Identity { get; set; }

public string Location { get; set; }

public IDictionary<string, string> Tags { get; set; }

public string[] Zones { get; set; }

public ApiManagementServiceSkuProperties Sku { get; set; }

public ApiManagementServiceProperties Properties { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

using System.Collections.Generic;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions;

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
{
public class ApiManagementServiceResources: ITemplateResources
{
public List<ApiManagementServiceResource> ApiManagementServices{ get; set; } = new();

public TemplateResource[] BuildTemplateResources()
{
return this.ApiManagementServices.ToArray();
}

public bool HasContent()
{
return !this.ApiManagementServices.IsNullOrEmpty();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
{
public class ApiManagementServiceSkuProperties
{
public int Capacity { get; set; }

public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
{
public class ApiVersionConstraint
{
public string MinApiVersion { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------

namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
{
public class ArmIdWrapper
{
public string Id { get; set; }
}
}

0 comments on commit bb99a62

Please sign in to comment.