/// <summary> /// Validates the settings. /// </summary> /// <param name="context">The validation context.</param> /// <param name="rule">The parent rule.</param> public void Validate(TrafficValidationContext context, TrafficHttpRule rule) { if (DnsTTL < 1) { context.Error($"[{nameof(TrafficHttpCache)}.{nameof(DnsTTL)}={DnsTTL}] cannot be less than 1 second."); } WarmTargets = WarmTargets ?? new List <TrafficWarmTarget>(); // Verify that each warm target has valid properties and that they // all match at one of the rule frontends. foreach (var target in WarmTargets) { target.Validate(context); if (rule.GetFrontendForWarmTarget(target) == null) { context.Error($"Rule [{rule.Name}] includes the [{target.Uri}] cache warming target which cannot be mapped to a rule frontend."); } } }
/// <summary> /// Validates the frontend. /// </summary> /// <param name="context">The validation context.</param> /// <param name="rule">The parent rule.</param> public void Validate(TrafficValidationContext context, TrafficHttpRule rule) { base.Validate(context, rule); if (rule.Frontends.Count > 1 || !string.IsNullOrEmpty(CertName) || ProxyPort == 0 || ProxyPort == HiveHostPorts.ProxyPublicHttp || ProxyPort == HiveHostPorts.ProxyPublicHttps || ProxyPort == HiveHostPorts.ProxyPrivateHttp || ProxyPort == HiveHostPorts.ProxyPrivateHttps) { // The hostname is required so verify it. if (string.IsNullOrEmpty(Host)) { context.Error($"Rule [{rule.Name}] has a frontend without a [{nameof(Host)}] specified. HTTP rules targeting the default traffic manager HTTP/S ports, with more than one frontend, or secured by TLS requires frontend hostnames."); } else if (!HiveDefinition.DnsHostRegex.IsMatch(Host)) { context.Error($"Rule [{rule.Name}] defines the invalid hostname [{Host}]."); } } else { // The hostname is not required but verify it if one is specified. if (!string.IsNullOrEmpty(Host) && !HiveDefinition.DnsHostRegex.IsMatch(Host)) { context.Error($"Rule [{rule.Name}] defines the invalid hostname [{Host}]."); } } if (!string.IsNullOrEmpty(PathPrefix)) { if (!PathPrefix.StartsWith("/")) { context.Error($"Rule [{rule.Name}] references has [{nameof(PathPrefix)}={PathPrefix}] that does not begin with a forward slash."); } else { if (!PathPrefix.EndsWith("/")) { PathPrefix += "/"; } if (!Uri.TryCreate(PathPrefix, UriKind.Relative, out Uri uri)) { context.Error($"Rule [{rule.Name}] references has [{nameof(PathPrefix)}={PathPrefix}] that is not a valid relative URI."); } } } if (CertName != null && context.ValidateCertificates) { TlsCertificate certificate; if (!context.Certificates.TryGetValue(CertName, out certificate)) { context.Error($"Rule [{rule.Name}] references certificate [{CertName}] that does not exist or could not be loaded."); } else { if (!certificate.IsValidHost(Host)) { context.Error($"Rule [{rule.Name}] references certificate [{CertName}] which does not cover host [{Host}]."); } if (!certificate.IsValidDate(DateTime.UtcNow)) { context.Error($"Rule [{rule.Name}] references certificate [{CertName}] which expired on [{certificate.ValidUntil}]."); } } } if (ProxyPort != 0) { if (!context.Settings.ProxyPorts.IsValidPort(ProxyPort)) { context.Error($"Rule [{rule.Name}] assigns [{nameof(ProxyPort)}={ProxyPort}] which is outside the range of valid frontend ports for this traffic manager [{context.Settings.ProxyPorts}]."); } } else { if (CertName == null) { ProxyPort = context.Settings.DefaultHttpPort; } else { ProxyPort = context.Settings.DefaultHttpsPort; } } if (PublicPort == -1) { if (CertName == null) { PublicPort = NetworkPorts.HTTP; } else { PublicPort = NetworkPorts.HTTPS; } } if (PublicPort > 0 && !NetHelper.IsValidPort(PublicPort)) { context.Error($"Load balancer [{nameof(PublicPort)}={PublicPort}] is not a valid network port."); } if (RedirectTo != null) { // Strip off the path/query part of the URI, if necessary. if (RedirectTo.PathAndQuery != "/") { RedirectTo = new Uri($"{RedirectTo.Scheme}://{RedirectTo.Host}:{RedirectTo.Port}/"); } } }
/// <summary> /// Validates the backend. /// </summary> /// <param name="context">The validation context.</param> /// <param name="rule">The parent rule.</param> public void Validate(TrafficValidationContext context, TrafficHttpRule rule) { base.Validate(context, rule.Name); }