bool DoesLoggerReferenceNamedValue( List <LoggerTemplateResource> loggerTemplateResources, string propertyName, NamedValueTemplateResource propertyTemplateResource) { if (loggerTemplateResources.IsNullOrEmpty()) { return(false); } foreach (var logger in loggerTemplateResources) { if (logger.Properties.Credentials != null) { if (!string.IsNullOrEmpty(logger.Properties.Credentials.ConnectionString) && logger.Properties.Credentials.ConnectionString.Contains(propertyName) || !string.IsNullOrEmpty(logger.Properties.Credentials.InstrumentationKey) && logger.Properties.Credentials.InstrumentationKey.Contains(propertyName) || !string.IsNullOrEmpty(logger.Properties.Credentials.ConnectionString) && logger.Properties.Credentials.ConnectionString.Contains(propertyTemplateResource.Properties.DisplayName) || !string.IsNullOrEmpty(logger.Properties.Credentials.InstrumentationKey) && logger.Properties.Credentials.InstrumentationKey.Contains(propertyTemplateResource.Properties.DisplayName)) { // dont need to go through all loggers if the named value has already been found return(true); } } } return(false); }
public bool DoesBackendReferenceNamedValue(NamedValueTemplateResource namedValueResource, BackendTemplateResource backendTemplateResource) { var namedValue = namedValueResource.Properties.Value; return(namedValue == backendTemplateResource.Properties.Url || namedValue == backendTemplateResource.Properties.Description || namedValue == backendTemplateResource.Properties.Title); }
public async Task <Template> Create(DeploymentDefinition creatorConfig) { var template = EmptyTemplate; template.Parameters.Add(ApiServiceNameParameter.Key, ApiServiceNameParameter.Value); var resources = new List <TemplateResource>(); foreach (var backendTemplatePropeties in creatorConfig.NamedValues) { var namedValueTemplateResource = new NamedValueTemplateResource() { Name = $"[concat(parameters('ApimServiceName'), '/{backendTemplatePropeties.Name}')]", Properties = backendTemplatePropeties, DependsOn = new string[] { } }; resources.Add(namedValueTemplateResource); } template.Resources = resources.ToArray(); return(await Task.FromResult(template)); }
bool DoesPolicyReferenceNamedValue( List <PolicyTemplateResource> apiPolicies, string propertyName, NamedValueTemplateResource namedValueResource, string baseFilesGenerationDirectory) { if (apiPolicies.IsNullOrEmpty()) { return(false); } foreach (var policyTemplateResource in apiPolicies) { var policyContent = this.policyExtractor.GetCachedPolicyContent(policyTemplateResource, baseFilesGenerationDirectory); if (policyContent.Contains(namedValueResource.Properties.DisplayName) || policyContent.Contains(propertyName)) { // dont need to go through all policies if the named value has already been found return(true); } } return(false); }
public Template CreatePropertyTemplate(CreatorConfig creatorConfig) { // create empty template Template propertyTemplate = this.templateBuilder.GenerateEmptyTemplate().Build(); // add parameters propertyTemplate.Parameters = new Dictionary <string, TemplateParameterProperties> { { ParameterNames.ApimServiceName, new TemplateParameterProperties() { Type = "string" } } }; if (creatorConfig.parameterizeNamedValues) { if (creatorConfig.namedValues.Any(x => x.Value != null)) { propertyTemplate.Parameters.Add(ParameterNames.NamedValues, new TemplateParameterProperties { Type = "object" }); } if (creatorConfig.namedValues.Any(x => x.KeyVault != null)) { propertyTemplate.Parameters.Add(ParameterNames.NamedValueKeyVaultSecrets, new TemplateParameterProperties { Type = "object" }); } } List <TemplateResource> resources = new List <TemplateResource>(); foreach (PropertyConfig namedValue in creatorConfig.namedValues) { string value = namedValue.Value == null ? null : creatorConfig.parameterizeNamedValues ? $"[parameters('{ParameterNames.NamedValues}').{ParameterNamingHelper.GenerateValidParameterName(namedValue.DisplayName, ParameterPrefix.Property)}]" : namedValue.Value; var keyVault = namedValue.KeyVault == null ? null : creatorConfig.parameterizeNamedValues ? new NamedValueResourceKeyVaultProperties { SecretIdentifier = $"[parameters('{ParameterNames.NamedValueKeyVaultSecrets}').{ParameterNamingHelper.GenerateValidParameterName(namedValue.DisplayName, ParameterPrefix.Property)}]" } : namedValue.KeyVault; // create property resource with properties NamedValueTemplateResource propertyTemplateResource = new NamedValueTemplateResource() { Name = $"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{namedValue.DisplayName}')]", Type = ResourceTypeConstants.NamedValues, ApiVersion = GlobalConstants.ApiVersion, Properties = new NamedValueProperties() { DisplayName = namedValue.DisplayName, Value = value, Secret = namedValue.Secret, Tags = namedValue.Tags, KeyVault = keyVault }, DependsOn = new string[] { } }; resources.Add(propertyTemplateResource); } propertyTemplate.Resources = resources.ToArray(); return(propertyTemplate); }