diff --git a/src/ArmTemplates/Commands/Configurations/ExtractorConsoleAppConfiguration.cs b/src/ArmTemplates/Commands/Configurations/ExtractorConsoleAppConfiguration.cs
index 2c13d36e..0828c232 100644
--- a/src/ArmTemplates/Commands/Configurations/ExtractorConsoleAppConfiguration.cs
+++ b/src/ArmTemplates/Commands/Configurations/ExtractorConsoleAppConfiguration.cs
@@ -106,6 +106,9 @@ public class ExtractorConsoleAppConfiguration
[Option(longName: "extractIdentityProviders", HelpText = "Extract identity providers from the service if applies")]
public string ExtractIdentityProviders { get; set; }
+ [Option(longName: "parametersOutputDirectoryName ", HelpText = "Parameters output directory name, by default it is \"parameters\"")]
+ public string ParametersOutputDirectoryName { get; set; }
+
///
/// Api parameter properties for overriding Api OAuth2 scope or/and Service urloverride. Available via extractor-config file only.
///
diff --git a/src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs b/src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs
index 8795085f..bc272e6b 100644
--- a/src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs
+++ b/src/ArmTemplates/Commands/Executors/ExtractorExecutor.cs
@@ -410,6 +410,7 @@ public async Task> GenerateApiTemplateAsync(
if (apiTemplate?.HasResources() == true)
{
apiTemplate.TypedResources.FileName = FileNameGenerator.GenerateExtractorAPIFileName(singleApiName, this.extractorParameters.FileNames.BaseFileName);
+ apiTemplate.TypedResources.ParametersFileName = FileNameGenerator.GenerateExtractorAPIParametersFileName(singleApiName);
await FileWriter.SaveAsJsonAsync(
apiTemplate,
@@ -459,6 +460,79 @@ await FileWriter.SaveAsJsonAsync(
return templateParameters;
}
+ public async Task GenerateResourceParametersFiles(
+ string baseFilesGenerationDirectory,
+ Template mainParametersTemplate,
+ Template apiTemplate = null,
+ Template policyTemplate = null,
+ Template apiVersionSetTemplate = null,
+ Template productsTemplate = null,
+ Template productApisTemplate = null,
+ Template apiTagsTemplate = null,
+ Template loggersTemplate = null,
+ Template backendsTemplate = null,
+ Template authorizationServersTemplate = null,
+ Template namedValuesTemplate = null,
+ Template tagTemplate = null,
+ Template groupTemplate = null,
+ Template identityProviderTemplate = null,
+ Template schemaTemplate = null,
+ Template openIdConnectProviderTemplate = null,
+ Template policyFragmentsTemplate = null)
+ {
+ this.RenameExistingParametersDirectory(baseFilesGenerationDirectory);
+
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, apiTemplate?.TypedResources.ParametersFileName, apiTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.GlobalServicePolicyParameters , policyTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.ApiVersionSetsParameters, apiVersionSetTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.ProductsParameters, productsTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.ProductAPIsParameters, productApisTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.TagApiParameters, apiTagsTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.LoggersParameters, loggersTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.BackendsParameters, backendsTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.AuthorizationServersParameters, authorizationServersTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.NamedValuesParameters, namedValuesTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.TagsParameters, tagTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.GroupsParameters, groupTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.IdentityProvidersParameters, identityProviderTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.SchemaParameters, schemaTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.OpenIdConnectProvidersParameters, openIdConnectProviderTemplate, mainParametersTemplate);
+ await this.GenerateResourceParametersFile(baseFilesGenerationDirectory, this.extractorParameters.FileNames.PolicyFragmentsParameters, policyFragmentsTemplate, mainParametersTemplate);
+ }
+
+ public async Task GenerateResourceParametersFile(string baseFilesGenerationDirectory, string fileName, Template resourceTemplate, Template mainParametersTemplate) where TTemplateResource : ITemplateResources, new()
+ {
+ if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(baseFilesGenerationDirectory))
+ {
+ this.logger.LogWarning("Filename or directory for parameters file generation is null or empty, skipping the generation");
+ return;
+ }
+
+ if (resourceTemplate?.TypedResources?.HasContent() == true)
+ {
+ var parametersTemplate = this.parametersExtractor.CreateResourceTemplateParameterTemplate(resourceTemplate, mainParametersTemplate);
+
+ if (!parametersTemplate.Parameters.IsNullOrEmpty())
+ {
+ await FileWriter.SaveAsJsonAsync(
+ parametersTemplate,
+ directory: Path.Combine(baseFilesGenerationDirectory, this.extractorParameters.FileNames.ParametersDirectory),
+ fileName: fileName);
+ }
+ }
+ }
+
+ void RenameExistingParametersDirectory(string baseDirectoryLocation)
+ {
+ var parametersLocation = Path.Combine(baseDirectoryLocation, this.extractorParameters.FileNames.ParametersDirectory);
+ if (Directory.Exists(parametersLocation))
+ {
+ var creationDateTime = Directory.GetCreationTime(parametersLocation).ToString("yyyyMMddHHmmss");
+ var newParameterDirectory = $"{this.extractorParameters.FileNames.ParametersDirectory}{creationDateTime}";
+ Directory.Move(parametersLocation, Path.Combine(baseDirectoryLocation, newParameterDirectory));
+ }
+ }
+
public async Task> GenerateMasterTemplateAsync(
string baseFilesGenerationDirectory,
ApiTemplateResources apiTemplateResources = null,
@@ -1035,8 +1109,28 @@ async Task GenerateTemplates(
await this.GenerateGatewayTemplateAsync(singleApiName, baseFilesGenerationDirectory);
await this.GenerateGatewayApiTemplateAsync(singleApiName, multipleApiNames, baseFilesGenerationDirectory);
await this.GenerateApiManagementServiceTemplate(baseFilesGenerationDirectory);
- await this.GenerateParametersTemplateAsync(apisToExtract, loggerTemplate.TypedResources, backendTemplate.TypedResources, namedValueTemplate.TypedResources, identityProviderTemplate.TypedResources, openIdConnectProviderTemplate.TypedResources, baseFilesGenerationDirectory);
+ var parametersTemplate = await this.GenerateParametersTemplateAsync(apisToExtract, loggerTemplate.TypedResources, backendTemplate.TypedResources, namedValueTemplate.TypedResources, identityProviderTemplate.TypedResources, openIdConnectProviderTemplate.TypedResources, baseFilesGenerationDirectory);
+ await this.GenerateResourceParametersFiles(
+ baseFilesGenerationDirectory,
+ parametersTemplate,
+ apiTemplate: apiTemplate,
+ policyTemplate: globalServicePolicyTemplate,
+ productApisTemplate: productApiTemplate,
+ productsTemplate: productTemplate,
+ apiVersionSetTemplate: apiVersionSetTemplate,
+ authorizationServersTemplate: authorizationServerTemplate,
+ tagTemplate: tagTemplate,
+ apiTagsTemplate: apiTagTemplate,
+ loggersTemplate: loggerTemplate,
+ namedValuesTemplate: namedValueTemplate,
+ backendsTemplate: backendTemplate,
+ groupTemplate: groupTemplate,
+ identityProviderTemplate: identityProviderTemplate,
+ openIdConnectProviderTemplate: openIdConnectProviderTemplate,
+ schemaTemplate: schemasTempate,
+ policyFragmentsTemplate: policyFragmentTemplate);
+
await this.GenerateMasterTemplateAsync(
baseFilesGenerationDirectory,
apiTemplateResources: apiTemplate.TypedResources,
diff --git a/src/ArmTemplates/Common/FileHandlers/FileNameGenerator.cs b/src/ArmTemplates/Common/FileHandlers/FileNameGenerator.cs
index 19a8e21a..71bcbfe3 100644
--- a/src/ArmTemplates/Common/FileHandlers/FileNameGenerator.cs
+++ b/src/ArmTemplates/Common/FileHandlers/FileNameGenerator.cs
@@ -24,22 +24,38 @@ public static FileNames GenerateFileNames(string baseFileName)
return new FileNames
{
ApiVersionSets = $@"{baseFileName}apiVersionSets.template.json",
+ ApiVersionSetsParameters = "apiVersionSets.parameters.json",
AuthorizationServers = $@"{baseFileName}authorizationServers.template.json",
+ AuthorizationServersParameters = "authorizationServers.parameters.json",
Backends = $@"{baseFileName}backends.template.json",
+ BackendsParameters = "backends.parameters.json",
GlobalServicePolicy = $@"{baseFileName}globalServicePolicy.template.json",
+ GlobalServicePolicyParameters = "globalServicePolicy.parameters.json",
Loggers = $@"{baseFileName}loggers.template.json",
+ LoggersParameters = "loggers.parameters.json",
NamedValues = $@"{baseFileName}namedValues.template.json",
+ NamedValuesParameters = "namedValues.parameters.json",
Tags = $@"{baseFileName}tags.template.json",
+ TagsParameters = "tags.parameters.json",
Products = $@"{baseFileName}products.template.json",
+ ProductsParameters = "products.parameters.json",
ProductAPIs = $@"{baseFileName}productAPIs.template.json",
+ ProductAPIsParameters = "productAPIs.parameters.json",
Gateway = $@"{baseFileName}gateways.template.json",
+ GatewayParameters = "gateways.parameters.json",
GatewayApi = $@"{baseFileName}gateways-apis.template.json",
+ GatewayApiParameters = "gateways-apis.parameters.json",
IdentityProviders = $@"{baseFileName}identity-providers.template.json",
+ IdentityProvidersParameters = "identity-providers.parameters.json",
OpenIdConnectProviders = $@"{baseFileName}openid-connect-providers.template.json",
+ OpenIdConnectProvidersParameters = "openid-connect-providers.parameters.json",
ApiManagementService = $@"{baseFileName}api-management-service.template.json",
TagApi = $@"{baseFileName}apiTags.template.json",
+ TagApiParameters = "apiTags.parameters.json",
Schema = $@"{baseFileName}schemas.template.json",
+ SchemaParameters = "schemas.parameters.json",
PolicyFragments = $@"{baseFileName}policy-fragments.template.json",
+ PolicyFragmentsParameters = "policy-fragments.parameters.json",
Parameters = $@"{baseFileName}parameters.json",
LinkedMaster = $@"{baseFileName}master.template.json",
Apis = "/Apis",
@@ -48,6 +64,8 @@ public static FileNames GenerateFileNames(string baseFileName)
RevisionMasterFolder = "/RevisionMasterFolder",
GroupAPIsMasterFolder = "/MultipleApisMasterFolder",
Groups = $"{baseFileName}groups.template.json",
+ GroupsParameters = "groups.parameters.json",
+ ParametersDirectory = $"{baseFileName}parameters",
BaseFileName = baseFileName
};
}
@@ -69,7 +87,16 @@ public static string GenerateCreatorAPIFileName(string apiName, bool isSplitAPI,
public static string GenerateExtractorAPIFileName(string singleAPIName, string baseFileName)
{
- return singleAPIName == null ? $@"{baseFileName}apis.template.json" : $@"{baseFileName}{singleAPIName}-api.template.json";
+ return $@"{baseFileName}{GenerateApiFileNameBase(singleAPIName)}.template.json";
+ }
+
+ public static string GenerateExtractorAPIParametersFileName(string singleAPIName)
+ {
+ return $@"{GenerateApiFileNameBase(singleAPIName)}.parameters.json";
+ }
+
+ public static string GenerateApiFileNameBase(string singleAPIName) {
+ return singleAPIName == null ? "apis" : $"{singleAPIName}-api";
}
public static string GenerateOriginalAPIName(string apiName)
diff --git a/src/ArmTemplates/Common/FileHandlers/FileNames.cs b/src/ArmTemplates/Common/FileHandlers/FileNames.cs
index 2fd8a68d..2671ad78 100644
--- a/src/ArmTemplates/Common/FileHandlers/FileNames.cs
+++ b/src/ArmTemplates/Common/FileHandlers/FileNames.cs
@@ -9,40 +9,74 @@ public class FileNames
{
public string ApiVersionSets { get; set; }
+ public string ApiVersionSetsParameters { get; set; }
+
public string AuthorizationServers { get; set; }
+ public string AuthorizationServersParameters { get; set; }
+
public string Backends { get; set; }
+ public string BackendsParameters { get; set; }
+
public string GlobalServicePolicy { get; set; }
+ public string GlobalServicePolicyParameters { get; set; }
+
public string Loggers { get; set; }
+ public string LoggersParameters { get; set; }
+
public string NamedValues { get; set; }
+ public string NamedValuesParameters { get; set; }
+
public string Tags { get; set; }
+ public string TagsParameters { get; set; }
+
public string Products { get; set; }
+ public string ProductsParameters { get; set; }
+
public string ProductAPIs { get; set; }
+ public string ProductAPIsParameters { get; set; }
+
public string Groups { get; set; }
+ public string GroupsParameters { get; set; }
+
public string TagApi { get; set; }
+ public string TagApiParameters { get; set; }
+
public string Gateway { get; set; }
+ public string GatewayParameters { get; set; }
+
public string GatewayApi { get; set; }
+ public string GatewayApiParameters { get; set; }
+
public string IdentityProviders { get; set; }
+ public string IdentityProvidersParameters { get; set; }
+
public string OpenIdConnectProviders { get; set; }
+ public string OpenIdConnectProvidersParameters { get; set; }
+
public string ApiManagementService { get; set; }
public string Schema { get; set; }
+ public string SchemaParameters { get; set; }
+
public string PolicyFragments { get; set; }
+ public string PolicyFragmentsParameters { get; set; }
+
public string Parameters { get; set; }
// linked property outputs 1 master template
@@ -59,5 +93,7 @@ public class FileNames
public string GroupAPIsMasterFolder { get; set; }
public string BaseFileName { get; set; }
+
+ public string ParametersDirectory { get; set; }
}
}
diff --git a/src/ArmTemplates/Common/Templates/Apis/ApiTemplateResources.cs b/src/ArmTemplates/Common/Templates/Apis/ApiTemplateResources.cs
index 65823bae..05c31fdb 100644
--- a/src/ArmTemplates/Common/Templates/Apis/ApiTemplateResources.cs
+++ b/src/ArmTemplates/Common/Templates/Apis/ApiTemplateResources.cs
@@ -19,6 +19,8 @@ public class ApiTemplateResources : TemplateResourcesBase, ITemplateResources
{
public string FileName { get; set; }
+ public string ParametersFileName { get; set; }
+
public List Apis { get; set; } = new();
public List ApiSchemas { get; set; } = new();
diff --git a/src/ArmTemplates/Extractor/EntityExtractors/Abstractions/IParametersExtractor.cs b/src/ArmTemplates/Extractor/EntityExtractors/Abstractions/IParametersExtractor.cs
index 943e1f44..ffc663a7 100644
--- a/src/ArmTemplates/Extractor/EntityExtractors/Abstractions/IParametersExtractor.cs
+++ b/src/ArmTemplates/Extractor/EntityExtractors/Abstractions/IParametersExtractor.cs
@@ -27,5 +27,7 @@ Task CreateMasterTemplateParameterValues(
IdentityProviderResources identityProviderResources,
OpenIdConnectProviderResources openIdConnectProviderResources,
ExtractorParameters extractorParameters);
+
+ Template CreateResourceTemplateParameterTemplate(Template resourceTemplate, Template mainParametersTemplate);
}
}
diff --git a/src/ArmTemplates/Extractor/EntityExtractors/ParametersExtractor.cs b/src/ArmTemplates/Extractor/EntityExtractors/ParametersExtractor.cs
index e07d9919..201e281b 100644
--- a/src/ArmTemplates/Extractor/EntityExtractors/ParametersExtractor.cs
+++ b/src/ArmTemplates/Extractor/EntityExtractors/ParametersExtractor.cs
@@ -18,6 +18,7 @@
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.OpenIdConnectProviders;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.EntityExtractors.Abstractions;
using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
+using Microsoft.Extensions.Logging;
namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.EntityExtractors
{
@@ -27,13 +28,16 @@ public class ParametersExtractor : IParametersExtractor
readonly IApisClient apisClient;
readonly IIdentityProviderClient identityProviderClient;
readonly IOpenIdConnectProvidersClient openIdConnectProviderClient;
+ readonly ILogger logger;
public ParametersExtractor(
+ ILogger logger,
ITemplateBuilder templateBuilder,
IApisClient apisClient,
IIdentityProviderClient identityProviderClient,
IOpenIdConnectProvidersClient openIdConnectProviderClient)
{
+ this.logger = logger;
this.templateBuilder = templateBuilder;
this.apisClient = apisClient;
this.identityProviderClient = identityProviderClient;
@@ -268,5 +272,31 @@ async Task AddSecretValuesParameters()
return parametersTemplate;
}
+
+ public Template CreateResourceTemplateParameterTemplate(Template resourceTemplate, Template mainParameterTemplate)
+ {
+ var parametersTemplate = this.templateBuilder
+ .GenerateEmptyTemplate()
+ .Build();
+ parametersTemplate.Parameters = new();
+ var parameters = parametersTemplate.Parameters;
+
+ if (resourceTemplate?.Parameters.IsNullOrEmpty() != true)
+ {
+ foreach (var parameterKey in resourceTemplate.Parameters.Keys)
+ {
+ if (!mainParameterTemplate.Parameters.ContainsKey(parameterKey))
+ {
+ this.logger.LogWarning($"Parameter {parameterKey} were not found in main parameters template");
+ continue;
+ }
+
+ var parameterValue = mainParameterTemplate.Parameters[parameterKey];
+ parameters.Add(parameterKey, parameterValue);
+ }
+ }
+
+ return parametersTemplate;
+ }
}
}
diff --git a/src/ArmTemplates/Extractor/Models/ExtractorParameters.cs b/src/ArmTemplates/Extractor/Models/ExtractorParameters.cs
index 3a7c22fd..9b2fdd78 100644
--- a/src/ArmTemplates/Extractor/Models/ExtractorParameters.cs
+++ b/src/ArmTemplates/Extractor/Models/ExtractorParameters.cs
@@ -90,6 +90,8 @@ public record ExtractorParameters
public bool ExtractIdentityProviders { get; set; }
+ public string ParametersOutputDirectoryName { get; set; }
+
public Dictionary ApiParameters { get; private set; }
public ExtractorParameters(ExtractorConsoleAppConfiguration extractorConfig)
@@ -125,6 +127,12 @@ public ExtractorParameters(ExtractorConsoleAppConfiguration extractorConfig)
this.ParametrizeApiOauth2Scope = (extractorConfig.ParamApiOauth2Scope != null && extractorConfig.ParamApiOauth2Scope.Equals("true", StringComparison.OrdinalIgnoreCase)) || (extractorConfig.ApiParameters != null && extractorConfig.ApiParameters.Any(x => x.Value.Oauth2Scope is not null));
this.ExtractSecrets = extractorConfig.ExtractSecrets != null && extractorConfig.ExtractSecrets.Equals("true", StringComparison.OrdinalIgnoreCase);
this.ExtractIdentityProviders = extractorConfig.ExtractIdentityProviders != null && extractorConfig.ExtractIdentityProviders.Equals("true", StringComparison.OrdinalIgnoreCase);
+
+ this.ParametersOutputDirectoryName = extractorConfig.ParametersOutputDirectoryName;
+ if (!string.IsNullOrEmpty(extractorConfig.ParametersOutputDirectoryName))
+ {
+ this.FileNames.ParametersDirectory = extractorConfig.ParametersOutputDirectoryName;
+ }
}
public ExtractorParameters OverrideConfiguration(ExtractorConsoleAppConfiguration overridingConfig)
diff --git a/src/README.md b/src/README.md
index 011f20dc..71428b07 100644
--- a/src/README.md
+++ b/src/README.md
@@ -447,6 +447,7 @@ You have two choices when specifying your settings:
| apiParameters | No | Parameterize api parameters (Oauth2 Scope/Service Url) values for APIs in advance. |
| exctractSecrets | No | By default false. If set to "true" secrets will be extracted as well and parameters templated will be supplied with actual secret values. Currently applies to identityProvider service. |
| extractIdentityProviders | No | By default false. Set to true will attempt to extract the identity providers from service. |
+| parametersOutputDirectoryName | No | If set will redefine the output folder name for parameters. By default will be equal to {service-name}-parameters |
#### Note
diff --git a/tests/ArmTemplates.Tests/Common/FileHandlerTests/FileNameGeneratorTests.cs b/tests/ArmTemplates.Tests/Common/FileHandlerTests/FileNameGeneratorTests.cs
new file mode 100644
index 00000000..a570e019
--- /dev/null
+++ b/tests/ArmTemplates.Tests/Common/FileHandlerTests/FileNameGeneratorTests.cs
@@ -0,0 +1,61 @@
+// --------------------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+// --------------------------------------------------------------------------
+
+using Xunit;
+using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.FileHandlers;
+using FluentAssertions;
+
+namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Tests.Common.FileHandlerTests
+{
+ public class FileNameGeneratorTests
+ {
+ [Fact]
+ public void ShouldGenerateApiFileName_GivenSingleApiName()
+ {
+ // arrange
+ string apiName = "apiName";
+ string baseFileName = "base-";
+
+ // act
+ var fileNameLocation = FileNameGenerator.GenerateExtractorAPIFileName(apiName, baseFileName);
+
+ // assert
+ fileNameLocation.Should().BeEquivalentTo($"{baseFileName}{apiName}-api.template.json");
+ }
+
+ [Fact]
+ public void ShouldGenerateApiFileName_GivenSingleApiNameIsNull()
+ {
+ // arrange
+ string baseFileName = "base-";
+
+ // act
+ var fileNameLocation = FileNameGenerator.GenerateExtractorAPIFileName(null, baseFileName);
+
+ // assert
+ fileNameLocation.Should().BeEquivalentTo($"{baseFileName}apis.template.json");
+ }
+
+ [Fact]
+ public void ShouldGenerateApiBaseFileName_GivenSingleApiNameIsNull()
+ {
+ // act
+ var apiFileNameBase = FileNameGenerator.GenerateApiFileNameBase(null);
+
+ // assert
+ apiFileNameBase.Should().BeEquivalentTo("apis");
+ }
+
+ [Fact]
+ public void ShouldGenerateApiBaseFileName_GivenSingleApiName()
+ {
+ var apiName = "apiName";
+ var apiFileNameBase = FileNameGenerator.GenerateApiFileNameBase(apiName);
+
+ // assert
+ apiFileNameBase.Should().BeEquivalentTo($"{apiName}-api");
+ }
+ }
+}
diff --git a/tests/ArmTemplates.Tests/Extractor/Scenarios/ParametersExtractorTests.cs b/tests/ArmTemplates.Tests/Extractor/Scenarios/ParametersExtractorTests.cs
index 4928a511..aec5f4e7 100644
--- a/tests/ArmTemplates.Tests/Extractor/Scenarios/ParametersExtractorTests.cs
+++ b/tests/ArmTemplates.Tests/Extractor/Scenarios/ParametersExtractorTests.cs
@@ -32,7 +32,7 @@ public ParametersExtractorTests() : base("parameters-tests")
ExtractorExecutor GetExtractorInstance(ExtractorParameters extractorParameters, IApisClient apisClient = null, IIdentityProviderClient identityProviderClient = null, IOpenIdConnectProvidersClient openIdConnectProviderClient = null)
{
- var parametersExtractor = new ParametersExtractor(new TemplateBuilder(), apisClient, identityProviderClient, openIdConnectProviderClient);
+ var parametersExtractor = new ParametersExtractor(this.GetTestLogger(), new TemplateBuilder(), apisClient, identityProviderClient, openIdConnectProviderClient);
var loggerExtractor = new LoggerExtractor(
this.GetTestLogger(),
@@ -325,5 +325,112 @@ public async Task GenerateParametersTemplates_ProperlyLaysTheInformation_Provide
secretValueParameterValues[ParameterNames.IdentityProvidersSecretValues].Should().ContainKey("originalNameIdentityProvider");
secretValueParameterValues[ParameterNames.IdentityProvidersSecretValues]["originalNameIdentityProvider"].Should().Be(string.Empty);
}
+
+ [Fact]
+ public async Task GenerateResourceParametersFiles_ProperlyGeneratesRenmaesAndCreatesNewDirectoryWithParameterFile_GivenItsCalledTwice()
+ {
+ // arrange
+ var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateResourceParametersFiles_ProperlyGeneratesRenmaesAndCreatesNewDirectoryWithParameterFile_GivenItsCalledTwice));
+
+ var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration();
+ var extractorParameters = new ExtractorParameters(extractorConfig);
+ var extractorExecutor = this.GetExtractorInstance(extractorParameters, null);
+
+ var resourceTemplate = new Template()
+ {
+ Parameters = new Dictionary() {
+ { "parameter1", new () },
+ { "parameter2", new () }
+ },
+ TypedResources = new OpenIdConnectProviderResources()
+ {
+ OpenIdConnectProviders = new List()
+ {
+ new(),
+ new(),
+ }
+ }
+ };
+
+ var mainParameterTemplate = new Template()
+ {
+ Parameters = new Dictionary() {
+ { "parameter1", new () },
+ { "parameter2", new () },
+ { "parameter3", new () },
+ { "parameter4", new () },
+ { "parameter5", new () },
+ }
+ };
+
+ // act
+ await extractorExecutor.GenerateResourceParametersFiles(currentTestDirectory, mainParameterTemplate, openIdConnectProviderTemplate: resourceTemplate);
+ Directory.Exists(Path.Combine(currentTestDirectory, extractorParameters.FileNames.ParametersDirectory)).Should().BeTrue();
+ var creationDateTime = Directory.GetCreationTime(Path.Combine(currentTestDirectory, extractorParameters.FileNames.ParametersDirectory)).ToString("yyyyMMddHHmmss");
+
+ await extractorExecutor.GenerateResourceParametersFiles(currentTestDirectory, mainParameterTemplate, openIdConnectProviderTemplate: resourceTemplate);
+ Directory.Exists(Path.Combine(currentTestDirectory, extractorParameters.FileNames.ParametersDirectory)).Should().BeTrue();
+ Directory.Exists(Path.Combine(currentTestDirectory, $"{extractorParameters.FileNames.ParametersDirectory}{creationDateTime}")).Should().BeTrue();
+ }
+
+ [Fact]
+ public async Task GenerateResourceParametersFile_DoesNotRaiseException_GivenNullFilenames()
+ {
+ // arrange
+ var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateResourceParametersFile_DoesNotRaiseException_GivenNullFilenames));
+ var parameterFileName = "filename.json";
+
+ var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration();
+ var extractorParameters = new ExtractorParameters(extractorConfig);
+ var extractorExecutor = this.GetExtractorInstance(extractorParameters, null);
+
+ var resourceTemplate = new Template()
+ {
+ Parameters = new Dictionary() {
+ { "parameter1", new () },
+ { "parameter2", new () }
+ }
+ };
+
+ // act
+ await extractorExecutor.GenerateResourceParametersFile(parameterFileName, null, resourceTemplate, null);
+
+ File.Exists(Path.Combine(currentTestDirectory, extractorParameters.FileNames.ParametersDirectory, parameterFileName)).Should().BeFalse();
+ }
+
+ [Fact]
+ public void CreateResourceTemplateParameterTemplate_ProperlyGeneratesTemplate_WithFilteredParameters()
+ {
+ // arrange
+
+ var parameterExtractor = new ParametersExtractor(this.GetTestLogger(), new TemplateBuilder(), default, default, default);
+
+ var resourceTemplate = new Template()
+ {
+ Parameters = new Dictionary() {
+ { "parameter1", new () },
+ { "parameter2", new () }
+ }
+ };
+
+ var mainParameterTemplate = new Template()
+ {
+ Parameters = new Dictionary() {
+ { "parameter1", new () },
+ { "parameter2", new () },
+ { "parameter3", new () },
+ { "parameter4", new () },
+ { "parameter5", new () },
+ }
+ };
+
+ // act
+ var resourceTemplateParameterTemplate = parameterExtractor.CreateResourceTemplateParameterTemplate(resourceTemplate, mainParameterTemplate);
+
+ // assert
+ resourceTemplateParameterTemplate.Parameters.Should().HaveCount(2);
+ resourceTemplateParameterTemplate.Parameters["parameter1"].Should().NotBeNull();
+ resourceTemplateParameterTemplate.Parameters["parameter2"].Should().NotBeNull();
+ }
}
}