-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schemas) move plugins schemas to new dao
- Loading branch information
Showing
28 changed files
with
816 additions
and
1,090 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
local Errors = require "kong.dao.errors" | ||
local typedefs = require "kong.db.schema.typedefs" | ||
|
||
|
||
return { | ||
no_consumer = true, | ||
name = "acl", | ||
fields = { | ||
whitelist = { type = "array" }, | ||
blacklist = { type = "array" }, | ||
hide_groups_header = { type = "boolean", default = false }, | ||
{ consumer = typedefs.no_consumer }, | ||
{ config = { | ||
type = "record", | ||
nullable = false, | ||
fields = { | ||
{ whitelist = { type = "array", elements = { type = "string" }, }, }, | ||
{ blacklist = { type = "array", elements = { type = "string" }, }, }, | ||
{ hide_groups_header = { type = "boolean", default = false }, }, | ||
} | ||
} | ||
} | ||
}, | ||
entity_checks = { | ||
{ only_one_of = { "config.whitelist", "config.blacklist" }, }, | ||
{ at_least_one_of = { "config.whitelist", "config.blacklist" }, }, | ||
}, | ||
self_check = function(schema, plugin_t, dao, is_update) | ||
if next(plugin_t.whitelist or {}) and next(plugin_t.blacklist or {}) then | ||
return false, Errors.schema "You cannot set both a whitelist and a blacklist" | ||
elseif not (next(plugin_t.whitelist or {}) or next(plugin_t.blacklist or {})) then | ||
return false, Errors.schema "You must set at least a whitelist or blacklist" | ||
end | ||
return true | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,49 @@ | ||
local function check_status(status) | ||
if status and (status < 100 or status > 999) then | ||
return false, "unhandled_status must be within 100 - 999." | ||
end | ||
local REGIONS = { | ||
"ap-northeast-1", "ap-northeast-2", | ||
"ap-south-1", | ||
"ap-southeast-1", "ap-southeast-2", | ||
"ca-central-1", | ||
"eu-central-1", | ||
"eu-west-1", "eu-west-2", | ||
"sa-east-1", | ||
"us-east-1", "us-east-2", | ||
"us-gov-west-1", | ||
"us-west-1", "us-west-2", | ||
} | ||
|
||
return true | ||
end | ||
|
||
return { | ||
name = "aws-lambda", | ||
fields = { | ||
timeout = { | ||
type = "number", | ||
default = 60000, | ||
required = true, | ||
}, | ||
keepalive = { | ||
type = "number", | ||
default = 60000, | ||
required = true, | ||
}, | ||
aws_key = { | ||
type = "string", | ||
required = true, | ||
}, | ||
aws_secret = { | ||
type = "string", | ||
required = true, | ||
}, | ||
aws_region = { | ||
type = "string", | ||
required = true, | ||
enum = { | ||
"us-east-1", | ||
"us-east-2", | ||
"us-west-1", | ||
"us-west-2", | ||
"us-gov-west-1", | ||
"ap-northeast-1", | ||
"ap-northeast-2", | ||
"ap-southeast-1", | ||
"ap-southeast-2", | ||
"ap-south-1", | ||
"ca-central-1", | ||
"eu-central-1", | ||
"eu-west-1", | ||
"eu-west-2", | ||
"sa-east-1", | ||
}, | ||
}, | ||
function_name = { | ||
type= "string", | ||
required = true, | ||
}, | ||
qualifier = { | ||
type = "string", | ||
}, | ||
invocation_type = { | ||
type = "string", | ||
required = true, | ||
default = "RequestResponse", | ||
enum = { | ||
"RequestResponse", | ||
"Event", | ||
"DryRun", | ||
} | ||
}, | ||
log_type = { | ||
type = "string", | ||
required = true, | ||
default = "Tail", | ||
enum = { | ||
"Tail", | ||
"None", | ||
} | ||
}, | ||
port = { | ||
type = "number", | ||
default = 443, | ||
}, | ||
unhandled_status = { | ||
type = "number", | ||
func = check_status, | ||
}, | ||
forward_request_method = { | ||
type = "boolean", | ||
default = false, | ||
}, | ||
forward_request_uri = { | ||
type = "boolean", | ||
default = false, | ||
}, | ||
forward_request_headers = { | ||
type = "boolean", | ||
default = false, | ||
}, | ||
forward_request_body = { | ||
type = "boolean", | ||
default = false, | ||
}, | ||
{ config = { | ||
type = "record", | ||
nullable = false, | ||
fields = { | ||
{ timeout = { type = "number", required = true, default = 60000 }, }, | ||
{ keepalive = { type = "number", required = true, default = 60000 }, }, | ||
{ aws_key = { type = "string", required = true }, }, | ||
{ aws_secret = { type = "string", required = true }, }, | ||
{ aws_region = { type = "string", required = true, one_of = REGIONS }, }, | ||
{ function_name = { type= "string", required = true }, }, | ||
{ qualifier = { type = "string" }, }, | ||
{ invocation_type = { | ||
type = "string", | ||
required = true, | ||
default = "RequestResponse", | ||
one_of = { "RequestResponse", "Event", "DryRun" }, | ||
}, }, | ||
{ log_type = { | ||
type = "string", | ||
required = true, | ||
default = "Tail", | ||
one_of = { "Tail", "None" }, | ||
}, }, | ||
{ port = { type = "integer", default = 443 }, }, | ||
{ unhandled_status = { type = "integer", between = { 100, 999 }, }, }, | ||
{ forward_request_method = { type = "boolean", default = false }, }, | ||
{ forward_request_uri = { type = "boolean", default = false }, }, | ||
{ forward_request_headers = { type = "boolean", default = false }, }, | ||
{ forward_request_body = { type = "boolean", default = false }, }, | ||
}, }, }, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
local utils = require "kong.tools.utils" | ||
|
||
local function check_user(anonymous) | ||
if anonymous == "" or utils.is_valid_uuid(anonymous) then | ||
return true | ||
end | ||
|
||
return false, "the anonymous user must be empty or a valid uuid" | ||
end | ||
local typedefs = require "kong.db.schema.typedefs" | ||
|
||
return { | ||
no_consumer = true, | ||
name = "basic-auth", | ||
fields = { | ||
anonymous = {type = "string", default = "", func = check_user}, | ||
hide_credentials = {type = "boolean", default = false} | ||
} | ||
{ consumer = typedefs.no_consumer }, | ||
{ config = { | ||
type = "record", | ||
nullable = false, | ||
fields = { | ||
{ anonymous = { type = "string", uuid = true, len_min = 0 }, }, | ||
{ hide_credentials = { type = "boolean", default = false }, }, | ||
}, }, }, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,23 @@ | ||
local re_match = ngx.re.match | ||
|
||
local check_regex = function(value) | ||
if value then | ||
for _, rule in ipairs(value) do | ||
local _, err = re_match("just a string to test", rule) | ||
if err then | ||
return false, "value '" .. rule .. "' is not a valid regex" | ||
end | ||
end | ||
end | ||
return true | ||
end | ||
local typedefs = require "kong.db.schema.typedefs" | ||
|
||
return { | ||
no_consumer = true, | ||
name = "bot-detection", | ||
fields = { | ||
whitelist = { | ||
type = "array", | ||
func = check_regex, | ||
new_type = { | ||
type = "array", | ||
elements = { | ||
type = "string", | ||
match = ".*", | ||
is_regex = true, | ||
}, | ||
default = {}, | ||
} | ||
}, | ||
blacklist = { | ||
type = "array", | ||
func = check_regex, | ||
new_type = { | ||
type = "array", | ||
elements = { | ||
type = "string", | ||
is_regex = true, | ||
}, | ||
default = {}, | ||
} | ||
}, | ||
} | ||
{ consumer = typedefs.no_consumer }, | ||
{ config = { | ||
type = "record", | ||
nullable = false, | ||
fields = { | ||
{ whitelist = { | ||
type = "array", | ||
elements = { type = "string", is_regex = true, match = ".*" }, | ||
default = {}, | ||
}, }, | ||
{ blacklist = { | ||
type = "array", | ||
elements = { type = "string", is_regex = true }, | ||
default = {}, | ||
}, }, | ||
}, }, }, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
return { | ||
name = "correlation-id", | ||
fields = { | ||
header_name = { | ||
type = "string", | ||
default = "Kong-Request-ID" | ||
config = { | ||
type = "record", | ||
nullable = false, | ||
fields = { | ||
{ header_name = { type = "string", default = "Kong-Request-ID" }, }, | ||
{ generator = { type = "string", default = "uuid#counter", | ||
one_of = { "uuid", "uuid#counter", "tracker" }, }, }, | ||
{ echo_downstream = { type = "boolean", default = false, }, }, | ||
}, | ||
}, | ||
generator = { | ||
type = "string", | ||
default = "uuid#counter", | ||
enum = {"uuid", "uuid#counter", "tracker"} | ||
}, | ||
echo_downstream = { | ||
type = "boolean", | ||
default = false | ||
} | ||
} | ||
}, | ||
} |
Oops, something went wrong.