public async Task <Template> GenerateNamedValuesTemplateAsync(string singleApiName, List <TemplateResource> apiTemplateResources, Extractor exc, BackendExtractor backendExtractor, List <TemplateResource> loggerTemplateResources) { Template armTemplate = GenerateEmptyPropertyTemplateWithParameters(); if (exc.paramNamedValue) { TemplateParameterProperties namedValueParameterProperties = new TemplateParameterProperties() { type = "object" }; armTemplate.parameters.Add(ParameterNames.NamedValues, namedValueParameterProperties); } if (exc.paramNamedValuesKeyVaultSecrets) { TemplateParameterProperties keyVaultNamedValueParameterProperties = new TemplateParameterProperties() { type = "object" }; armTemplate.parameters.Add(ParameterNames.NamedValueKeyVaultSecrets, keyVaultNamedValueParameterProperties); } if (exc.notIncludeNamedValue == true) { Console.WriteLine("------------------------------------------"); Console.WriteLine("Skipping extracting named values from service"); return(armTemplate); } Console.WriteLine("------------------------------------------"); Console.WriteLine("Extracting named values from service"); List <TemplateResource> templateResources = new List <TemplateResource>(); // pull all named values (properties) for service string[] properties = await GetPropertiesAsync(exc.sourceApimName, exc.resourceGroup); // isolate api and operation policy resources in the case of a single api extraction, as they may reference named value var policyResources = apiTemplateResources.Where(resource => (resource.type == ResourceTypeConstants.APIPolicy || resource.type == ResourceTypeConstants.APIOperationPolicy || resource.type == ResourceTypeConstants.ProductPolicy)); foreach (var extractedProperty in properties) { JToken oProperty = JObject.Parse(extractedProperty); string propertyName = ((JValue)oProperty["name"]).Value.ToString(); string fullPropertyResource = await GetPropertyDetailsAsync(exc.sourceApimName, exc.resourceGroup, propertyName); // convert returned named value to template resource class PropertyTemplateResource propertyTemplateResource = JsonConvert.DeserializeObject <PropertyTemplateResource>(fullPropertyResource); propertyTemplateResource.name = $"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{propertyName}')]"; propertyTemplateResource.type = ResourceTypeConstants.Property; propertyTemplateResource.apiVersion = GlobalConstants.APIVersion; propertyTemplateResource.scale = null; if (exc.paramNamedValue) { propertyTemplateResource.properties.value = $"[parameters('{ParameterNames.NamedValues}').{ExtractorUtils.GenValidParamName(propertyName, ParameterPrefix.Property)}]"; } //Hide the value field if it is a keyvault named value if (propertyTemplateResource.properties.keyVault != null) { propertyTemplateResource.properties.value = null; } if (propertyTemplateResource.properties.keyVault != null && exc.paramNamedValuesKeyVaultSecrets) { propertyTemplateResource.properties.keyVault.secretIdentifier = $"[parameters('{ParameterNames.NamedValueKeyVaultSecrets}').{ExtractorUtils.GenValidParamName(propertyName, ParameterPrefix.Property)}]"; } if (singleApiName == null) { // if the user is executing a full extraction, extract all the loggers Console.WriteLine("'{0}' Named value found", propertyName); templateResources.Add(propertyTemplateResource); } else { // if the user is executing a single api, extract all the named values used in the template resources bool foundInPolicy = DoesPolicyReferenceNamedValue(exc, policyResources, propertyName, propertyTemplateResource); bool foundInBackEnd = await backendExtractor.IsNamedValueUsedInBackends(exc.sourceApimName, exc.resourceGroup, singleApiName, apiTemplateResources, exc, propertyName, propertyTemplateResource.properties.displayName); bool foundInLogger = DoesLoggerReferenceNamedValue(loggerTemplateResources, propertyName, propertyTemplateResource); // check if named value is referenced in a backend if (foundInPolicy || foundInBackEnd || foundInLogger) { // named value was used in policy, extract it Console.WriteLine("'{0}' Named value found", propertyName); templateResources.Add(propertyTemplateResource); } } } armTemplate.resources = templateResources.ToArray(); return(armTemplate); }