Beispiel #1
0
        public async Task Validate(IDictionary <string, AsyncLazy <KongSchema> > schemas, ICollection <string> errorMessages, KongObject parent = null)
        {
            var schemaPath = $"plugins/{Name}";

            if (!schemas.ContainsKey(schemaPath))
            {
                errorMessages.Add($"{KongSchema.Violation<KongPlugin>()} (plugin '{Name}' is not available on Kong server).");
                return;
            }

            var schema         = await schemas[schemaPath].Task;
            var baseSchema     = await schemas["plugins"].Task;
            var fallbackFields = baseSchema.Fields.Where(b => schema.Fields.All(f => f.Name != b.Name)).ToArray();

            if (fallbackFields.Any())
            {
                schema.Fields = schema.Fields.Concat(fallbackFields).ToArray();
            }

            var node = JObject.FromObject(this);

            schema.Validate <KongPlugin>(node, errorMessages, parent);
            RunOn     = node["run_on"].Value <string>();
            Protocols = node["protocols"].Values <string>();
        }
Beispiel #2
0
 private async Task ValidateRoutes(IDictionary <string, AsyncLazy <KongSchema> > schemas, ICollection <string> errorMessages)
 {
     if (Routes == null || !Routes.Any())
     {
         errorMessages.Add($"{KongSchema.Violation<KongService>()} (routes cannot be null or empty).");
         return;
     }
     foreach (var route in Routes)
     {
         await route.Validate(schemas, errorMessages, this);
     }
 }
Beispiel #3
0
 private async Task ValidatePlugins(IDictionary <string, AsyncLazy <KongSchema> > schemas, ICollection <string> errorMessages)
 {
     if (Plugins == null)
     {
         errorMessages.Add($"{KongSchema.Violation<KongService>()} (plugins cannot be null).");
         return;
     }
     foreach (var plugin in Plugins)
     {
         await plugin.Validate(schemas, errorMessages, this);
     }
 }
Beispiel #4
0
        public async Task Validate(IDictionary <string, AsyncLazy <KongSchema> > schemas, ICollection <string> errorMessages, KongObject parent = null)
        {
            var schema = await schemas["consumers"].Task;
            var node   = JObject.FromObject(this);

            node.Property("plugins")?.Remove();
            if (Username == null && CustomId == null)
            {
                errorMessages.Add($"{KongSchema.Violation<KongConsumer>()} (at least one of 'username, custom_id' must be set).");
            }
            schema.Validate <KongConsumer>(node, errorMessages, parent);

            await ValidatePlugins(schemas, errorMessages);
        }
Beispiel #5
0
        public async Task Validate(IDictionary <string, AsyncLazy <KongSchema> > schemas, ICollection <string> errorMessages, KongObject parent = null)
        {
            var schema = await schemas["routes"].Task;
            var node   = JObject.FromObject(this);

            node.Property("plugins")?.Remove();
            if (Protocols != null)
            {
                if (Protocols.Contains("http") && Methods == null && Hosts == null && Headers == null && Paths == null)
                {
                    errorMessages.Add($"{KongSchema.Violation<KongRoute>()} (at least one of 'methods, hosts, headers, paths' must be set).");
                }
                else if (Protocols.Contains("https") && Methods == null && Hosts == null && Headers == null && Paths == null && Snis == null)
                {
                    errorMessages.Add($"{KongSchema.Violation<KongRoute>()} (at least one of 'methods, hosts, headers, paths, snis' must be set).");
                }
                else if (Protocols.Contains("tcp") && Sources == null && Destinations == null)
                {
                    errorMessages.Add($"{KongSchema.Violation<KongRoute>()} (at least one of 'sources, destinations' must be set).");
                }
                else if (Protocols.Contains("tls") && Sources == null && Destinations == null && Snis == null)
                {
                    errorMessages.Add($"{KongSchema.Violation<KongRoute>()} (at least one of 'sources, destinations, snis' must be set).");
                }
                else if (Protocols.Contains("grpc") && Hosts == null && Headers == null && Paths == null)
                {
                    errorMessages.Add($"{KongSchema.Violation<KongRoute>()} (at least one of 'hosts, headers, paths' must be set).");
                }
                else if (Protocols.Contains("grpcs") && Hosts == null && Headers == null && Paths == null && Snis == null)
                {
                    errorMessages.Add($"{KongSchema.Violation<KongRoute>()} (at least one of 'hosts, headers, paths, snis' must be set).");
                }
            }
            schema.Validate <KongRoute>(node, errorMessages, parent);

            await ValidatePlugins(schemas, errorMessages);
        }