|
5 | 5 |
|
6 | 6 | using System.Threading.Tasks;
|
7 | 7 | using System.Collections.Generic;
|
8 |
| -using System.Linq; |
9 |
| -using System; |
10 | 8 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Policy;
|
11 | 9 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Extensions;
|
12 | 10 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
|
13 | 11 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.EntityExtractors.Abstractions;
|
14 | 12 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Abstractions;
|
15 | 13 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
|
16 | 14 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Builders.Abstractions;
|
17 |
| -using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.NamedValues; |
18 | 15 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Backend;
|
19 | 16 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.API.Clients.Abstractions;
|
20 | 17 | using Microsoft.Extensions.Logging;
|
@@ -48,7 +45,6 @@ public BackendExtractor(
|
48 | 45 | public async Task<Template<BackendTemplateResources>> GenerateBackendsTemplateAsync(
|
49 | 46 | string singleApiName,
|
50 | 47 | List<PolicyTemplateResource> apiPolicies,
|
51 |
| - List<NamedValueTemplateResource> namedValues, |
52 | 48 | string baseFilesGenerationDirectory,
|
53 | 49 | ExtractorParameters extractorParameters)
|
54 | 50 | {
|
@@ -87,7 +83,7 @@ public async Task<Template<BackendTemplateResources>> GenerateBackendsTemplateAs
|
87 | 83 | {
|
88 | 84 | var policyContent = this.policyExtractor.GetCachedPolicyContent(policyTemplateResource, baseFilesGenerationDirectory);
|
89 | 85 |
|
90 |
| - if (this.DoesPolicyReferenceBackend(policyContent, namedValues, backendResource.OriginalName, backendResource)) |
| 86 | + if (this.DoesPolicyReferenceBackend(policyContent, backendResource.OriginalName, backendResource)) |
91 | 87 | {
|
92 | 88 | // backend was used in policy, extract it
|
93 | 89 | backendTemplate.TypedResources.Backends.Add(backendResource);
|
@@ -161,33 +157,18 @@ void SaveBackendApiParametersToCache()
|
161 | 157 |
|
162 | 158 | bool DoesPolicyReferenceBackend(
|
163 | 159 | string policyContent,
|
164 |
| - IEnumerable<NamedValueTemplateResource> namedValueResources, |
165 | 160 | string backendName,
|
166 | 161 | BackendTemplateResource backendTemplateResource)
|
167 | 162 | {
|
168 |
| - // a policy is referenced by a backend with the set-backend-service policy, which will reference use the backends name or url, or through referencing a named value that applies to the backend |
169 |
| - var namedValueResourcesUsedByBackend = namedValueResources.Where(resource => this.DoesBackendReferenceNamedValue(resource, backendTemplateResource)); |
170 |
| - |
171 |
| - if (backendName != null && policyContent.Contains(backendName) || |
172 |
| - backendTemplateResource.Properties.Url != null && policyContent.Contains(backendTemplateResource.Properties.Url) || |
173 |
| - backendTemplateResource.Properties.Title != null && policyContent.Contains(backendTemplateResource.Properties.Title) || |
174 |
| - backendTemplateResource.Properties.ResourceId != null && policyContent.Contains(backendTemplateResource.Properties.ResourceId)) |
| 163 | + if (!string.IsNullOrEmpty(backendName) && policyContent.Contains(backendName) || |
| 164 | + !string.IsNullOrEmpty(backendTemplateResource.Properties.Url) && policyContent.Contains(backendTemplateResource.Properties.Url) || |
| 165 | + !string.IsNullOrEmpty(backendTemplateResource.Properties.Title) && policyContent.Contains(backendTemplateResource.Properties.Title) || |
| 166 | + !string.IsNullOrEmpty(backendTemplateResource.Properties.ResourceId) && policyContent.Contains(backendTemplateResource.Properties.ResourceId)) |
175 | 167 | {
|
176 | 168 | return true;
|
177 | 169 | }
|
178 | 170 |
|
179 |
| - return namedValueResourcesUsedByBackend.Any(x => |
180 |
| - (x.Properties.DisplayName is not null && policyContent.Contains(x.Properties.DisplayName)) || |
181 |
| - (x.Properties.Value is not null && policyContent.Contains(x.Properties.Value))); |
182 |
| - } |
183 |
| - |
184 |
| - public bool DoesBackendReferenceNamedValue(NamedValueTemplateResource namedValueResource, BackendTemplateResource backendTemplateResource) |
185 |
| - { |
186 |
| - var namedValue = namedValueResource.Properties.Value; |
187 |
| - |
188 |
| - return namedValue == backendTemplateResource.Properties.Url |
189 |
| - || namedValue == backendTemplateResource.Properties.Description |
190 |
| - || namedValue == backendTemplateResource.Properties.Title; |
| 171 | + return false; |
191 | 172 | }
|
192 | 173 |
|
193 | 174 | public async Task<bool> IsNamedValueUsedInBackends(
|
@@ -233,7 +214,7 @@ public async Task<bool> IsNamedValueUsedInBackends(
|
233 | 214 | foreach (var policyTemplateResource in apiPolicies)
|
234 | 215 | {
|
235 | 216 | var policyContent = this.policyExtractor.GetCachedPolicyContent(policyTemplateResource, baseFilesGenerationDirectory);
|
236 |
| - if (this.DoesPolicyReferenceBackend(policyContent, Array.Empty<NamedValueTemplateResource>(), backendName, backendResource)) |
| 217 | + if (this.DoesPolicyReferenceBackend(policyContent, backendName, backendResource)) |
237 | 218 | {
|
238 | 219 | // don't need to go through all policies and backends if the named values has already been found
|
239 | 220 | return true;
|
|
0 commit comments