Initial code import
[msb/apigateway.git] / openresty-ext / src / assembly / resources / openresty / nginx / luaext / lib / utils / svc_util.lua
1 --[[\r
2 \r
3     Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
4 \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
8 \r
9             http://www.apache.org/licenses/LICENSE-2.0\r
10 \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
16 \r
17 --]]\r
18 \r
19 local _M = {}\r
20 _M._VERSION = '1.0.0'\r
21 \r
22 local tbl_util  = require('lib.utils.table_util')\r
23 local msbConf= require('conf.msbinit')\r
24 local log_util  =  require('lib.utils.log_util')\r
25 local tbl_isempty = tbl_util.isempty\r
26 local enableauthcheck = msbConf.systemConf.enableauthcheck\r
27 local log = log_util.log\r
28 \r
29 function _M.isactive(svcinfo)\r
30         if tbl_isempty(svcinfo) then\r
31                 return false\r
32         end\r
33         if svcinfo["status"] == "1" then\r
34                 return true\r
35         else\r
36                 return false\r
37         end\r
38 end\r
39 \r
40 function _M.isautodiscover(svcinfo)\r
41         if tbl_isempty(svcinfo) then\r
42                 return false\r
43         end\r
44         if svcinfo["autoDiscover"] == "1" then\r
45                 return true\r
46         else\r
47                 return false\r
48         end\r
49 end\r
50 \r
51 function _M.setauthheader(svcinfo)\r
52         --if auth check enabled and this service is inter-system then add sth\r
53         if enableauthcheck and svcinfo["visualRange"] == "0" then\r
54                 ngx.req.set_header("Z-EXTENT", "C012089CF43DE687B23B2C0176B344EE")\r
55                 log("add Z-EXTENT",true)\r
56         end\r
57 end\r
58 \r
59 return _M