forked from CNSRE/ABTestingGateway
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathaction.lua
83 lines (72 loc) · 2.25 KB
/
action.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
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
local policyModule = require('abtesting.adapter.policy')
local redisModule = require('abtesting.utils.redis')
local systemConf = require('abtesting.utils.init')
local handler = require('abtesting.error.handler').handler
local utils = require('abtesting.utils.utils')
local ERRORINFO = require('abtesting.error.errcode').info
local cjson = require('cjson.safe')
local doresp = utils.doresp
local dolog = utils.dolog
local redisConf = systemConf.redisConf
local divtypes = systemConf.divtypes
local prefixConf = systemConf.prefixConf
local policyLib = prefixConf.policyLibPrefix
local runtimeLib = prefixConf.runtimeInfoPrefix
local domain_name = prefixConf.domainname
local policy = require("admin/policy")
local runtime = require('admin/runtime')
local ab_action = {}
ab_action.policy_check = policy.check
ab_action.policy_set = policy.set
ab_action.policy_get = policy.get
ab_action.policy_del = policy.del
ab_action.runtime_set = runtime.set
ab_action.runtime_del = runtime.del
ab_action.runtime_get = runtime.get
local get_uriargs_error = function()
local info = ERRORINFO.ACTION_BLANK_ERROR
local response = doresp(info, 'user req')
dolog(info, desc)
ngx.say(response)
return
end
local get_action_error = function()
local info = ERRORINFO.ACTION_BLANK_ERROR
local response = doresp(info, 'user req')
dolog(info, desc)
ngx.say(response)
return
end
local do_action_error = function()
local info = ERRORINFO.DOACTION_ERROR
local desc = action
local response = doresp(info, desc)
dolog(info, desc)
ngx.say(response)
return
end
local red = redisModule:new(redisConf)
local ok, err = red:connectdb()
if not ok then
local info = ERRORINFO.REDIS_CONNECT_ERROR
local response = doresp(info, err)
dolog(info, desc)
ngx.say(response)
return
end
local args = ngx.req.get_uri_args()
if args then
local action = args.action
local do_action = ab_action[action]
if do_action then
do_action({['db']=red})
-- local ok, info = do_action(policy, {['db']=red})
-- if not ok then
-- do_action_error()
-- end
else
doaction_error()
end
else
get_uriargs_error()
end