Example #1
0
        public override Task Validate(ICollection <string> errorMessages)
        {
            if (IsNullOrEmpty(Protocols) || Protocols.Any(string.IsNullOrWhiteSpace))
            {
                errorMessages.Add("Route Protocols cannot be null or contain null or empty values");
            }

            if (IsNullOrEmpty(Hosts) && IsNullOrEmpty(Methods) && IsNullOrEmpty(Paths))
            {
                errorMessages.Add("At least one of 'hosts', 'methods', or 'paths' must be set");
                return(Task.CompletedTask);
            }

            if (Hosts?.Any(string.IsNullOrWhiteSpace) == true)
            {
                errorMessages.Add("Route Hosts cannot contain null or empty values");
            }

            if (Methods?.Any(string.IsNullOrWhiteSpace) == true)
            {
                errorMessages.Add("Route Methods cannot contain null or empty values");
            }

            if (Paths?.Any(string.IsNullOrWhiteSpace) == true)
            {
                errorMessages.Add("Route Paths cannot contain null or empty values");
            }

            return(Task.CompletedTask);
        }
Example #2
0
        public virtual async Task Validate(IReadOnlyCollection <string> availablePlugins, ICollection <string> errorMessages)
        {
            if (IsNullOrEmpty(Protocols) || Protocols.Any(x => !new[] { "http", "https" }.Contains(x)))
            {
                errorMessages.Add("Route Protocols is invalid (must contain one or both of 'http' or 'https').");
            }

            if (IsNullOrEmpty(Hosts) && IsNullOrEmpty(Methods) && IsNullOrEmpty(Paths))
            {
                errorMessages.Add("At least one of Route 'Hosts', 'Methods', or 'Paths' must be set.");
            }

            if (Hosts == null || Hosts.Any(x => string.IsNullOrWhiteSpace(x) || Uri.CheckHostName(x) == UriHostNameType.Unknown))
            {
                errorMessages.Add("Route Hosts is invalid (cannot be null, or contain null, empty or invalid values).");
            }

            if (Methods == null || Methods.Any(string.IsNullOrWhiteSpace))
            {
                errorMessages.Add("Route Methods is invalid (cannot be null, or contain null or empty values).");
            }

            if (Paths == null || Paths.Any(x => string.IsNullOrWhiteSpace(x) || !Uri.IsWellFormedUriString(x, UriKind.Relative)))
            {
                errorMessages.Add("Route Paths is invalid (cannot be null, or contain null, empty or invalid values).");
            }

            await ValidatePlugins(availablePlugins, errorMessages);
        }
Example #3
0
        public virtual async Task Validate(IDictionary <string, AsyncLazy <KongPluginSchema> > availablePlugins, ICollection <string> errorMessages)
        {
            if (IsNullOrEmpty(Protocols) || Protocols.Any(x => !AllowedProtocols.Contains(x)))
            {
                errorMessages.Add("Route Protocols is invalid (must contain one or both of 'http' or 'https').");
            }

            if (IsNullOrEmpty(Hosts) && IsNullOrEmpty(Methods) && IsNullOrEmpty(Paths))
            {
                errorMessages.Add("At least one of Route 'Hosts', 'Methods', or 'Paths' must be set.");
            }

            if (Hosts?.Any(string.IsNullOrWhiteSpace) == true)
            {
                errorMessages.Add("Route Hosts is invalid (cannot contain null or empty values).");
            }
            if (Hosts?.Any(x => !string.IsNullOrWhiteSpace(x) && x.StartsWith("*.") && x.EndsWith(".*")) == true)
            {
                errorMessages.Add("Route Hosts is invalid (values cannot begin and end with a wildcard, only one wildcard at the start or end is allowed).");
            }
            if (Hosts?.Any(x => !string.IsNullOrWhiteSpace(x) && Uri.CheckHostName(RemoveWildcards(x)) == UriHostNameType.Unknown) == true)
            {
                errorMessages.Add("Route Hosts is invalid (values must be valid hostnames or IP addresses, with a single optional wildcard at the start or end).");
            }

            if (Methods?.Any(string.IsNullOrWhiteSpace) == true)
            {
                errorMessages.Add("Route Methods is invalid (cannot contain null or empty values).");
            }

            if (Paths?.Any(string.IsNullOrWhiteSpace) == true)
            {
                errorMessages.Add("Route Paths is invalid (cannot contain null or empty values).");
            }

            if (Paths?.Any(x => !string.IsNullOrWhiteSpace(x) && !x.StartsWith('/')) == true)
            {
                errorMessages.Add("Route Paths is invalid (values must start with '/').");
            }

            await ValidatePlugins(availablePlugins, errorMessages);
        }