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

Commit bb99a62

Browse files
f-alizadaFarhad Alizada
andauthored
Extract ApiManagement service (#760)
* 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>
1 parent c2a2cee commit bb99a62

35 files changed

+813
-15
lines changed

docs/SupportedResources/2021-08-01.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Some of operations could be skipped (not needed for extraction), because they ar
1212
| API Issue Attachment || | |
1313
| API Issue Comment || | |
1414
| API Management Operations | - | | |
15-
| API Management Service | | | we can load service description |
15+
| API Management Service | | [main](https://github.com/Azure/azure-api-management-devops-resource-kit) | we can load service description |
1616
| API Management Service Skus | - | | |
1717
| Api Operation || [1.0.0-beta.2](https://github.com/Azure/azure-api-management-devops-resource-kit/releases/tag/1.0.0-beta.2) | |
1818
| 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) | |
@@ -40,7 +40,7 @@ Some of operations could be skipped (not needed for extraction), because they ar
4040
| Gateway Hostname Configuration || | |
4141
| Group || [1.0.0-beta.2](https://github.com/Azure/azure-api-management-devops-resource-kit/releases/tag/1.0.0-beta.2) | |
4242
| Group User || | |
43-
| Identity Provider | | | |
43+
| Identity Provider | | [1.0.0-beta.7](https://github.com/Azure/azure-api-management-devops-resource-kit/releases/tag/1.0.0-beta.7) | |
4444
| Issue || | |
4545
| Logger || [1.0.0-beta.2](https://github.com/Azure/azure-api-management-devops-resource-kit/releases/tag/1.0.0-beta.2) | |
4646
| Network Status || | |

src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions;
1111
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.FileHandlers;
1212
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions;
13+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService;
1314
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Apis;
1415
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiVersionSet;
1516
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.AuthorizationServer;
@@ -62,6 +63,7 @@ public class ExtractorExecutor
6263
readonly IGatewayExtractor gatewayExtractor;
6364
readonly IGatewayApiExtractor gatewayApiExtractor;
6465
readonly IIdentityProviderExtractor identityProviderExtractor;
66+
readonly IApiManagementServiceExtractor apiManagementServiceExtractor;
6567

6668
public ExtractorExecutor(
6769
ILogger<ExtractorExecutor> logger,
@@ -83,7 +85,8 @@ public ExtractorExecutor(
8385
IApiRevisionExtractor apiRevisionExtractor,
8486
IGatewayExtractor gatewayExtractor,
8587
IGatewayApiExtractor gatewayApiExtractor,
86-
IIdentityProviderExtractor identityProviderExtractor)
88+
IIdentityProviderExtractor identityProviderExtractor,
89+
IApiManagementServiceExtractor apiManagementServiceExtractor)
8790
{
8891
this.logger = logger;
8992
this.apisClient = apisClient;
@@ -105,6 +108,7 @@ public ExtractorExecutor(
105108
this.gatewayExtractor = gatewayExtractor;
106109
this.gatewayApiExtractor = gatewayApiExtractor;
107110
this.identityProviderExtractor = identityProviderExtractor;
111+
this.apiManagementServiceExtractor = apiManagementServiceExtractor;
108112
}
109113

110114
/// <summary>
@@ -131,7 +135,8 @@ public static ExtractorExecutor BuildExtractorExecutor(
131135
IApiRevisionExtractor apiRevisionExtractor = null,
132136
IGatewayExtractor gatewayExtractor = null,
133137
IGatewayApiExtractor gatewayApiExtractor = null,
134-
IIdentityProviderExtractor identityProviderExtractor = null)
138+
IIdentityProviderExtractor identityProviderExtractor = null,
139+
IApiManagementServiceExtractor apiManagementServiceExtractor = null)
135140
=> new ExtractorExecutor(
136141
logger,
137142
apisClient,
@@ -152,7 +157,8 @@ public static ExtractorExecutor BuildExtractorExecutor(
152157
apiRevisionExtractor,
153158
gatewayExtractor,
154159
gatewayApiExtractor,
155-
identityProviderExtractor);
160+
identityProviderExtractor,
161+
apiManagementServiceExtractor);
156162

157163
public void SetExtractorParameters(ExtractorParameters extractorParameters)
158164
{
@@ -728,6 +734,23 @@ await FileWriter.SaveAsJsonAsync(
728734
return gatewayApiTemplate;
729735
}
730736

737+
public async Task<Template<ApiManagementServiceResources>> GenerateApiManagementServiceTemplate(string baseFilesGenerationDirectory)
738+
{
739+
this.logger.LogInformation("Started generation of ApiManagement service template...");
740+
var apiManagementServiceTemplate = await this.apiManagementServiceExtractor.GenerateApiManagementServicesTemplateAsync(this.extractorParameters);
741+
742+
if (apiManagementServiceTemplate?.HasResources() == true)
743+
{
744+
await FileWriter.SaveAsJsonAsync(
745+
apiManagementServiceTemplate,
746+
directory: baseFilesGenerationDirectory,
747+
fileName: this.extractorParameters.FileNames.ApiManagementService);
748+
}
749+
750+
this.logger.LogInformation("Finished generation of identity providers template...");
751+
return apiManagementServiceTemplate;
752+
}
753+
731754
/// <summary>
732755
/// Generates split api templates / folders for each api in this sourceApim
733756
/// </summary>
@@ -910,6 +933,7 @@ async Task GenerateTemplates(
910933
var identityProviderTemplate = await this.GenerateIdentityProviderTemplateAsync(baseFilesGenerationDirectory);
911934
await this.GenerateGatewayTemplateAsync(singleApiName, baseFilesGenerationDirectory);
912935
await this.GenerateGatewayApiTemplateAsync(singleApiName, multipleApiNames, baseFilesGenerationDirectory);
936+
await this.GenerateApiManagementServiceTemplate(baseFilesGenerationDirectory);
913937
await this.GenerateParametersTemplateAsync(apisToExtract, loggerTemplate.TypedResources, backendTemplate.TypedResources, namedValueTemplate.TypedResources, identityProviderTemplate.TypedResources, baseFilesGenerationDirectory);
914938

915939
await this.GenerateMasterTemplateAsync(
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
using System.Threading.Tasks;
7+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService;
8+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
9+
10+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions
11+
{
12+
public interface IApiManagementServiceClient
13+
{
14+
Task<ApiManagementServiceResource> GetApiManagementServiceAsync(ExtractorParameters extractorParameters);
15+
}
16+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
using System.Net.Http;
7+
using System.Threading.Tasks;
8+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
9+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
10+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService;
11+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
12+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Utilities.DataProcessors.Absctraction;
13+
14+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.ApiManagementService
15+
{
16+
public class ApiManagementServiceClient: ApiClientBase, IApiManagementServiceClient
17+
{
18+
const string GetApiManagementServiceByName = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}?api-version={4}";
19+
20+
readonly IApiManagementServiceProcessor apiManagementServiceProcessor;
21+
22+
public ApiManagementServiceClient(
23+
IHttpClientFactory httpClientFactory,
24+
IApiManagementServiceProcessor apiManagementServiceProcessor): base(httpClientFactory)
25+
{
26+
this.apiManagementServiceProcessor = apiManagementServiceProcessor;
27+
}
28+
29+
public async Task<ApiManagementServiceResource> GetApiManagementServiceAsync(ExtractorParameters extractorParameters)
30+
{
31+
var (azToken, azSubId) = await this.Auth.GetAccessToken();
32+
33+
string requestUrl = string.Format(GetApiManagementServiceByName,
34+
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersion);
35+
36+
var apiManagementServiceResource = await this.GetResponseAsync<ApiManagementServiceResource>(azToken, requestUrl);
37+
this.apiManagementServiceProcessor.ProcessSingleInstanceData(apiManagementServiceResource, extractorParameters);
38+
39+
return apiManagementServiceResource;
40+
}
41+
}
42+
}

src/ArmTemplates/Common/Constants/ResourceTypeConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ public static class ResourceTypeConstants
3535
public const string GatewayApi = "Microsoft.ApiManagement/service/gateways/apis";
3636
public const string ArmDeployments = "Microsoft.Resources/deployments";
3737
public const string IdentityProviders = "Microsoft.ApiManagement/service/identityProviders";
38+
public const string ApiManagementService = "Microsoft.ApiManagement/service";
3839
}
3940
}

src/ArmTemplates/Common/Extensions/JsonExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions
1010
{
11-
static class JsonExtensions
11+
public static class JsonExtensions
1212
{
1313
static readonly JsonSerializerSettings DefaultJsonSerializationSettings = new JsonSerializerSettings
1414
{

src/ArmTemplates/Common/FileHandlers/FileNameGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static FileNames GenerateFileNames(string baseFileName)
3535
Gateway = $@"{baseFileName}gateways.template.json",
3636
GatewayApi = $@"{baseFileName}gateways-apis.template.json",
3737
IdentityProviders = $@"{baseFileName}identity-providers.template.json",
38+
ApiManagementService = $@"{baseFileName}api-management-service.template.json",
3839
TagApi = $@"{baseFileName}apiTags.template.json",
3940
Parameters = $@"{baseFileName}parameters.json",
4041
LinkedMaster = $@"{baseFileName}master.template.json",

src/ArmTemplates/Common/FileHandlers/FileNames.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class FileNames
3535

3636
public string IdentityProviders { get; set; }
3737

38+
public string ApiManagementService { get; set; }
39+
3840
public string Parameters { get; set; }
3941

4042
// linked property outputs 1 master template
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
7+
{
8+
public class AdditionalLocation
9+
{
10+
public string DisableGateway { get; set; }
11+
12+
public string GatewayRegionalUrl { get; set; }
13+
14+
public string Location { get; set; }
15+
16+
public string PlatformVersion { get; set; }
17+
18+
public string[] PrivateIPAddresses { get; set; }
19+
20+
public string[] PublicIPAddresses { get; set; }
21+
22+
public string PublicIpAddressId { get; set; }
23+
24+
public ApiManagementServiceSkuProperties Sku { get; set; }
25+
26+
public VirtualNetworkConfiguration VirtualNetworkConfiguration { get; set; }
27+
28+
public string[] Zones { get; set; }
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
using System.Collections.Generic;
7+
8+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
9+
{
10+
public class ApiManagementServiceIdentity
11+
{
12+
public string PrincipalId { get; set; }
13+
14+
public string TenantId { get; set; }
15+
16+
public string Type { get; set; }
17+
18+
public IDictionary<string, UserIdentityProperties> UserAssignedIdentities { get; set; }
19+
}
20+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
using System.Collections.Generic;
7+
8+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
9+
{
10+
public class ApiManagementServiceProperties
11+
{
12+
public AdditionalLocation[] AdditionalLocations { get; set; }
13+
14+
public ApiVersionConstraint ApiVersionConstraint { get; set; }
15+
16+
public CertificateConfiguration[] Certificates { get; set; }
17+
18+
public IDictionary<string, string> CustomProperties { get; set; }
19+
20+
public bool DisableGateway { get; set; }
21+
22+
public bool? EnableClientCertificate { get; set; }
23+
24+
public string NotificationSenderEmail { get; set; }
25+
26+
public string PlatformVersion { get; set; }
27+
28+
public RemotePrivateEndpointConnectionWrapper[] PrivateEndpointConnections { get; set; }
29+
30+
public string[] PrivateIPAddresses { get; set; }
31+
32+
public string ProvisioningState { get; set; }
33+
34+
public string PublicIpAddressId { get; set; }
35+
36+
public string PublicNetworkAccess { get; set; }
37+
38+
public string PublisherEmail { get; set; }
39+
40+
public string PublisherName { get; set; }
41+
42+
public bool Restore { get; set; }
43+
44+
public string TargetProvisioningState { get; set; }
45+
46+
public VirtualNetworkConfiguration VirtualNetworkConfiguration { get; set; }
47+
48+
public string VirtualNetworkType { get; set; }
49+
}
50+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
using System.Collections.Generic;
7+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions;
8+
using Newtonsoft.Json;
9+
10+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
11+
{
12+
public class ApiManagementServiceResource : TemplateResource
13+
{
14+
[JsonIgnore]
15+
public string OriginalName { get; set; }
16+
17+
public ApiManagementServiceIdentity Identity { get; set; }
18+
19+
public string Location { get; set; }
20+
21+
public IDictionary<string, string> Tags { get; set; }
22+
23+
public string[] Zones { get; set; }
24+
25+
public ApiManagementServiceSkuProperties Sku { get; set; }
26+
27+
public ApiManagementServiceProperties Properties { get; set; }
28+
}
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
using System.Collections.Generic;
7+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions;
8+
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions;
9+
10+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
11+
{
12+
public class ApiManagementServiceResources: ITemplateResources
13+
{
14+
public List<ApiManagementServiceResource> ApiManagementServices{ get; set; } = new();
15+
16+
public TemplateResource[] BuildTemplateResources()
17+
{
18+
return this.ApiManagementServices.ToArray();
19+
}
20+
21+
public bool HasContent()
22+
{
23+
return !this.ApiManagementServices.IsNullOrEmpty();
24+
}
25+
}
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
7+
{
8+
public class ApiManagementServiceSkuProperties
9+
{
10+
public int Capacity { get; set; }
11+
12+
public string Name { get; set; }
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
7+
{
8+
public class ApiVersionConstraint
9+
{
10+
public string MinApiVersion { get; set; }
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// --------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------
5+
6+
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.ApiManagementService
7+
{
8+
public class ArmIdWrapper
9+
{
10+
public string Id { get; set; }
11+
}
12+
}

0 commit comments

Comments
 (0)