public ThrowOnFailedValidation(ReadOnlySettings settings) { this.settings = settings; // validators defaultQueuePathValidation = queuePath => { var validationResult = new ValidationResult(); if (!queueAndTopicNameRegex.IsMatch(queuePath)) { validationResult.AddErrorForInvalidCharacters($"Queue path {queuePath} contains illegal characters. Legal characters should match the following regex: `{queuePath}`."); } var maximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.QueuePathMaximumLength); if (queuePath.Length > maximumLength) { validationResult.AddErrorForInvalidLenth($"Queue path `{queuePath}` exceeds maximum length of {maximumLength} characters."); } return(validationResult); }; defaultTopicPathValidation = topicPath => { var validationResult = new ValidationResult(); if (!queueAndTopicNameRegex.IsMatch(topicPath)) { validationResult.AddErrorForInvalidCharacters($"Topic path {topicPath} contains illegal characters. Legal characters should match the following regex: `{topicPath}`."); } var maximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.TopicPathMaximumLength); if (topicPath.Length > maximumLength) { validationResult.AddErrorForInvalidLenth($"Topic path `{topicPath}` exceeds maximum length of {maximumLength} characters."); } return(validationResult); }; defaultSubscriptionNameValidation = subscriptionName => { var validationResult = new ValidationResult(); if (!subscriptionAndRuleNameRegex.IsMatch(subscriptionName)) { validationResult.AddErrorForInvalidCharacters($"Subscription name {subscriptionName} contains illegal characters. Legal characters should match the following regex: `{subscriptionName}`."); } var maximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.SubscriptionNameMaximumLength); if (subscriptionName.Length > maximumLength) { validationResult.AddErrorForInvalidLenth($"Subscription name `{subscriptionName}` exceeds maximum length of {maximumLength} characters."); } return(validationResult); }; defaultRuleNameValidation = ruleName => { var validationResult = new ValidationResult(); if (!subscriptionAndRuleNameRegex.IsMatch(ruleName)) { validationResult.AddErrorForInvalidCharacters($"Rule name {ruleName} contains illegal characters. Legal characters should match the following regex: `{ruleName}`."); } var maximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.RuleNameMaximumLength); if (ruleName.Length > maximumLength) { validationResult.AddErrorForInvalidLenth($"Rule name `{ruleName}` exceeds maximum length of {maximumLength} characters."); } return(validationResult); }; }
public ValidateAndHashIfNeeded(ReadOnlySettings settings) { this.settings = settings; // validators defaultQueuePathValidation = queuePath => { var validationResult = new ValidationResult(); if (!queueAndTopicPathValidationRegex.IsMatch(queuePath)) { validationResult.AddErrorForInvalidCharacters($"Queue path {queuePath} contains illegal characters. Legal characters should match the following regex: `{queuePath}`."); } var maximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.QueuePathMaximumLength); if (queuePath.Length > maximumLength) { validationResult.AddErrorForInvalidLenth($"Queue path `{queuePath}` exceeds maximum length of {maximumLength} characters."); } return(validationResult); }; defaultTopicPathValidation = topicPath => { var validationResult = new ValidationResult(); if (!queueAndTopicPathValidationRegex.IsMatch(topicPath)) { validationResult.AddErrorForInvalidCharacters($"Topic path {topicPath} contains illegal characters. Legal characters should match the following regex: `{topicPath}`."); } var maximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.TopicPathMaximumLength); if (topicPath.Length > maximumLength) { validationResult.AddErrorForInvalidLenth($"Topic path `{topicPath}` exceeds maximum length of {maximumLength} characters."); } return(validationResult); }; defaultSubscriptionNameValidation = subscriptionName => { var validationResult = new ValidationResult(); if (!subscriptionAndRuleNameValidationRegex.IsMatch(subscriptionName)) { validationResult.AddErrorForInvalidCharacters($"Subscription name {subscriptionName} contains illegal characters. Legal characters should match the following regex: `{subscriptionName}`."); } var maximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.SubscriptionNameMaximumLength); if (subscriptionName.Length > maximumLength) { validationResult.AddErrorForInvalidLenth($"Subscription name `{subscriptionName}` exceeds maximum length of {maximumLength} characters."); } return(validationResult); }; defaultRuleNameValidation = ruleName => { var validationResult = new ValidationResult(); if (!subscriptionAndRuleNameValidationRegex.IsMatch(ruleName)) { validationResult.AddErrorForInvalidCharacters($"Rule name {ruleName} contains illegal characters. Legal characters should match the following regex: `{ruleName}`."); } var maximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.RuleNameMaximumLength); if (ruleName.Length > maximumLength) { validationResult.AddErrorForInvalidLenth($"Rule name `{ruleName}` exceeds maximum length of {maximumLength} characters."); } return(validationResult); }; // sanitizers defaultQueuePathSanitization = queuePath => queueAndTopicPathSanitizationRegex.Replace(queuePath, string.Empty); defaultTopicPathSanitization = topicPath => queueAndTopicPathSanitizationRegex.Replace(topicPath, string.Empty); defaultSubscriptionNameSanitization = subscriptionPath => subscriptionAndRuleNameSanitizationRegex.Replace(subscriptionPath, string.Empty); defaultRuleNameSanitization = rulePath => subscriptionAndRuleNameSanitizationRegex.Replace(rulePath, string.Empty); // hash defaultHashing = entityPathOrName => MD5DeterministicNameBuilder.Build(entityPathOrName); }
internal ThrowOnFailedValidation(ReadOnlySettings settings) { var maximumQueuePathLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.QueuePathMaximumLength); if (!settings.TryGet(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.QueuePathValidator, out queuePathValidation)) { queuePathValidation = queuePath => { ValidationResult validationResult = null; if (!ValidateAndHashIfNeeded.queueAndTopicPathValidationRegex.IsMatch(queuePath)) { validationResult = new ValidationResult(); validationResult.AddErrorForInvalidCharacters($"Queue path {queuePath} contains illegal characters. Legal characters should match the following regex: `{ValidateAndHashIfNeeded.queueAndTopicPathValidationRegex}`."); } if (queuePath.Length > maximumQueuePathLength) { validationResult = validationResult ?? new ValidationResult(); validationResult.AddErrorForInvalidLength($"Queue path `{queuePath}` exceeds maximum length of {maximumQueuePathLength} characters."); } return(validationResult ?? ValidationResult.Empty); }; } var topicPathMaximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.TopicPathMaximumLength); if (!settings.TryGet(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.TopicPathValidator, out topicPathValidation)) { topicPathValidation = topicPath => { ValidationResult validationResult = null; if (!ValidateAndHashIfNeeded.queueAndTopicPathValidationRegex.IsMatch(topicPath)) { validationResult = new ValidationResult(); validationResult.AddErrorForInvalidCharacters($"Topic path {topicPath} contains illegal characters. Legal characters should match the following regex: `{ValidateAndHashIfNeeded.queueAndTopicPathValidationRegex}`."); } if (topicPath.Length > topicPathMaximumLength) { validationResult = validationResult ?? new ValidationResult(); validationResult.AddErrorForInvalidLength($"Topic path `{topicPath}` exceeds maximum length of {topicPathMaximumLength} characters."); } return(validationResult ?? ValidationResult.Empty); }; } var subscriptionNameMaximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.SubscriptionNameMaximumLength); if (!settings.TryGet(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.SubscriptionNameValidator, out subscriptionNameValidation)) { subscriptionNameValidation = subscriptionName => { ValidationResult validationResult = null; if (!ValidateAndHashIfNeeded.subscriptionAndRuleNameValidationRegex.IsMatch(subscriptionName)) { validationResult = new ValidationResult(); validationResult.AddErrorForInvalidCharacters($"Subscription name {subscriptionName} contains illegal characters. Legal characters should match the following regex: `{ValidateAndHashIfNeeded.subscriptionAndRuleNameValidationRegex}`."); } if (subscriptionName.Length > subscriptionNameMaximumLength) { validationResult = validationResult ?? new ValidationResult(); validationResult.AddErrorForInvalidLength($"Subscription name `{subscriptionName}` exceeds maximum length of {subscriptionNameMaximumLength} characters."); } return(validationResult ?? ValidationResult.Empty); }; } var ruleNameMaximumLength = settings.GetOrDefault <int>(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.RuleNameMaximumLength); if (!settings.TryGet(WellKnownConfigurationKeys.Topology.Addressing.Sanitization.RuleNameValidator, out ruleNameValidation)) { ruleNameValidation = ruleName => { ValidationResult validationResult = null; if (!ValidateAndHashIfNeeded.subscriptionAndRuleNameValidationRegex.IsMatch(ruleName)) { validationResult = new ValidationResult(); validationResult.AddErrorForInvalidCharacters($"Rule name {ruleName} contains illegal characters. Legal characters should match the following regex: `{ValidateAndHashIfNeeded.subscriptionAndRuleNameValidationRegex}`."); } if (ruleName.Length > ruleNameMaximumLength) { validationResult = validationResult ?? new ValidationResult(); validationResult.AddErrorForInvalidLength($"Rule name `{ruleName}` exceeds maximum length of {ruleNameMaximumLength} characters."); } return(validationResult ?? ValidationResult.Empty); }; } }