3 Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)
\r
5 Licensed under the Apache License, Version 2.0 (the "License");
\r
6 you may not use this file except in compliance with the License.
\r
7 You may obtain a copy of the License at
\r
9 http://www.apache.org/licenses/LICENSE-2.0
\r
11 Unless required by applicable law or agreed to in writing, software
\r
12 distributed under the License is distributed on an "AS IS" BASIS,
\r
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 See the License for the specific language governing permissions and
\r
15 limitations under the License.
\r
20 _M._VERSION = '1.0.0'
\r
22 local msbConf= require('conf.msbinit')
\r
23 local svcConf = require('conf.svcconf')
\r
24 local log_util = require('lib.utils.log_util')
\r
25 local bit = require("bit")
\r
27 local log = log_util.log
\r
28 local useconsultemplate = msbConf.systemConf.useconsultemplate
\r
29 local urlfieldMap = svcConf.urlfieldMap
\r
30 local apiRelatedTypes = svcConf.apiRelatedTypes
\r
32 local SYS_SCENARIO_FLAG = { -- cos router
\r
33 ["ROUTER"] = 1, -- 0 1
\r
37 function _M.isactive(svcinfo)
\r
38 if svcinfo["status"] == "1" then
\r
45 function _M.use_own_upstream(svcinfo)
\r
46 if useconsultemplate and svcinfo.spec.useOwnUpstream == "1" then
\r
47 log("useOwnUpstream",true)
\r
54 function _M.get_url(svcinfo,svc_type)
\r
55 return svcinfo.spec[urlfieldMap[svc_type]]
\r
58 function _M.get_backend_protocol(svcinfo)
\r
59 local svc_enable_ssl = svcinfo.spec["enable_ssl"]
\r
60 if svc_enable_ssl then
\r
67 function _M.is_api_related_types(svc_type)
\r
68 if(apiRelatedTypes[svc_type]) then
\r
75 function _M.get_connect_timeout(svcinfo)
\r
76 local connect_timeout = svcinfo.spec["connect_timeout"]
\r
77 if connect_timeout then
\r
78 connect_timeout = tonumber(connect_timeout)
\r
79 if connect_timeout and connect_timeout<=0 then
\r
80 ngx.log(ngx.WARN, ngx.var.request_id.." ".."bad connect timeout!Zero and negative timeout values are not allowed.Input value:"..connect_timeout)
\r
83 return connect_timeout
\r
90 function _M.get_send_timeout(svcinfo)
\r
91 local send_timeout = svcinfo.spec["send_timeout"]
\r
92 if send_timeout then
\r
93 send_timeout = tonumber(send_timeout)
\r
94 if send_timeout and send_timeout<=0 then
\r
95 ngx.log(ngx.WARN, ngx.var.request_id.." ".."bad send timeout!Zero and negative timeout values are not allowed.Input value:"..send_timeout)
\r
105 function _M.get_read_timeout(svcinfo)
\r
106 local read_timeout = svcinfo.spec["read_timeout"]
\r
107 if read_timeout then
\r
108 read_timeout = tonumber(read_timeout)
\r
109 if read_timeout and read_timeout <= 0 then
\r
110 ngx.log(ngx.WARN, ngx.var.request_id.." ".."bad send timeout!Zero and negative timeout values are not allowed.Input value:"..read_timeout)
\r
113 return read_timeout
\r
120 function _M.enable_refer_match(svcinfo)
\r
121 local enable_refer_match = svcinfo.spec["enable_refer_match"]
\r
122 --Be compatible with the old service info. If the field is not filled, the refer match is enabled by default.
\r
123 if enable_refer_match == nil or enable_refer_match then
\r
130 function _M.is_allow_access(system_tag,svcinfo)
\r
131 local scenario = svcinfo.spec["scenario"] or 1
\r
132 local ok,res = pcall(function() return bit.band(SYS_SCENARIO_FLAG[system_tag], scenario) end)
\r
133 if ok and res==SYS_SCENARIO_FLAG[system_tag] then
\r