Repository navigation
Expand file tree
/
Copy pathglobal.lua
More file actions
121 lines (83 loc) · 2.3 KB
/
Copy pathglobal.lua
File metadata and controls
121 lines (83 loc) · 2.3 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
-- TODO: get rid of 'kong.meta'; this module is king
local meta = require "kong.meta"
local PDK = require "kong.pdk"
local phase_checker = require "kong.pdk.private.phases"
local type = type
local setmetatable = setmetatable
local KONG_VERSION = tostring(meta._VERSION)
local KONG_VERSION_NUM = tonumber(string.format("%d%.2d%.2d",
meta._VERSION_TABLE.major * 100,
meta._VERSION_TABLE.minor * 10,
meta._VERSION_TABLE.patch))
-- Runloop interface
local _GLOBAL = {
phases = phase_checker.phases,
}
function _GLOBAL.new()
return {
version = KONG_VERSION,
version_num = KONG_VERSION_NUM,
pdk_major_version = nil,
pdk_version = nil,
configuration = nil,
}
end
function _GLOBAL.set_named_ctx(self, name, key)
if not self then
error("arg #1 cannot be nil", 2)
end
if type(name) ~= "string" then
error("name must be a string", 2)
end
if #name == 0 then
error("name cannot be an empty string", 2)
end
if not self.ctx then
error("ctx PDK module not initialized", 2)
end
self.ctx.keys[name] = key
end
function _GLOBAL.set_phase(self, phase)
if not self then
error("arg #1 cannot be nil", 2)
end
local kctx = self.ctx
if not kctx then
error("ctx SDK module not initialized", 2)
end
kctx.core.phase = phase
end
do
local log_facilities = {
core = nil,
namespaced = setmetatable({}, { __index = "k" }),
}
function _GLOBAL.set_namespaced_log(self, namespace)
if not self then
error("arg #1 cannot be nil", 2)
end
if type(namespace) ~= "string" then
error("namespace (arg #2) must be a string", 2)
end
local log = log_facilities.namespaced[namespace]
if not log then
log = self.log.new(namespace) -- use default namespaced format
log_facilities.namespaced[namespace] = log
end
self.log = log
end
function _GLOBAL.reset_log(self)
if not self then
error("arg #1 cannot be nil", 2)
end
self.log = log_facilities.core
end
function _GLOBAL.init_pdk(self, kong_config, pdk_major_version)
if not self then
error("arg #1 cannot be nil", 2)
end
PDK.new(kong_config, pdk_major_version, self)
log_facilities.core = self.log
end
end
return _GLOBAL