This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/extract/policy fragments (#775)
* Add policy-fragments extraction * Add policy fragment tests, update main template tests Co-authored-by: Farhad Alizada <[email protected]>
- Loading branch information
Showing
26 changed files
with
547 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/ArmTemplates/Common/API/Clients/Abstractions/IPolicyFragmentsClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// -------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// -------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.PolicyFragments; | ||
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models; | ||
|
||
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions | ||
{ | ||
public interface IPolicyFragmentsClient | ||
{ | ||
Task<List<PolicyFragmentsResource>> GetAllAsync(ExtractorParameters extractorParameters); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/ArmTemplates/Common/API/Clients/PolicyFragments/PolicyFragmentsClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// -------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// -------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
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.PolicyFragments; | ||
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.PolicyFragments | ||
{ | ||
public class PolicyFragmentsClient : ApiClientBase, IPolicyFragmentsClient | ||
{ | ||
const string GetAllRequest = "{0}/subscriptions/{1}/resourceGroups/{2}/providers/Microsoft.ApiManagement/service/{3}/policyFragments?api-version={4}&format=rawxml"; | ||
|
||
readonly IPolicyFragmentDataProcessor policyFragmentDataProcessor; | ||
|
||
public PolicyFragmentsClient( | ||
IHttpClientFactory httpClientFactory, | ||
IPolicyFragmentDataProcessor policyFragmentDataProcessor): base(httpClientFactory) | ||
{ | ||
this.policyFragmentDataProcessor = policyFragmentDataProcessor; | ||
} | ||
|
||
public async Task<List<PolicyFragmentsResource>> GetAllAsync(ExtractorParameters extractorParameters) | ||
{ | ||
var (azToken, azSubId) = await this.Auth.GetAccessToken(); | ||
|
||
var requestUrl = string.Format(GetAllRequest, | ||
this.BaseUrl, azSubId, extractorParameters.ResourceGroup, extractorParameters.SourceApimName, GlobalConstants.ApiVersionPreview); | ||
|
||
var policyFragments = await this.GetPagedResponseAsync<PolicyFragmentsResource>(azToken, requestUrl); | ||
this.policyFragmentDataProcessor.ProcessData(policyFragments, extractorParameters); | ||
|
||
return policyFragments; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/ArmTemplates/Common/Templates/PolicyFragments/PolicyFragmentsProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
// -------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.PolicyFragments | ||
{ | ||
public class PolicyFragmentsProperties | ||
{ | ||
public string Description { get; set; } | ||
|
||
public string Format { get; set; } | ||
|
||
public string Value { get; set; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/ArmTemplates/Common/Templates/PolicyFragments/PolicyFragmentsResource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// -------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// -------------------------------------------------------------------------- | ||
|
||
using Newtonsoft.Json; | ||
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions; | ||
|
||
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.PolicyFragments | ||
{ | ||
public class PolicyFragmentsResource : TemplateResource | ||
{ | ||
[JsonIgnore] | ||
public string OriginalName { get; set; } | ||
|
||
public PolicyFragmentsProperties Properties { get; set; } | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/ArmTemplates/Common/Templates/PolicyFragments/PolicyFragmentsResources.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.PolicyFragments | ||
{ | ||
public class PolicyFragmentsResources : ITemplateResources | ||
{ | ||
public List<PolicyFragmentsResource> PolicyFragments { get; set; } = new(); | ||
|
||
public TemplateResource[] BuildTemplateResources() | ||
{ | ||
return this.PolicyFragments.ToArray(); | ||
} | ||
|
||
public bool HasContent() | ||
{ | ||
return !this.PolicyFragments.IsNullOrEmpty(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/ArmTemplates/Extractor/EntityExtractors/Abstractions/IPolicyFragmentsExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// -------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// -------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions; | ||
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Policy; | ||
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.PolicyFragments; | ||
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models; | ||
|
||
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.EntityExtractors.Abstractions | ||
{ | ||
public interface IPolicyFragmentsExtractor | ||
{ | ||
Task<Template<PolicyFragmentsResources>> GeneratePolicyFragmentsTemplateAsync(List<PolicyTemplateResource> apiTemplatePolicies, ExtractorParameters extractorParameters); | ||
} | ||
} |
Oops, something went wrong.