private async void GenerateNamedValuesTemplate(string resourceGroup, string apimname, string fileFolder) { Console.WriteLine("------------------------------------------"); Console.WriteLine("Getting named values from service"); PropertyExtractor propertyExtractor = new PropertyExtractor(); Template armTemplate = GenerateEmptyTemplateWithParameters(); List <TemplateResource> templateResources = new List <TemplateResource>(); // pull named values for later credential reference string properties = propertyExtractor.GetProperties(apimname, resourceGroup).Result; JObject oProperties = JObject.Parse(properties); foreach (var extractedProperty in oProperties["value"]) { string propertyName = ((JValue)extractedProperty["name"]).Value.ToString(); Console.WriteLine("'{0}' Named value found", propertyName); string fullLoggerResource = await propertyExtractor.GetProperty(apimname, resourceGroup, propertyName); PropertyTemplateResource propertyTemplateResource = JsonConvert.DeserializeObject <PropertyTemplateResource>(fullLoggerResource); propertyTemplateResource.name = $"[concat(parameters('ApimServiceName'), '/{propertyName}')]"; propertyTemplateResource.type = "Microsoft.ApiManagement/service/properties"; propertyTemplateResource.apiVersion = "2018-06-01-preview"; propertyTemplateResource.scale = null; templateResources.Add(propertyTemplateResource); } armTemplate.resources = templateResources.ToArray(); FileWriter fileWriter = new FileWriter(); fileWriter.WriteJSONToFile(armTemplate, @fileFolder + Path.DirectorySeparatorChar + apimname + "-namedvalues.json"); }
private async void GenerateLoggerTemplate(string resourceGroup, string apimname, string fileFolder) { Console.WriteLine("------------------------------------------"); Console.WriteLine("Geting loggers from service"); LoggerExtractor loggerExtractor = new LoggerExtractor(); PropertyExtractor propertyExtractor = new PropertyExtractor(); Template armTemplate = new Template() { schema = "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", contentVersion = "1.0.0.0", parameters = new Dictionary <string, TemplateParameterProperties> { { "ApimServiceName", new TemplateParameterProperties() { type = "string" } } }, variables = { }, resources = { }, outputs = { } }; List <TemplateResource> templateResources = new List <TemplateResource>(); // pull named values for later credential reference string properties = propertyExtractor.GetProperties(apimname, resourceGroup).Result; JObject oProperties = JObject.Parse(properties); List <PropertyTemplateResource> propertyResources = oProperties["value"].ToObject <List <PropertyTemplateResource> >(); string loggers = loggerExtractor.GetLoggers(apimname, resourceGroup).Result; JObject oLoggers = JObject.Parse(loggers); foreach (var extractedLogger in oLoggers["value"]) { string loggerName = ((JValue)extractedLogger["name"]).Value.ToString(); Console.WriteLine("'{0}' Logger found", loggerName); string fullLoggerResource = await loggerExtractor.GetLogger(apimname, resourceGroup, loggerName); LoggerTemplateResource loggerResource = JsonConvert.DeserializeObject <LoggerTemplateResource>(fullLoggerResource); loggerResource.name = $"[concat(parameters('ApimServiceName'), '/{loggerName}')]"; loggerResource.type = "Microsoft.ApiManagement/service/loggers"; loggerResource.apiVersion = "2018-06-01-preview"; loggerResource.scale = null; // swap credentials for their hidden values, taken from named values if (loggerResource.properties.credentials != null) { if (loggerResource.properties.credentials.instrumentationKey != null) { string hiddenKey = loggerResource.properties.credentials.instrumentationKey.Substring(2, loggerResource.properties.credentials.instrumentationKey.Length - 4); loggerResource.properties.credentials.instrumentationKey = propertyResources.Find(p => p.properties.displayName == hiddenKey).properties.value; } else if (loggerResource.properties.credentials.connectionString != null) { string hiddenKey = loggerResource.properties.credentials.connectionString.Substring(2, loggerResource.properties.credentials.connectionString.Length - 4); loggerResource.properties.credentials.connectionString = propertyResources.Find(p => p.properties.displayName == hiddenKey).properties.value; } } templateResources.Add(loggerResource); } armTemplate.resources = templateResources.ToArray(); FileWriter fileWriter = new FileWriter(); string filePath = fileFolder + Path.DirectorySeparatorChar + string.Format("loggers", "/", "-") + ".json"; fileWriter.WriteJSONToFile(armTemplate, filePath); }