aboutsummaryrefslogtreecommitdiffstats
path: root/openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/svc_util.lua
diff options
context:
space:
mode:
Diffstat (limited to 'openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/svc_util.lua')
-rw-r--r--openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/svc_util.lua93
1 files changed, 68 insertions, 25 deletions
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/svc_util.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/svc_util.lua
index 226e31f..ce65e14 100644
--- a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/svc_util.lua
+++ b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/svc_util.lua
@@ -1,6 +1,6 @@
--[[
- Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+ Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -22,19 +22,18 @@ _M._VERSION = '1.0.0'
local msbConf= require('conf.msbinit')
local svcConf = require('conf.svcconf')
local log_util = require('lib.utils.log_util')
+local bit = require("bit")
local log = log_util.log
-local ngx_var = ngx.var
-
-local defaultport = msbConf.systemConf.defaultport
-local defaulthttpsport = msbConf.systemConf.defaulthttpsport
-local defaultprefix = msbConf.systemConf.defaultprefix
-local router_subdomain = msbConf.routerConf.subdomain
-local router_defaultprefix = msbConf.routerConf.defaultprefix
local useconsultemplate = msbConf.systemConf.useconsultemplate
local urlfieldMap = svcConf.urlfieldMap
local apiRelatedTypes = svcConf.apiRelatedTypes
+local SYS_SCENARIO_FLAG = { -- cos router
+ ["ROUTER"] = 1, -- 0 1
+ ["COS"] = 2 -- 1 0
+}
+
function _M.isactive(svcinfo)
if svcinfo["status"] == "1" then
return true
@@ -65,32 +64,76 @@ function _M.get_backend_protocol(svcinfo)
end
end
-function _M.get_key_prefix()
- --now assemble the key prefix according the svc_name and server_port
- local key_prefix = ""
- local server_port = ngx_var.server_port
- local svc_name = ngx_var.svc_name
- if (svc_name == "microservices" or svc_name == "msdiscover") then
- key_prefix = defaultprefix
- elseif (server_port == defaultport or server_port == defaulthttpsport) then
- local m, err = ngx.re.match(ngx_var.host, "(?<hostname>.+)\\."..router_subdomain,"o")
- if m then
- key_prefix = router_defaultprefix..":"..m["hostname"]
+function _M.is_api_related_types(svc_type)
+ if(apiRelatedTypes[svc_type]) then
+ return true
+ else
+ return false
+ end
+end
+
+function _M.get_connect_timeout(svcinfo)
+ local connect_timeout = svcinfo.spec["connect_timeout"]
+ if connect_timeout then
+ connect_timeout = tonumber(connect_timeout)
+ if connect_timeout and connect_timeout<=0 then
+ ngx.log(ngx.WARN, ngx.var.request_id.." ".."bad connect timeout!Zero and negative timeout values are not allowed.Input value:"..connect_timeout)
+ return nil
else
- key_prefix = defaultprefix
+ return connect_timeout
end
else
- key_prefix = "msb:"..server_port
+ return nil
end
- return key_prefix
end
-function _M.is_api_related_types(svc_type)
- if(apiRelatedTypes[svc_type]) then
+function _M.get_send_timeout(svcinfo)
+ local send_timeout = svcinfo.spec["send_timeout"]
+ if send_timeout then
+ send_timeout = tonumber(send_timeout)
+ if send_timeout and send_timeout<=0 then
+ ngx.log(ngx.WARN, ngx.var.request_id.." ".."bad send timeout!Zero and negative timeout values are not allowed.Input value:"..send_timeout)
+ return nil
+ else
+ return send_timeout
+ end
+ else
+ return nil
+ end
+end
+
+function _M.get_read_timeout(svcinfo)
+ local read_timeout = svcinfo.spec["read_timeout"]
+ if read_timeout then
+ read_timeout = tonumber(read_timeout)
+ if read_timeout and read_timeout <= 0 then
+ ngx.log(ngx.WARN, ngx.var.request_id.." ".."bad send timeout!Zero and negative timeout values are not allowed.Input value:"..read_timeout)
+ return nil
+ else
+ return read_timeout
+ end
+ else
+ return nil
+ end
+end
+
+function _M.enable_refer_match(svcinfo)
+ local enable_refer_match = svcinfo.spec["enable_refer_match"]
+ --Be compatible with the old service info. If the field is not filled, the refer match is enabled by default.
+ if enable_refer_match == nil or enable_refer_match then
return true
else
return false
end
end
-return _M \ No newline at end of file
+function _M.is_allow_access(system_tag,svcinfo)
+ local scenario = svcinfo.spec["scenario"] or 1
+ local ok,res = pcall(function() return bit.band(SYS_SCENARIO_FLAG[system_tag], scenario) end)
+ if ok and res==SYS_SCENARIO_FLAG[system_tag] then
+ return true
+ else
+ return false
+ end
+end
+return _M