-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.lua
56 lines (49 loc) · 1.12 KB
/
schema.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local typedefs = require "kong.db.schema.typedefs"
local is_present = function(v)
return type(v) == "string" and #v > 0
end
local status_code = {
type = "integer",
default = 301,
between = { 301, 302 },
}
local string = {
type = "string"
}
local dynamic_configuration = {
type = "record",
fields = {
{ pattern = string },
{ replacement = string },
{ redirect_code = status_code },
{ redirect_domain = string }
},
}
local static_configuration = {
type = "record",
fields = {
{ redirect_code = status_code },
{ redirect_url = string }
},
}
return {
name = "kong-dynamic-redirect",
fields = {
{ protocols = typedefs.protocols_http },
{ config = {
type = "record",
fields = {
{ dynamic = dynamic_configuration },
{ static = static_configuration }
},
custom_validator = function(config)
if is_present(config.dynamic)
and is_present(config.static) then
return nil, "Cannot use both static and dynamic configs at the same time!"
end
return true
end,
},
},
},
}