2
2
using System . Collections . Generic ;
3
3
using Newtonsoft . Json . Linq ;
4
4
using System . Linq ;
5
- using Newtonsoft . Json ;
6
5
using System ;
7
6
using Microsoft . Azure . Management . ApiManagement . ArmTemplates . Common . TemplateModels ;
8
7
using Microsoft . Azure . Management . ApiManagement . ArmTemplates . Common . Templates . Policy ;
@@ -18,10 +17,14 @@ namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Entity
18
17
public class BackendExtractor : EntityExtractorBase , IBackendExtractor
19
18
{
20
19
readonly ITemplateBuilder templateBuilder ;
20
+ readonly IPolicyExtractor policyExtractor ;
21
21
22
- public BackendExtractor ( ITemplateBuilder templateBuilder )
22
+ public BackendExtractor (
23
+ ITemplateBuilder templateBuilder ,
24
+ IPolicyExtractor policyExtractor )
23
25
{
24
26
this . templateBuilder = templateBuilder ;
27
+ this . policyExtractor = policyExtractor ;
25
28
}
26
29
27
30
public async Task < string > GetBackendsAsync ( string apiManagementName , string resourceGroupName , int skipNumOfRecords )
@@ -47,16 +50,13 @@ public async Task<string> GetBackendDetailsAsync(string apiManagementName, strin
47
50
/// <summary>
48
51
/// Generate the ARM assets for the backend resources
49
52
/// </summary>
50
- /// <param name="apimname"></param>
51
- /// <param name="resourceGroup"></param>
52
- /// <param name="singleApiName"></param>
53
- /// <param name="apiTemplateResources"></param>
54
- /// <param name="propertyResources"></param>
55
- /// <param name="policyXMLBaseUrl"></param>
56
- /// <param name="policyXMLSasToken"></param>
57
- /// <param name="extractBackendParameters"></param>
58
53
/// <returns>a combination of a Template and the value for the BackendSettings parameter</returns>
59
- public async Task < Tuple < Template , Dictionary < string , BackendApiParameters > > > GenerateBackendsARMTemplateAsync ( string apimname , string resourceGroup , string singleApiName , List < TemplateResource > apiTemplateResources , List < TemplateResource > propertyResources , ExtractorParameters extractorParameters )
54
+ public async Task < Tuple < Template , Dictionary < string , BackendApiParameters > > > GenerateBackendsARMTemplateAsync (
55
+ string singleApiName ,
56
+ List < PolicyTemplateResource > policyTemplateResources ,
57
+ List < TemplateResource > propertyResources ,
58
+ ExtractorParameters extractorParameters ,
59
+ string baseFilesGenerationDirectory )
60
60
{
61
61
Console . WriteLine ( "------------------------------------------" ) ;
62
62
Console . WriteLine ( "Extracting backends from service" ) ;
@@ -74,7 +74,6 @@ public async Task<Tuple<Template, Dictionary<string, BackendApiParameters>>> Gen
74
74
List < TemplateResource > templateResources = new List < TemplateResource > ( ) ;
75
75
76
76
// isolate api and operation policy resources in the case of a single api extraction, as they may reference backends
77
- var policyResources = apiTemplateResources . Where ( resource => resource . Type == ResourceTypeConstants . APIPolicy || resource . Type == ResourceTypeConstants . APIOperationPolicy || resource . Type == ResourceTypeConstants . ProductPolicy ) ;
78
77
var namedValueResources = propertyResources . Where ( resource => resource . Type == ResourceTypeConstants . Property ) ;
79
78
80
79
// pull all backends for service
@@ -84,13 +83,20 @@ public async Task<Tuple<Template, Dictionary<string, BackendApiParameters>>> Gen
84
83
85
84
do
86
85
{
87
- string backends = await this . GetBackendsAsync ( apimname , resourceGroup , skipNumberOfBackends ) ;
86
+ string backends = await this . GetBackendsAsync (
87
+ extractorParameters . SourceApimName ,
88
+ extractorParameters . ResourceGroup ,
89
+ skipNumberOfBackends ) ;
90
+
88
91
oBackends = JObject . Parse ( backends ) ;
89
92
90
93
foreach ( var item in oBackends [ "value" ] )
91
94
{
92
95
string backendName = ( ( JValue ) item [ "name" ] ) . Value . ToString ( ) ;
93
- string backend = await this . GetBackendDetailsAsync ( apimname , resourceGroup , backendName ) ;
96
+ string backend = await this . GetBackendDetailsAsync (
97
+ extractorParameters . SourceApimName ,
98
+ extractorParameters . ResourceGroup ,
99
+ backendName ) ;
94
100
95
101
// convert returned backend to template resource class
96
102
BackendTemplateResource backendTemplateResource = backend . Deserialize < BackendTemplateResource > ( ) ;
@@ -107,9 +113,9 @@ public async Task<Tuple<Template, Dictionary<string, BackendApiParameters>>> Gen
107
113
else
108
114
{
109
115
// check extracted policies to see if the backend is referenced.
110
- foreach ( PolicyTemplateResource policyTemplateResource in policyResources )
116
+ foreach ( var policyTemplateResource in policyTemplateResources )
111
117
{
112
- string policyContent = PolicyTemplateUtils . GetPolicyContent ( extractorParameters , policyTemplateResource ) ;
118
+ var policyContent = this . policyExtractor . GetCachedPolicyContent ( policyTemplateResource , baseFilesGenerationDirectory ) ;
113
119
114
120
if ( this . DoesPolicyReferenceBackend ( policyContent , namedValueResources , backendName , backendTemplateResource ) )
115
121
{
@@ -193,7 +199,15 @@ public bool DoesBackendReferenceNamedValue(TemplateResource namedValueResource,
193
199
|| namedValue == backendTemplateResource . Properties . title ;
194
200
}
195
201
196
- public async Task < bool > IsNamedValueUsedInBackends ( string apimname , string resourceGroup , string singleApiName , List < TemplateResource > apiTemplateResources , ExtractorParameters extractorParameters , string propertyName , string propertyDisplayName )
202
+ public async Task < bool > IsNamedValueUsedInBackends (
203
+ string apimname ,
204
+ string resourceGroup ,
205
+ string singleApiName ,
206
+ List < TemplateResource > apiTemplateResources ,
207
+ ExtractorParameters extractorParameters ,
208
+ string propertyName ,
209
+ string propertyDisplayName ,
210
+ string baseFilesGenerationDirectory )
197
211
{
198
212
// isolate api and operation policy resources in the case of a single api extraction, as they may reference backends
199
213
var policyResources = apiTemplateResources . Where ( resource => resource . Type == ResourceTypeConstants . APIPolicy || resource . Type == ResourceTypeConstants . APIOperationPolicy || resource . Type == ResourceTypeConstants . ProductPolicy ) ;
@@ -238,7 +252,7 @@ public async Task<bool> IsNamedValueUsedInBackends(string apimname, string resou
238
252
// this is why an empty named values must be passed to this method for validation
239
253
foreach ( PolicyTemplateResource policyTemplateResource in policyResources )
240
254
{
241
- string policyContent = PolicyTemplateUtils . GetPolicyContent ( extractorParameters , policyTemplateResource ) ;
255
+ var policyContent = this . policyExtractor . GetCachedPolicyContent ( policyTemplateResource , baseFilesGenerationDirectory ) ;
242
256
243
257
if ( this . DoesPolicyReferenceBackend ( policyContent , emptyNamedValueResources , backendName , backendTemplateResource ) )
244
258
{
0 commit comments