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

Commit 525f848

Browse files
committed
add list of products, loggers, apis to creator config, map yaml successfully
1 parent 07caa44 commit 525f848

File tree

12 files changed

+158
-194
lines changed

12 files changed

+158
-194
lines changed

src/APIM_ARMTemplate/apimtemplate/Commands/Create.cs

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,37 +41,48 @@ public CreateCommand()
4141

4242
// create templates from provided configuration
4343
Template apiVersionSetTemplate = creatorConfig.apiVersionSet != null ? apiVersionSetTemplateCreator.CreateAPIVersionSetTemplate(creatorConfig) : null;
44-
Template initialAPITemplate = await apiTemplateCreator.CreateInitialAPITemplateAsync(creatorConfig);
45-
Template subsequentAPITemplate = apiTemplateCreator.CreateSubsequentAPITemplate(creatorConfig);
46-
CreatorFileNames creatorFileNames = fileWriter.GenerateCreatorLinkedFileNames(creatorConfig);
44+
List<Template> initialAPITemplates = new List<Template>();
45+
List<Template> subsequentAPITemplates = new List<Template>();
46+
List<LinkedMasterTemplateAPIInformation> apiInformation = new List<LinkedMasterTemplateAPIInformation>();
47+
48+
foreach (APIConfig api in creatorConfig.apis)
49+
{
50+
Template initialAPITemplate = await apiTemplateCreator.CreateInitialAPITemplateAsync(creatorConfig, api);
51+
Template subsequentAPITemplate = apiTemplateCreator.CreateSubsequentAPITemplate(api);
52+
initialAPITemplates.Add(initialAPITemplate);
53+
subsequentAPITemplates.Add(subsequentAPITemplate);
54+
apiInformation.Add(new LinkedMasterTemplateAPIInformation() { name = api.name, hasAPIVersionSetId = api.apiVersionSetId != null });
55+
}
4756

57+
CreatorFileNames creatorFileNames = fileWriter.GenerateCreatorLinkedFileNames(creatorConfig);
4858
if (creatorConfig.linked == true)
4959
{
5060
// create linked master template
51-
Template masterTemplate = masterTemplateCreator.CreateLinkedMasterTemplate(apiVersionSetTemplate, initialAPITemplate, subsequentAPITemplate, creatorFileNames);
52-
Template masterTemplateParameters = masterTemplateCreator.CreateMasterTemplateParameterValues(creatorConfig);
53-
54-
// write templates to outputLocation
55-
if (apiVersionSetTemplate != null)
56-
{
57-
fileWriter.WriteJSONToFile(apiVersionSetTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.apiVersionSet));
58-
}
59-
fileWriter.WriteJSONToFile(initialAPITemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.initialAPI));
60-
fileWriter.WriteJSONToFile(subsequentAPITemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.subsequentAPI));
61+
Template masterTemplate = masterTemplateCreator.CreateLinkedMasterTemplate(apiVersionSetTemplate, apiInformation, creatorFileNames);
62+
// write linked specific template to outputLocationc
6163
fileWriter.WriteJSONToFile(masterTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.linkedMaster));
62-
fileWriter.WriteJSONToFile(masterTemplateParameters, String.Concat(creatorConfig.outputLocation, creatorFileNames.masterParameters));
6364
}
6465
else
6566
{
66-
// create unlinked master template
67-
Template initialMasterTemplate = masterTemplateCreator.CreateInitialUnlinkedMasterTemplate(apiVersionSetTemplate, initialAPITemplate);
68-
Template subsequentMasterTemplate = masterTemplateCreator.CreateSubsequentUnlinkedMasterTemplate(subsequentAPITemplate);
69-
Template masterTemplateParameters = masterTemplateCreator.CreateMasterTemplateParameterValues(creatorConfig);
67+
// write unlinked specific templates to outputLocationc
68+
foreach (Template initialAPITemplate in initialAPITemplates)
69+
{
70+
fileWriter.WriteJSONToFile(initialAPITemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.initialAPI));
71+
}
72+
foreach (Template subsequentAPITemplate in subsequentAPITemplates)
73+
{
74+
fileWriter.WriteJSONToFile(subsequentAPITemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.subsequentAPI));
75+
}
7076

71-
// write templates to outputLocation
72-
fileWriter.WriteJSONToFile(initialMasterTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.unlinkedMasterOne));
73-
fileWriter.WriteJSONToFile(subsequentMasterTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.unlinkedMasterTwo));
74-
fileWriter.WriteJSONToFile(masterTemplateParameters, String.Concat(creatorConfig.outputLocation, creatorFileNames.masterParameters));
77+
}
78+
// write parameters to outputLocation
79+
Template masterTemplateParameters = masterTemplateCreator.CreateMasterTemplateParameterValues(creatorConfig);
80+
fileWriter.WriteJSONToFile(masterTemplateParameters, String.Concat(creatorConfig.outputLocation, creatorFileNames.masterParameters));
81+
82+
// write common templates to outputLocationc
83+
if (apiVersionSetTemplate != null)
84+
{
85+
fileWriter.WriteJSONToFile(apiVersionSetTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.apiVersionSet));
7586
}
7687
ColoredConsole.WriteLine("Templates written to output location");
7788
}
@@ -98,26 +109,6 @@ public bool ValidateCreatorConfig(CreatorConfig creatorConfig)
98109
isValid = false;
99110
throw new CommandParsingException(this, "APIM service name is required");
100111
}
101-
if (creatorConfig.api == null)
102-
{
103-
isValid = false;
104-
throw new CommandParsingException(this, "API configuration is required");
105-
}
106-
if (creatorConfig.api.openApiSpec == null)
107-
{
108-
isValid = false;
109-
throw new CommandParsingException(this, "Open API Spec is required");
110-
}
111-
if (creatorConfig.api.suffix == null)
112-
{
113-
isValid = false;
114-
throw new CommandParsingException(this, "API suffix is required");
115-
}
116-
if (creatorConfig.api.name == null)
117-
{
118-
isValid = false;
119-
throw new CommandParsingException(this, "API name is required");
120-
}
121112
if (creatorConfig.linked == true && creatorConfig.linkedTemplatesBaseUrl == null)
122113
{
123114
isValid = false;
@@ -133,21 +124,44 @@ public bool ValidateCreatorConfig(CreatorConfig creatorConfig)
133124
isValid = false;
134125
throw new CommandParsingException(this, "Versioning scheme is required if an API Version Set is provided");
135126
}
136-
if (creatorConfig.api.operations != null)
127+
foreach (APIConfig api in creatorConfig.apis)
137128
{
138-
foreach (KeyValuePair<string, OperationsConfig> operation in creatorConfig.api.operations)
129+
if (api == null)
139130
{
140-
if (operation.Value == null || operation.Value.policy == null)
131+
isValid = false;
132+
throw new CommandParsingException(this, "API configuration is required");
133+
}
134+
if (api.openApiSpec == null)
135+
{
136+
isValid = false;
137+
throw new CommandParsingException(this, "Open API Spec is required");
138+
}
139+
if (api.suffix == null)
140+
{
141+
isValid = false;
142+
throw new CommandParsingException(this, "API suffix is required");
143+
}
144+
if (api.name == null)
145+
{
146+
isValid = false;
147+
throw new CommandParsingException(this, "API name is required");
148+
}
149+
if (api.operations != null)
150+
{
151+
foreach (KeyValuePair<string, OperationsConfig> operation in api.operations)
141152
{
142-
isValid = false;
143-
throw new CommandParsingException(this, "Policy XML is required if an API operation is provided");
153+
if (operation.Value == null || operation.Value.policy == null)
154+
{
155+
isValid = false;
156+
throw new CommandParsingException(this, "Policy XML is required if an API operation is provided");
157+
}
144158
}
145159
}
146-
}
147-
if (creatorConfig.api.diagnostic != null && creatorConfig.api.diagnostic.loggerId == null)
148-
{
149-
isValid = false;
150-
throw new CommandParsingException(this, "LoggerId is required if an API diagnostic is provided");
160+
if (api.diagnostic != null && api.diagnostic.loggerId == null)
161+
{
162+
isValid = false;
163+
throw new CommandParsingException(this, "LoggerId is required if an API diagnostic is provided");
164+
}
151165
}
152166
return isValid;
153167
}

src/APIM_ARMTemplate/apimtemplate/Commands/Extract.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,14 @@ private void GenerateProductsARMTemplate(string apimname, string resourceGroup,
347347
MissingMemberHandling = MissingMemberHandling.Ignore
348348
};
349349

350-
ProductsDetailsTemplateResource productsDetailsResource = JsonConvert.DeserializeObject<ProductsDetailsTemplateResource>(productDetails, settings);
351-
productsDetailsResource.name = $"[concat(parameters('ApimServiceName'), '/{productName}')]";
352-
productsDetailsResource.apiVersion = "2018-06-01-preview";
350+
ProductsTemplateResource productsTemplateResource = JsonConvert.DeserializeObject<ProductsTemplateResource>(productDetails, settings);
351+
productsTemplateResource.name = $"[concat(parameters('ApimServiceName'), '/{productName}')]";
352+
productsTemplateResource.apiVersion = "2018-06-01-preview";
353353

354354
// only extract the product if this is a full extraction, or in the case of a single api, if it is found in products associated with the api
355355
if (singleApiName == null || productAPIResources.SingleOrDefault(p => p.name.Contains(productName)) != null)
356356
{
357-
templateResources.Add(productsDetailsResource);
357+
templateResources.Add(productsTemplateResource);
358358
}
359359
}
360360

@@ -492,7 +492,7 @@ private async void GenerateNamedValuesTemplate(string resourceGroup, string apim
492492
}
493493
else
494494
{
495-
// if the user is executing a single api, extract all the named values used in the template resources
495+
// TODO - if the user is executing a single api, extract all the named values used in the template resources
496496
Console.WriteLine("'{0}' Named value found", propertyName);
497497
templateResources.Add(propertyTemplateResource);
498498
};

src/APIM_ARMTemplate/apimtemplate/Common/FileHandlers/FileWriter.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,12 @@ public void WriteJSONToFile(object template, string location)
2020

2121
public CreatorFileNames GenerateCreatorLinkedFileNames(CreatorConfig creatorConfig)
2222
{
23-
string apiName = creatorConfig.api.name;
24-
string versionSetName = creatorConfig.apiVersionSet.displayName;
2523
// generate useable object with file names for consistency throughout project
2624
return new CreatorFileNames()
2725
{
28-
apiVersionSet = $@"/{versionSetName}.template.json",
29-
initialAPI = $@"/{apiName}-initial.api.template.json",
30-
subsequentAPI = $@"/{apiName}-subsequent.api.template.json",
31-
linkedMaster = $@"/{apiName}.master.template.json",
32-
unlinkedMasterOne = $@"/{apiName}.master1.template.json",
33-
unlinkedMasterTwo = $@"/{apiName}.master2.template.json",
34-
masterParameters = $@"/{apiName}.master.parameters.json",
26+
apiVersionSet = @"/version-sets.template.json",
27+
linkedMaster = @"/master.template.json",
28+
masterParameters = @"/master.parameters.json",
3529
};
3630
}
3731
}

src/APIM_ARMTemplate/apimtemplate/Common/TemplateModels/LoggerTemplateResource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common
33
{
44
public class LoggerTemplateResource : TemplateResource
55
{
6-
public LoggerResourceProperties properties { get; set; }
6+
public LoggerTemplateProperties properties { get; set; }
77
}
88

9-
public class LoggerResourceProperties
9+
public class LoggerTemplateProperties
1010
{
1111
public string loggerType { get; set; }
1212
public string description { get; set; }
Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
using System.Collections.Generic;
22
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common
33
{
4-
public class ProductsProperties
4+
public class ProductsTemplateResource : TemplateResource
5+
{
6+
public ProductsTemplateProperties properties { get; set; }
7+
}
8+
9+
public class ProductsTemplateProperties
510
{
611
public string displayName { get; set; }
712
public string description { get; set; }
@@ -11,22 +16,4 @@ public class ProductsProperties
1116
public int subscriptionsLimit { get; set; }
1217
public string state { get; set; }
1318
}
14-
15-
public class Value
16-
{
17-
public string id { get; set; }
18-
public string type { get; set; }
19-
public string name { get; set; }
20-
public ProductsProperties properties { get; set; }
21-
}
22-
23-
public class ProductsTemplateResource
24-
{
25-
public List<Value> value { get; set; }
26-
}
27-
28-
public class ProductsDetailsTemplateResource : TemplateResource
29-
{
30-
public ProductsProperties properties { get; set; }
31-
}
3219
}

src/APIM_ARMTemplate/apimtemplate/Creator/Models/CreatorConfiguration.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public class CreatorConfig
1313
public string version { get; set; }
1414
public string apimServiceName { get; set; }
1515
public APIVersionSetConfig apiVersionSet { get; set; }
16-
public APIConfig api { get; set; }
16+
public List<APIConfig> apis { get; set; }
17+
public List<ProductsTemplateProperties> products { get; set; }
18+
public List<LoggerConfig> loggers { get; set; }
1719
public string outputLocation { get; set; }
1820
public bool linked { get; set; }
1921
public string linkedTemplatesBaseUrl { get; set; }
@@ -50,7 +52,12 @@ public class OperationsConfig
5052
public string policy { get; set; }
5153
}
5254

53-
public class DiagnosticConfig: DiagnosticTemplateProperties
55+
public class DiagnosticConfig : DiagnosticTemplateProperties
56+
{
57+
public string name { get; set; }
58+
}
59+
60+
public class LoggerConfig : LoggerTemplateProperties
5461
{
5562
public string name { get; set; }
5663
}

0 commit comments

Comments
 (0)