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

Commit e98f5ab

Browse files
committed
make file names consistent across creator and extractor
1 parent f587da9 commit e98f5ab

File tree

10 files changed

+68
-145
lines changed

10 files changed

+68
-145
lines changed

src/APIM_ARMTemplate/apimtemplate.test/Creator/TemplateCreatorTests/MasterTemplateCreatorTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ public class MasterTemplateCreatorTests
1111
public void ShouldCreateCorrectNumberOfDeploymentResources()
1212
{
1313
// arrange
14+
CreatorConfig creatorConfig = new CreatorConfig() { apimServiceName = "apimService" };
1415
MasterTemplateCreator masterTemplateCreator = new MasterTemplateCreator();
1516
Template apiVersionSetsTemplate = new Template();
1617
Template productsTemplate = new Template();
1718
Template loggersTemplate = new Template();
1819
List<LinkedMasterTemplateAPIInformation> apiInfoList = new List<LinkedMasterTemplateAPIInformation>() { new LinkedMasterTemplateAPIInformation() { name = "api", isSplit = true } };
1920
FileNameGenerator fileNameGenerator = new FileNameGenerator();
20-
CreatorFileNames creatorFileNames = fileNameGenerator.GenerateCreatorLinkedFileNames();
21+
FileNames creatorFileNames = fileNameGenerator.GenerateFileNames(creatorConfig.apimServiceName);
2122

2223
// should create 5 resources (apiVersionSet, product, logger, both api templates)
2324
int count = 5;
2425

2526
// act
26-
Template masterTemplate = masterTemplateCreator.CreateLinkedMasterTemplate(apiVersionSetsTemplate, productsTemplate, loggersTemplate, null, null, apiInfoList, creatorFileNames, fileNameGenerator);
27+
Template masterTemplate = masterTemplateCreator.CreateLinkedMasterTemplate(apiVersionSetsTemplate, productsTemplate, loggersTemplate, null, null, apiInfoList, creatorFileNames, creatorConfig.apimServiceName, fileNameGenerator);
2728

2829
// assert
2930
Assert.Equal(count, masterTemplate.resources.Length);

src/APIM_ARMTemplate/apimtemplate/Commands/Create.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public CreateCommand()
3535
// initialize file helper classes
3636
FileWriter fileWriter = new FileWriter();
3737
FileNameGenerator fileNameGenerator = new FileNameGenerator();
38-
CreatorFileNames creatorFileNames = fileNameGenerator.GenerateCreatorLinkedFileNames();
38+
FileNames fileNames = fileNameGenerator.GenerateFileNames(creatorConfig.apimServiceName);
3939

4040
// initialize template creator classes
4141
APIVersionSetTemplateCreator apiVersionSetTemplateCreator = new APIVersionSetTemplateCreator();
@@ -96,40 +96,40 @@ public CreateCommand()
9696
if (creatorConfig.linked == true)
9797
{
9898
// create linked master template
99-
Template masterTemplate = masterTemplateCreator.CreateLinkedMasterTemplate(apiVersionSetsTemplate, productsTemplate, loggersTemplate, backendsTemplate, authorizationServersTemplate, apiInformation, creatorFileNames, fileNameGenerator);
100-
fileWriter.WriteJSONToFile(masterTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.linkedMaster));
99+
Template masterTemplate = masterTemplateCreator.CreateLinkedMasterTemplate(apiVersionSetsTemplate, productsTemplate, loggersTemplate, backendsTemplate, authorizationServersTemplate, apiInformation, fileNames, creatorConfig.apimServiceName, fileNameGenerator);
100+
fileWriter.WriteJSONToFile(masterTemplate, String.Concat(creatorConfig.outputLocation, fileNames.linkedMaster));
101101
}
102102
foreach (Template apiTemplate in apiTemplates)
103103
{
104104
APITemplateResource apiResource = apiTemplate.resources.FirstOrDefault(resource => resource.type == ResourceTypeConstants.API) as APITemplateResource;
105105
APIConfig providedAPIConfiguration = creatorConfig.apis.FirstOrDefault(api => apiResource.name.Contains(api.name));
106106
// if the api version is not null the api is split into multiple templates. If the template is split and the content value has been set, then the template is for a subsequent api
107-
string apiFileName = fileNameGenerator.GenerateAPIFileName(providedAPIConfiguration.name, apiTemplateCreator.isSplitAPI(providedAPIConfiguration), apiResource.properties.value == null);
107+
string apiFileName = fileNameGenerator.GenerateCreatorAPIFileName(providedAPIConfiguration.name, apiTemplateCreator.isSplitAPI(providedAPIConfiguration), apiResource.properties.value == null, creatorConfig.apimServiceName);
108108
fileWriter.WriteJSONToFile(apiTemplate, String.Concat(creatorConfig.outputLocation, apiFileName));
109109
}
110110
if (apiVersionSetsTemplate != null)
111111
{
112-
fileWriter.WriteJSONToFile(apiVersionSetsTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.apiVersionSets));
112+
fileWriter.WriteJSONToFile(apiVersionSetsTemplate, String.Concat(creatorConfig.outputLocation, fileNames.apiVersionSets));
113113
}
114114
if (productsTemplate != null)
115115
{
116-
fileWriter.WriteJSONToFile(productsTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.products));
116+
fileWriter.WriteJSONToFile(productsTemplate, String.Concat(creatorConfig.outputLocation, fileNames.products));
117117
}
118118
if (loggersTemplate != null)
119119
{
120-
fileWriter.WriteJSONToFile(loggersTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.loggers));
120+
fileWriter.WriteJSONToFile(loggersTemplate, String.Concat(creatorConfig.outputLocation, fileNames.loggers));
121121
}
122122
if (backendsTemplate != null)
123123
{
124-
fileWriter.WriteJSONToFile(backendsTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.backends));
124+
fileWriter.WriteJSONToFile(backendsTemplate, String.Concat(creatorConfig.outputLocation, fileNames.backends));
125125
}
126126
if (authorizationServersTemplate != null)
127127
{
128-
fileWriter.WriteJSONToFile(authorizationServersTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.authorizationServers));
128+
fileWriter.WriteJSONToFile(authorizationServersTemplate, String.Concat(creatorConfig.outputLocation, fileNames.authorizationServers));
129129
}
130130

131131
// write parameters to outputLocation
132-
fileWriter.WriteJSONToFile(masterTemplateParameters, String.Concat(creatorConfig.outputLocation, creatorConfig.linked == true ? creatorFileNames.linkedParameters : creatorFileNames.unlinkedParameters));
132+
fileWriter.WriteJSONToFile(masterTemplateParameters, String.Concat(creatorConfig.outputLocation, fileNames.parameters));
133133
Console.WriteLine("Templates written to output location");
134134
Console.WriteLine("Press any key to exit process:");
135135
#if DEBUG

src/APIM_ARMTemplate/apimtemplate/Commands/Extract.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ public ExtractCommand()
5050
Console.WriteLine("Executing full extraction ...", singleApiName);
5151
}
5252

53-
// initialize entity extractor classes
53+
// initialize file helper classes
5454
FileWriter fileWriter = new FileWriter();
55+
FileNameGenerator fileNameGenerator = new FileNameGenerator();
56+
FileNames fileNames = fileNameGenerator.GenerateFileNames(apimname);
57+
58+
// initialize entity extractor classes
5559
APIExtractor apiExtractor = new APIExtractor();
5660
APIVersionSetExtractor apiVersionSetExtractor = new APIVersionSetExtractor();
5761
AuthorizationServerExtractor authorizationServerExtractor = new AuthorizationServerExtractor();
@@ -72,14 +76,14 @@ public ExtractCommand()
7276
Template backendTemplate = await backendExtractor.GenerateBackendsARMTemplate(apimname, resourceGroup, singleApiName, apiTemplateResources, namedValueResources);
7377

7478
// write templates to output file location
75-
string apiFileName = singleApiName == null ? @fileFolder + Path.DirectorySeparatorChar + apimname + "-apis-template.json" : @fileFolder + Path.DirectorySeparatorChar + apimname + "-" + singleApiName + "-api-template.json";
76-
fileWriter.WriteJSONToFile(apiTemplate, apiFileName);
77-
fileWriter.WriteJSONToFile(apiVersionSetTemplate, @fileFolder + Path.DirectorySeparatorChar + apimname + "-apiVersionSets.json");
78-
fileWriter.WriteJSONToFile(authorizationTemplate, @fileFolder + Path.DirectorySeparatorChar + apimname + "-authorizationServers.json");
79-
fileWriter.WriteJSONToFile(backendTemplate, @fileFolder + Path.DirectorySeparatorChar + apimname + "-backends.json");
80-
fileWriter.WriteJSONToFile(loggerTemplate, @fileFolder + Path.DirectorySeparatorChar + apimname + "-loggers.json");
81-
fileWriter.WriteJSONToFile(namedValueTemplate, @fileFolder + Path.DirectorySeparatorChar + apimname + "-namedValues.json");
82-
fileWriter.WriteJSONToFile(productTemplate, @fileFolder + Path.DirectorySeparatorChar + apimname + "-products.json");
79+
string apiFileName = fileNameGenerator.GenerateExtractorAPIFileName(singleApiName, apimname);
80+
fileWriter.WriteJSONToFile(apiTemplate, String.Concat(@fileFolder, apiFileName));
81+
fileWriter.WriteJSONToFile(apiVersionSetTemplate, String.Concat(@fileFolder, fileNames.apiVersionSets));
82+
fileWriter.WriteJSONToFile(authorizationTemplate, String.Concat(@fileFolder, fileNames.authorizationServers));
83+
fileWriter.WriteJSONToFile(backendTemplate, String.Concat(@fileFolder, fileNames.backends));
84+
fileWriter.WriteJSONToFile(loggerTemplate, String.Concat(@fileFolder, fileNames.loggers));
85+
fileWriter.WriteJSONToFile(namedValueTemplate, String.Concat(@fileFolder, fileNames.namedValues));
86+
fileWriter.WriteJSONToFile(productTemplate, String.Concat(@fileFolder, fileNames.products));
8387

8488
Console.WriteLine("Templates written to output location");
8589
Console.WriteLine("Press any key to exit process:");

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

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,51 @@ namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common
44
{
55
public class FileNameGenerator
66
{
7-
public CreatorFileNames GenerateCreatorLinkedFileNames()
7+
8+
public FileNames GenerateFileNames(string apimServiceName)
89
{
910
// generate useable object with file names for consistency throughout project
10-
return new CreatorFileNames()
11+
return new FileNames()
1112
{
12-
apiVersionSets = @"/apiVersionSets.template.json",
13-
products = @"/products.template.json",
14-
loggers = @"/loggers.template.json",
15-
backends = @"/backends.template.json",
16-
authorizationServers = @"/authorizationServers.template.json",
17-
linkedMaster = @"/master.template.json",
18-
linkedParameters = @"/master.parameters.json",
19-
unlinkedParameters = @"/parameters.json"
13+
apiVersionSets = $@"/{apimServiceName}-apiVersionSets.template.json",
14+
products = $@"/{apimServiceName}-products.template.json",
15+
loggers = $@"/{apimServiceName}-loggers.template.json",
16+
backends = $@"/{apimServiceName}-backends.template.json",
17+
namedValues = $@"/{apimServiceName}-namedValues.template.json",
18+
authorizationServers = $@"/{apimServiceName}-authorizationServers.template.json",
19+
linkedMaster = $@"/{apimServiceName}-master.template.json",
20+
parameters = $@"/{apimServiceName}-parameters.json"
2021
};
2122
}
2223

23-
public string GenerateAPIFileName(string apiName, bool isSplitAPI, bool isInitialAPI)
24+
public string GenerateCreatorAPIFileName(string apiName, bool isSplitAPI, bool isInitialAPI, string apimServiceName)
2425
{
2526
if (isSplitAPI == true)
2627
{
27-
return isInitialAPI == true ? $@"/{apiName}-initial.api.template.json" : $@"/{apiName}-subsequent.api.template.json";
28+
return isInitialAPI == true ? $@"/{apimServiceName}-{apiName}-initial.api.template.json" : $@"/{apimServiceName}-{apiName}-subsequent.api.template.json";
2829
}
2930
else
3031
{
31-
return $@"/{apiName}.api.template.json";
32+
return $@"/{apimServiceName}-{apiName}.api.template.json";
3233
}
3334
}
35+
36+
public string GenerateExtractorAPIFileName(string singleAPIName, string apimServiceName)
37+
{
38+
return singleAPIName == null ? $@"{apimServiceName}-apis.template.json" : $@"{apimServiceName}-{singleAPIName}-api.template.json";
39+
}
40+
}
41+
42+
public class FileNames
43+
{
44+
public string apiVersionSets { get; set; }
45+
public string products { get; set; }
46+
public string loggers { get; set; }
47+
public string authorizationServers { get; set; }
48+
public string backends { get; set; }
49+
public string namedValues { get; set; }
50+
public string parameters { get; set; }
51+
// linked property outputs 1 master template
52+
public string linkedMaster { get; set; }
3453
}
3554
}

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

Lines changed: 0 additions & 46 deletions
This file was deleted.

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

Lines changed: 0 additions & 15 deletions
This file was deleted.

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

Lines changed: 0 additions & 15 deletions
This file was deleted.

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

Lines changed: 0 additions & 10 deletions
This file was deleted.

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)