From bf5775b9ac23c9579da7a4688b310561d94916dd Mon Sep 17 00:00:00 2001 From: Navendu Pottekkat Date: Wed, 15 Nov 2023 17:46:19 +0530 Subject: [PATCH] only etcd not changed Signed-off-by: Navendu Pottekkat --- apisix/cli/schema.lua | 526 ++++++++++++++++++++++++++++++++---------- 1 file changed, 403 insertions(+), 123 deletions(-) diff --git a/apisix/cli/schema.lua b/apisix/cli/schema.lua index 5f6ec63f64dc7..3c45f97b8bceb 100644 --- a/apisix/cli/schema.lua +++ b/apisix/cli/schema.lua @@ -66,6 +66,67 @@ local etcd_schema = { required = {"prefix", "host"} } + +local admin_schema = { + type = "object", + properties = { + admin_key = { + type = "array", + properties = { + items = { + properties = { + name = { type = "string" }, + key = { type = "string" }, + role = { type = "string" }, + } + } + } + }, + admin_listen = { + properties = { + listen = { type = "string" }, + port = { type = "integer" }, + }, + default = { + listen = "0.0.0.0", + port = 9180, + } + }, + https_admin = { + type = "boolean", + }, + admin_key_required = { + type = "boolean", + }, + enable_admin_cors = { + type = "boolean" + }, + allow_admin = { + type = "array", + items = { + type = "string" + } + }, + admin_api_mtls = { + type = "object", + properties = { + admin_ssl_cert = { + type = "string" + }, + admin_ssl_cert_key = { + type = "string" + }, + admin_ssl_ca_cert = { + type = "string" + } + } + }, + admin_api_version = { + type = "string" + } + } +} + local config_schema = { type = "object", properties = { @@ -107,6 +168,30 @@ local config_schema = { } }, }, + enable_admin = { + type = "boolean", + }, + enable_dev_mode = { + type = "boolean", + }, + enable_reuseport = { + type = "boolean", + }, + show_upstream_status_in_response_header = { + type = "boolean", + }, + enable_ipv6 = { + type = "boolean", + }, + enable_server_tokens = { + type = "boolean", + }, + extra_lua_path = { + type = "string" + }, + extra_lua_cpath = { + type = "string" + }, lua_module_hook = { pattern = "^[a-zA-Z._-]+$", }, @@ -154,12 +239,12 @@ local config_schema = { }, oneOf = { { - required = {"name", "memory_size"}, + required = { "name", "memory_size" }, maxProperties = 2, }, { - required = {"name", "memory_size", "disk_size", - "disk_path", "cache_levels"}, + required = { "name", "memory_size", "disk_size", + "disk_path", "cache_levels" }, } }, }, @@ -167,9 +252,33 @@ local config_schema = { } } }, + delete_uri_tail_slash = { + type = "boolean", + }, + normalize_uri_like_servlet = { + type = "boolean", + }, + router = { + type = "object", + properties = { + http = { + type = "string", + enum = { "radixtree_host_uri", + "radixtree_uri", + "radixtree_uri_with_parameter" }, + }, + ssl = { + type = "string", + enum = { "radixtree_host_uri", + "radixtree_uri", + "radixtree_uri_with_parameter", + "radixtree_sni" }, + }, + } + }, proxy_mode = { type = "string", - enum = {"http", "stream", "http&stream"}, + enum = { "http", "stream", "http&stream" }, }, stream_proxy = { type = "object", @@ -202,7 +311,7 @@ local config_schema = { type = "boolean", } }, - required = {"addr"} + required = { "addr" } }, }, }, @@ -235,6 +344,12 @@ local config_schema = { dns_resolver_valid = { type = "integer", }, + resolver_timeout = { + type = "integer", + }, + enable_resolv_search_opt = { + type = "boolean", + }, ssl = { type = "object", properties = { @@ -282,18 +397,232 @@ local config_schema = { }, } }, + enable_control = { + type = "boolean", + }, + control = { + type = "object", + properties = { + ip = { + type = "string", + }, + port = { + type = "integer", + minimum = 1, + maximum = 65535 + }, + } + }, + data_encryption = { + type = "object", + properties = { + enable = { + type = "boolean", + }, + keyring = { + type = "array", + items = { + type = "string", + } + }, + } + }, nginx_config = { type = "object", properties = { + user = { + type = "string", + }, + error_log = { + type = "string", + }, + error_log_level = { + type = "string", + enum = { "info", "debug", "notice", "warn", "error", "crit", "alert", "emerg" } + }, + worker_processes = { + anyOf = { + { + type = "integer", + minimum = 1, + }, + { + type = "string" + }, + { + type = "string", + enum = { "auto" } + } + } + }, + enable_cpu_affinity = { + type = "boolean", + }, + worker_rlimit_nofile = { + type = "integer", + }, + worker_shutdown_timeout = { + type = "string", + }, + max_pending_timers = { + type = "integer", + }, + max_running_timers = { + type = "integer", + }, + event = { + type = "object", + properties = { + worker_connections = { + type = "integer" + }, + } + }, envs = { type = "array", minItems = 1, items = { type = "string", } + }, + meta = { + type = "object", + properties = { + lua_shared_dict = { + type = "object", + }, + } + }, + stream = { + type = "object", + properties = { + enable_access_log = { + type = "boolean", + }, + access_log = { + type = "string", + }, + access_log_format = { + type = "string", + }, + access_log_format_escape = { + type = "string", + }, + lua_shared_dict = { + type = "object", + }, + } + }, + main_configuration_snippet = { + type = "string" + }, + http_configuration_snippet = { + type = "string" + }, + http_server_configuration_snippet = { + type = "string" + }, + http_server_location_configuration_snippet = { + type = "string" + }, + http_admin_configuration_snippet = { + type = "string" + }, + http_end_configuration_snippet = { + type = "string" + }, + stream_configuration_snippet = { + type = "string" + }, + http = { + type = "object", + properties = { + enable_access_log = { + type = "boolean" + }, + access_log = { + type = "string" + }, + access_log_buffer = { + type = "integer" + }, + access_log_format = { + type = "string" + }, + access_log_format_escape = { + type = "string" + }, + keepalive_timeout = { + type = "string" + }, + client_header_timeout = { + type = "string" + }, + client_body_timeout = { + type = "string" + }, + client_max_body_size = { + anyOf = { + { + type = "number" + }, + { + type = "string" + } + } + }, + send_timeout = { + type = "string" + }, + underscores_in_headers = { + type = "string" + }, + real_ip_header = { + type = "string" + }, + real_ip_recursive = { + type = "string" + }, + real_ip_from = { + type = "array", + items = { + type = "string" + } + }, + custom_lua_shared_dict = { + type = "object" + }, + proxy_ssl_server_name = { + type = "boolean" + }, + upstream = { + type = "object", + properties = { + keepalive = { + type = "integer" + }, + keepalive_requests = { + type = "integer" + }, + keepalive_timeout = { + type = "string" + } + } + }, + charset = { + type = "string" + }, + variables_hash_max_size = { + type = "integer" + }, + lua_shared_dict = { + type = "object" + } + } } }, }, + -- TODO: Add schema for discovery http = { type = "object", properties = { @@ -302,6 +631,14 @@ local config_schema = { } } }, + graphql = { + type = "object", + properties = { + max_size = { + type = "integer" + } + } + }, etcd = etcd_schema, plugins = { type = "array", @@ -338,136 +675,87 @@ local config_schema = { type = "integer" }, http_request_phase = { - enum = {"access", "rewrite"}, + enum = { "access", "rewrite" }, default = "access", }, }, - required = {"name", "file", "priority"} + required = { "name", "file", "priority" } } } } }, + plugin_attr = { + type = "object" + }, deployment = { type = "object", properties = { role = { - enum = {"traditional", "control_plane", "data_plane", "standalone"}, + enum = { "traditional", "control_plane", "data_plane", "standalone" }, default = "traditional" - } + }, }, - }, - }, - required = {"apisix", "deployment"}, -} - -local admin_schema = { - type = "object", - properties = { - admin_key = { - type = "array", - properties = { - items = { - properties = { - name = { type = "string" }, - key = { type = "string" }, - role = { type = "string" }, + dependencies = { + role = { + oneOf = { + { + properties = { + role = { const = "traditional" }, + etcd = etcd_schema, + admin = admin_schema, + role_traditional = { + type = "object", + properties = { + config_provider = { + enum = { "etcd" } + }, + }, + required = { "config_provider" } + }, + }, + required = { "role_traditional" }, + }, + { + properties = { + role = { const = "control_plane" }, + etcd = etcd_schema, + admin = admin_schema, + role_control_plane = { + type = "object", + properties = { + config_provider = { + enum = { "etcd" } + }, + }, + required = { "config_provider" } + }, + }, + required = { "role_control_plane" }, + }, + { + properties = { + role = { const = "data_plane" }, + etcd = etcd_schema, + role_data_plane = { + type = "object", + properties = { + config_provider = { + enum = { "etcd", "yaml", "xds" } + }, + }, + required = { "config_provider" } + }, + }, + required = { "role_data_plane" }, + }, } } } }, - admin_listen = { - properties = { - listen = { type = "string" }, - port = { type = "integer" }, - }, - default = { - listen = "0.0.0.0", - port = 9180, - } - }, - https_admin = { - type = "boolean", - }, - admin_key_required = { - type = "boolean", - }, - enable_admin_cors = { - type = "boolean" - }, - allow_admin = { - type = "array", - items = { - type = "string" - } - }, - admin_api_mtls = { - type = "object", - properties = { - admin_ssl_cert = { - type = "string" - }, - admin_ssl_cert_key = { - type = "string" - }, - admin_ssl_ca_cert = { - type = "string" - } - } - }, - admin_api_version = { - type = "string" - } - } -} - -local deployment_schema = { - traditional = { - properties = { - etcd = etcd_schema, - admin = admin_schema, - role_traditional = { - properties = { - config_provider = { - enum = {"etcd"} - }, - }, - required = {"config_provider"} - } - }, - required = {"etcd"} - }, - control_plane = { - properties = { - etcd = etcd_schema, - admin = admin_schema, - role_control_plane = { - properties = { - config_provider = { - enum = {"etcd"} - }, - }, - required = {"config_provider"} - }, - }, - required = {"etcd", "role_control_plane"} }, - data_plane = { - properties = { - etcd = etcd_schema, - role_data_plane = { - properties = { - config_provider = { - enum = {"etcd", "yaml", "xds"} - }, - }, - required = {"config_provider"} - }, - }, - required = {"role_data_plane"} - } + required = { "apisix", "deployment" }, } - function _M.validate(yaml_conf) local validator = jsonschema.generate_validator(config_schema) local ok, err = validator(yaml_conf) @@ -488,15 +776,7 @@ function _M.validate(yaml_conf) end end - local role = yaml_conf.deployment.role - local validator = jsonschema.generate_validator(deployment_schema[role]) - local ok, err = validator(yaml_conf.deployment) - if not ok then - return false, "invalid deployment " .. role .. " configuration: " .. err - end - return true end - return _M