3 Copyright (C) 2016 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
26 local log = log_util.log
\r
27 local ngx_var = ngx.var
\r
29 local defaultport = msbConf.systemConf.defaultport
\r
30 local defaulthttpsport = msbConf.systemConf.defaulthttpsport
\r
31 local defaultprefix = msbConf.systemConf.defaultprefix
\r
32 local router_subdomain = msbConf.routerConf.subdomain
\r
33 local router_defaultprefix = msbConf.routerConf.defaultprefix
\r
34 local useconsultemplate = msbConf.systemConf.useconsultemplate
\r
35 local urlfieldMap = svcConf.urlfieldMap
\r
36 local apiRelatedTypes = svcConf.apiRelatedTypes
\r
38 function _M.isactive(svcinfo)
\r
39 if svcinfo["status"] == "1" then
\r
46 function _M.use_own_upstream(svcinfo)
\r
47 if useconsultemplate and svcinfo.spec.useOwnUpstream == "1" then
\r
48 log("useOwnUpstream",true)
\r
55 function _M.get_url(svcinfo,svc_type)
\r
56 return svcinfo.spec[urlfieldMap[svc_type]]
\r
59 function _M.get_backend_protocol(svcinfo)
\r
60 local svc_enable_ssl = svcinfo.spec["enable_ssl"]
\r
61 if svc_enable_ssl then
\r
68 function _M.get_key_prefix()
\r
69 --now assemble the key prefix according the svc_name and server_port
\r
70 local key_prefix = ""
\r
71 local server_port = ngx_var.server_port
\r
72 local svc_name = ngx_var.svc_name
\r
73 if (svc_name == "microservices" or svc_name == "msdiscover") then
\r
74 key_prefix = defaultprefix
\r
75 elseif (server_port == defaultport or server_port == defaulthttpsport) then
\r
76 local m, err = ngx.re.match(ngx_var.host, "(?<hostname>.+)\\."..router_subdomain,"o")
\r
78 key_prefix = router_defaultprefix..":"..m["hostname"]
\r
80 key_prefix = defaultprefix
\r
83 key_prefix = "msb:"..server_port
\r
88 function _M.is_api_related_types(svc_type)
\r
89 if(apiRelatedTypes[svc_type]) then
\r