summaryrefslogtreecommitdiffstats
path: root/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext
diff options
context:
space:
mode:
Diffstat (limited to 'msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext')
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/customrouter.lua187
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/execute_auth.lua25
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msbconf.lua26
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoadminrouter.lua110
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoapijsonrouter.lua110
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoapirouter.lua117
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openouirouter.lua115
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/auth.lua171
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/driver_manager.lua127
-rw-r--r--msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/setnocacheflag.lua29
10 files changed, 0 insertions, 1017 deletions
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/customrouter.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/customrouter.lua
deleted file mode 100644
index 46d0b8a..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/customrouter.lua
+++ /dev/null
@@ -1,187 +0,0 @@
---[[
-
- Copyright 2016 ZTE Corporation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Author: Zhaoxing Meng
- email: meng.zhaoxing1@zte.com.cn
-
-]]
--- put red into the connection pool of size 100,
--- with 10 seconds max idle time
-local function close_redis(red)
- if not red then
- return
- end
- --release connection to the pool
- local pool_max_idle_time = 10000
- local pool_size = 100
- local ok, err = red:set_keepalive(pool_max_idle_time, pool_size)
- if not ok then
- ngx.log(ngx.ERR, "set keepalive error:", err)
- end
- return
-end
-
-local function query_ipurl_updatecache(red,key)
- local keyprefix = "msb:routing:custom:"..key
-
-
- local infokey=keyprefix..":info"
- -- first of all check whether the status is 1(enabled)
- local status = red:hget(infokey,"status")
- if not (status=="1") then
- ngx.log(ngx.WARN, key.."is disabled.status=", status)
- return nil
- end
-
- -- Try to get url for key
- local url, err = red:hget(infokey,"url")
- ngx.log(ngx.WARN, "==url:", url)
- if not url or url == ngx.null then
- return nil
- end
-
- -- Try to get ip:port for key
- local serverkey=keyprefix..":lb:server1"
- local server, err = red:hget(serverkey,"ip")..":"..red:hget(serverkey,"port")
- ngx.log(ngx.WARN, "==server:", server)
- if not server or server == ngx.null then
- return nil
- end
-
- -- get the local cache
- local cache = ngx.shared.ceryx
- local uri = ngx.var.uri
- -- Save found key to local cache for 5 seconds
- cache:set("custom:key:"..uri,key,5)
- cache:set("custom:server:"..uri,server,5)
- cache:set("custom:url:"..uri,url,5)
-
- ngx.var.key = key
- ngx.var.server = server
- ngx.var.url = url
- return true
-end
-
-local function query_allkeys_updatecache(red)
- -- Try to get all keys start with "msb:routing:custom:"
- local allkeys, err = red:keys("msb:routing:custom:*")
- if not allkeys or allkeys == ngx.null then
- ngx.log(ngx.ERR,err)
- return ""
- end
- local key_set={}
- for key, value in ipairs(allkeys) do
- name = string.gsub(string.gsub(string.gsub(value,"msb:routing:custom:",""),":info",""),":lb:server1","")
- key_set[name]=true
- end
- local key_table = {}
- local index = 1
- for key,_ in pairs(key_set) do
- key_table[index] = key
- index = index + 1
- end
- table.sort(key_table, function (a, b)
- return a > b
- end)
-
- local servicenames = ""
- local delimiter = "<>"
- for i=1,#key_table do
- servicenames=servicenames..key_table[i]..delimiter
- end
-
- -- get the local cache
- local cache = ngx.shared.ceryx
- -- Save all keys to local cache for 30 seconds(0.5 minutes)
- cache:set("customrouter:allkeys", servicenames, 30)
- return servicenames;
-end
-
-local function query_router_info()
- local uri = ngx.var.uri
- ngx.log(ngx.WARN, "==uri:", uri)
-
- -- Check if key exists in local cache
- local cache = ngx.shared.ceryx
- local key, flags = cache:get("custom:key:"..uri)
- local server, flags = cache:get("custom:server:"..uri)
- local url, flags = cache:get("custom:url:"..uri)
- if key and server and url then
- ngx.var.key = key
- ngx.var.server = server
- ngx.var.url = url
- ngx.log(ngx.WARN, "==using custom cache:", key.."&&"..server.."&&"..url)
- return
- end
-
- local redis = require "resty.redis"
- local red = redis:new()
- red:set_timeout(1000) -- 1000 ms
- local redis_host = "127.0.0.1"
- local redis_port = 6379
- local res, err = red:connect(redis_host, redis_port)
-
- -- Return if could not connect to Redis
- if not res then
- ngx.log(ngx.ERR, "connect to redis error:", err)
- return
- end
-
- -- Check if all servicenames exists in local cache
- local servicenames, flags = cache:get("customrouter:allkeys")
- if servicenames then
- ngx.log(ngx.WARN,"==get all keys from cache:",servicenames)
- else
- servicenames = query_allkeys_updatecache(red)
- end
-
- local delimiter = "<>"
- for key in string.gmatch(servicenames,"(.-)"..delimiter) do
- ngx.log(ngx.WARN, "==key_table key:", key)
- local from, to, err = ngx.re.find(uri, "^"..key.."(/(.*))?$", "jo")
- if from then
- ngx.log(ngx.WARN,"Matched! start-end:",from,"-",to)
- local result = query_ipurl_updatecache(red,key)
- if result then
- break
- end
- else
- ngx.log(ngx.WARN,"not Matched")
- if err then
- ngx.log(ngx.WARN,"ngx.re.find throw error: ",err)
- return
- end
- end
- end
-
- return close_redis(red)
-end
-
-local function rewrite_router_url()
- local server=ngx.var.server
- if server=="fallback" then
- ngx.status = ngx.HTTP_NOT_FOUND
- ngx.exit(ngx.status)
- end
- local url=ngx.var.url
- local key=ngx.var.key
- local rewriteduri = ngx.re.sub(ngx.var.uri, "^"..key.."(.*)", url.."$1", "o")
- ngx.log(ngx.WARN, "==rewrited uri:", rewriteduri)
- ngx.req.set_uri(rewriteduri)
-end
-
-query_router_info()
-rewrite_router_url() \ No newline at end of file
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/execute_auth.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/execute_auth.lua
deleted file mode 100644
index 946f561..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/execute_auth.lua
+++ /dev/null
@@ -1,25 +0,0 @@
---[[
-
- Copyright 2016 ZTE Corporation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Author: Zhaoxing Meng
- email: meng.zhaoxing1@zte.com.cn
-
-]]
-local auth_plugin = require('plugins.auth')
-local msbconf = require('msbconf')
-if(msbconf.auth_plugin_status == "on") then
- auth_plugin.access()
-end \ No newline at end of file
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msbconf.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msbconf.lua
deleted file mode 100644
index 48b04c7..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msbconf.lua
+++ /dev/null
@@ -1,26 +0,0 @@
---[[
-
- Copyright 2016 ZTE Corporation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Author: Zhaoxing Meng
- email: meng.zhaoxing1@zte.com.cn
-
-]]
-local _M = {}
-_M._VERSION = '1.0.0'
-
-return {
- auth_plugin_status = "off"
-} \ No newline at end of file
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoadminrouter.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoadminrouter.lua
deleted file mode 100644
index 938a017..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoadminrouter.lua
+++ /dev/null
@@ -1,110 +0,0 @@
---[[
-
- Copyright 2016 ZTE Corporation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Author: Zhaoxing Meng
- email: meng.zhaoxing1@zte.com.cn
-
-]]
--- put red into the connection pool of size 100,
--- with 10 seconds max idle time
-local function close_redis(red)
- if not red then
- return
- end
- --release connection to the pool
- local pool_max_idle_time = 10000
- local pool_size = 100
- local ok, err = red:set_keepalive(pool_max_idle_time, pool_size)
- if not ok then
- ngx.log(ngx.ERR, "set keepalive error:", err)
- end
- return
-end
-
-local function rewrite_admin_url()
- local apiserver=ngx.var.apiserver
- if apiserver=="fallback" then
- ngx.status = ngx.HTTP_NOT_FOUND
- ngx.exit(ngx.status)
- end
- local adminurl=ngx.var.adminurl
- local uri = ngx.re.sub(ngx.var.uri, "^/admin/([^/]+)(/[Vv][^/]*)?(.*)", adminurl.."$3", "o")
- ngx.req.set_uri(uri)
-end
-
-local function query_admin_info()
- local apiserver = ngx.var.apiserver
- local apiname = ngx.var.apiname
- local apiversion = ngx.var.apiversion
- apiversion=string.sub(apiversion,2,string.len(apiversion))
-
- -- Check if key exists in local cache
- local cache = ngx.shared.ceryx
- local server, flags = cache:get("server:admin:"..apiname..":"..apiversion)
- local url, flags = cache:get("url:admin:"..apiname..":"..apiversion)
- if server and url then
- ngx.var.apiserver = server
- ngx.var.adminurl = url
- ngx.log(ngx.WARN, "==using admin cache:", server.."&&"..url)
- return
- end
-
- local redis = require "resty.redis"
- local red = redis:new()
- red:set_timeout(1000) -- 1000 ms
- local redis_host = "127.0.0.1"
- local redis_port = 6379
- local res, err = red:connect(redis_host, redis_port)
-
- -- Return if could not connect to Redis
- if not res then
- ngx.log(ngx.ERR, "connect to redis error:", err)
- return
- end
-
- -- Construct Redis key
- local prefix = "msb"
- local keyprefix = prefix..":routing:api:"..apiname..":"..apiversion
-
-
- -- Try to get ip:port for apiname
- local serverkey=keyprefix..":lb:server1"
- local server, err = red:hget(serverkey,"ip")..":"..red:hget(serverkey,"port")
- ngx.log(ngx.WARN, "==adminserver:", server)
- if not server or server == ngx.null then
- return close_redis(red)
- end
-
- -- Try to get admin url for apiname
- local infokey=keyprefix..":info"
- local url, err = red:hget(infokey,"metricsUrl")
- ngx.log(ngx.WARN, "==adminurl:", url)
- if not url or url == ngx.null then
- return close_redis(red)
- end
-
- -- Save found key to local cache for 5 seconds
- cache:set("server:admin:"..apiname..":"..apiversion, server, 5)
- cache:set("url:admin:"..apiname..":"..apiversion, url, 5)
-
- ngx.log(ngx.WARN, "==admin result:", server.."&&"..url)
- ngx.var.apiserver = server
- ngx.var.adminurl = url
-
- return close_redis(red)
-end
-query_admin_info()
-rewrite_admin_url() \ No newline at end of file
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoapijsonrouter.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoapijsonrouter.lua
deleted file mode 100644
index 9255a65..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoapijsonrouter.lua
+++ /dev/null
@@ -1,110 +0,0 @@
---[[
-
- Copyright 2016 ZTE Corporation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Author: Zhaoxing Meng
- email: meng.zhaoxing1@zte.com.cn
-
-]]
--- put red into the connection pool of size 100,
--- with 10 seconds max idle time
-local function close_redis(red)
- if not red then
- return
- end
- --release connection to the pool
- local pool_max_idle_time = 10000
- local pool_size = 100
- local ok, err = red:set_keepalive(pool_max_idle_time, pool_size)
- if not ok then
- ngx.log(ngx.ERR, "set keepalive error:", err)
- end
- return
-end
-
-local function rewrite_apijson_url()
- local apiserver=ngx.var.apiserver
- if apiserver=="fallback" then
- ngx.status = ngx.HTTP_NOT_FOUND
- ngx.exit(ngx.status)
- end
- local apijsonurl=ngx.var.apijsonurl
- local uri = ngx.re.sub(ngx.var.uri, "^/apijson/([^/]+)(/[Vv][^/]*)?(.*)", apijsonurl.."$3", "o")
- ngx.req.set_uri(uri)
-end
-
-local function query_apijson_info()
- local apiserver = ngx.var.apiserver
- local apiname = ngx.var.apiname
- local apiversion = ngx.var.apiversion
- apiversion=string.sub(apiversion,2,string.len(apiversion))
-
- -- Check if key exists in local cache
- local cache = ngx.shared.ceryx
- local server, flags = cache:get("server:apijson:"..apiname..":"..apiversion)
- local url, flags = cache:get("url:apijson:"..apiname..":"..apiversion)
- if server and url then
- ngx.var.apiserver = server
- ngx.var.apijsonurl = url
- ngx.log(ngx.WARN, "==using apijson cache:", server.."&&"..url)
- return
- end
-
- local redis = require "resty.redis"
- local red = redis:new()
- red:set_timeout(1000) -- 1000 ms
- local redis_host = "127.0.0.1"
- local redis_port = 6379
- local res, err = red:connect(redis_host, redis_port)
-
- -- Return if could not connect to Redis
- if not res then
- ngx.log(ngx.ERR, "connect to redis error:", err)
- return
- end
-
- -- Construct Redis key
- local prefix = "msb"
- local keyprefix = prefix..":routing:api:"..apiname..":"..apiversion
-
-
- -- Try to get ip:port for apiname
- local serverkey=keyprefix..":lb:server1"
- local server, err = red:hget(serverkey,"ip")..":"..red:hget(serverkey,"port")
- ngx.log(ngx.WARN, "==apijsonserver:", server)
- if not server or server == ngx.null then
- return close_redis(red)
- end
-
- -- Try to get apijson url for apiname
- local infokey=keyprefix..":info"
- local url, err = red:hget(infokey,"apijson")
- ngx.log(ngx.WARN, "==apijsonurl:", url)
- if not url or url == ngx.null then
- return close_redis(red)
- end
-
- -- Save found key to local cache for 5 seconds
- cache:set("server:apijson:"..apiname..":"..apiversion, server, 5)
- cache:set("url:apijson:"..apiname..":"..apiversion, url, 5)
-
- ngx.log(ngx.WARN, "==apijson result:", server.."&&"..url)
- ngx.var.apiserver = server
- ngx.var.apijsonurl = url
-
- return close_redis(red)
-end
-query_apijson_info()
-rewrite_apijson_url() \ No newline at end of file
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoapirouter.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoapirouter.lua
deleted file mode 100644
index 717bd1a..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openoapirouter.lua
+++ /dev/null
@@ -1,117 +0,0 @@
---[[
-
- Copyright 2016 ZTE Corporation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Author: Zhaoxing Meng
- email: meng.zhaoxing1@zte.com.cn
-
-]]
--- put red into the connection pool of size 100,
--- with 10 seconds max idle time
-local function close_redis(red)
- if not red then
- return
- end
- --release connection to the pool
- local pool_max_idle_time = 10000
- local pool_size = 100
- local ok, err = red:set_keepalive(pool_max_idle_time, pool_size)
- if not ok then
- ngx.log(ngx.ERR, "set keepalive error:", err)
- end
- return
-end
-
-local function rewrite_api_url()
- local apiserver=ngx.var.apiserver
- if apiserver=="fallback" then
- ngx.status = ngx.HTTP_NOT_FOUND
- ngx.exit(ngx.status)
- end
- local apiurl=ngx.var.apiurl
- local uri = ngx.re.sub(ngx.var.uri, "^/openoapi/([^/]+)(/[Vv][^/]*)?(.*)", apiurl.."$3", "o")
- ngx.req.set_uri(uri)
-end
-
-local function query_api_info()
- local apiserver = ngx.var.apiserver
- local apiname = ngx.var.apiname
- local apiversion = ngx.var.apiversion
- apiversion=string.sub(apiversion,2,string.len(apiversion))
-
- -- Check if key exists in local cache
- local cache = ngx.shared.ceryx
- local server, flags = cache:get("server:api:"..apiname..":"..apiversion)
- local url, flags = cache:get("url:api:"..apiname..":"..apiversion)
- if server and url then
- ngx.var.apiserver = server
- ngx.var.apiurl = url
- ngx.log(ngx.WARN, "==using api cache:", server.."&&"..url)
- return
- end
-
- local redis = require "resty.redis"
- local red = redis:new()
- red:set_timeout(1000) -- 1000 ms
- local redis_host = "127.0.0.1"
- local redis_port = 6379
- local res, err = red:connect(redis_host, redis_port)
-
- -- Return if could not connect to Redis
- if not res then
- ngx.log(ngx.ERR, "connect to redis error:", err)
- return
- end
-
- -- Construct Redis key
- local prefix = "msb"
- local keyprefix = prefix..":routing:api:"..apiname..":"..apiversion
-
- local infokey=keyprefix..":info"
- -- first of all check whether the status is 1(enabled)
- local status = red:hget(infokey,"status")
- if not (status=="1") then
- ngx.log(ngx.WARN, keyprefix.."is disabled.status=", status)
- return close_redis(red)
- end
-
- -- Try to get url for apiname
- local url, err = red:hget(infokey,"url")
- ngx.log(ngx.WARN, "==url:", url)
- if not url or url == ngx.null then
- return close_redis(red)
- end
-
- -- Try to get ip:port for apiname
- local serverkey=keyprefix..":lb:server1"
- local server, err = red:hget(serverkey,"ip")..":"..red:hget(serverkey,"port")
- ngx.log(ngx.WARN, "==server:", server)
- if not server or server == ngx.null then
- return close_redis(red)
- end
-
-
- -- Save found key to local cache for 5 seconds
- cache:set("server:api:"..apiname..":"..apiversion, server, 5)
- cache:set("url:api:"..apiname..":"..apiversion, url, 5)
-
- ngx.log(ngx.WARN, "==api result:", server.."&&"..url)
- ngx.var.apiserver = server
- ngx.var.apiurl = url
-
- return close_redis(red)
-end
-query_api_info()
-rewrite_api_url() \ No newline at end of file
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openouirouter.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openouirouter.lua
deleted file mode 100644
index c36057e..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/openouirouter.lua
+++ /dev/null
@@ -1,115 +0,0 @@
---[[
-
- Copyright 2016 ZTE Corporation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Author: Zhaoxing Meng
- email: meng.zhaoxing1@zte.com.cn
-
-]]
--- put red into the connection pool of size 100,
--- with 10 seconds max idle time
-local function close_redis(red)
- if not red then
- return
- end
- --release connection to the pool
- local pool_max_idle_time = 10000
- local pool_size = 100
- local ok, err = red:set_keepalive(pool_max_idle_time, pool_size)
- if not ok then
- ngx.log(ngx.ERR, "set keepalive error:", err)
- end
- return
-end
-
-local function rewrite_iui_url()
- local iuiserver=ngx.var.iuiserver
- if iuiserver=="fallback" then
- ngx.status = ngx.HTTP_NOT_FOUND
- ngx.exit(ngx.status)
- end
- local iuiurl=ngx.var.iuiurl
- local uri = ngx.re.sub(ngx.var.uri, "^/openoui/([^/]+)(.*)", iuiurl.."$2", "o")
- ngx.req.set_uri(uri)
-end
-
-local function query_iui_info()
- local iuiserver = ngx.var.iuiserver
- local iuiname = ngx.var.iuiname
-
- -- Check if key exists in local cache
- local cache = ngx.shared.ceryx
- local server, flags = cache:get("server:iui:"..iuiname)
- local url, flags = cache:get("url:iui:"..iuiname)
- if server and url then
- ngx.var.iuiserver = server
- ngx.var.iuiurl = url
- ngx.log(ngx.WARN, "==using iui cache:", server.."&&"..url)
- return
- end
-
- local redis = require "resty.redis"
- local red = redis:new()
- red:set_timeout(1000) -- 1000 ms
- local redis_host = "127.0.0.1"
- local redis_port = 6379
- local res, err = red:connect(redis_host, redis_port)
-
- -- Return if could not connect to Redis
- if not res then
- ngx.log(ngx.ERR, "connect to redis error:", err)
- return
- end
-
- -- Construct Redis key
- local prefix = "msb"
- local keyprefix = prefix..":routing:iui:"..iuiname
-
- local infokey=keyprefix..":info"
- -- first of all check whether the status is 1(enabled)
- local status = red:hget(infokey,"status")
- if not (status=="1") then
- ngx.log(ngx.WARN, keyprefix.."is disabled.status=", status)
- return close_redis(red)
- end
-
- -- Try to get url for iuiname
- local url, err = red:hget(infokey,"url")
- ngx.log(ngx.WARN, "==url:", url)
- if not url or url == ngx.null then
- return close_redis(red)
- end
-
- -- Try to get ip:port for iuiname
- local serverkey=keyprefix..":lb:server1"
- local server, err = red:hget(serverkey,"ip")..":"..red:hget(serverkey,"port")
- ngx.log(ngx.WARN, "==server:", server)
- if not server or server == ngx.null then
- return close_redis(red)
- end
-
-
- -- Save found key to local cache for 5 seconds
- cache:set("server:iui:"..iuiname, server, 5)
- cache:set("url:iui:"..iuiname, url, 5)
-
- ngx.log(ngx.WARN, "==iui result:", server.."&&"..url)
- ngx.var.iuiserver = server
- ngx.var.iuiurl = url
-
- return close_redis(red)
-end
-query_iui_info()
-rewrite_iui_url() \ No newline at end of file
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/auth.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/auth.lua
deleted file mode 100644
index 1572060..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/auth.lua
+++ /dev/null
@@ -1,171 +0,0 @@
---[[
-
- Copyright 2016 2015-2016 OEPN-O. and others. All rights reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-]]
-local _M = {}
-_M._VERSION = '1.0.0'
-local auth_url = '/openoapi/auth/v1';
-local auth_token_url = auth_url..'/tokens';
-local auth_token_key = "X-Auth-Token";
-local redirect_url = "/openoui/common/login.html"
-
-local white_list= {
- auth_token_url,
- redirect_url,
- '/openoui/common/css',
- '/openoui/common/js',
- '/openoui/common/thirdparty',
- '/openoui/common/i18n',
- '/openoui/common/image',
- '/openoui/common/login.html',
- '/openoui/common/json'
-};
-
-local function verify_value(value)
- if (nil == value or 0 == #value)
- then
- return false;
- else
- return true;
- end
-end
-
---[[checks str2 starts with str1]]--
-local function starts_with(str1, str2)
- return string.sub(str2, 1, string.len(str1)) == str1;
-end
-
--- Check and ignore the request if it is from auth module.--
-local function is_white_list(url)
- for i, value in ipairs(white_list)
- do
- if (starts_with(value, url))
- then
- return true;
- end
- end
- return false;
-end
-
-local function set_header(tokens)
- for key,value in pairs(tokens)
- do
- ngx.log (ngx.ERR, "Headers: ", key, value);
- ngx.req.set_header(key, value);
- end
-
-end
---[[ validates the token with auth ]]--
-local function validate_token(tokens)
- -- auth expects the token in header.
- set_header(tokens);
- -- call auth token check url to validate.
- local res = ngx.location.capture(auth_token_url, { method = ngx.HTTP_HEAD});
- ngx.log (ngx.ERR, "Auth Result:", res.status);
- if (nil == res)
- then
- return false;
- end
- return (ngx.HTTP_OK == res.status);
-end
-
---[[ get auth token from cookies ]]--
-local function get_cookies()
- local cookie_name = "cookie_"..auth_token_key;
- local auth_token = ngx.var[cookie_name];
- local tokens = {};
- -- verify whether its empty or null.
- if (verify_value(auth_token))
- then
- ngx.log(ngx.ERR, "token : ", auth_token );
- tokens[auth_token_key] = auth_token;
- end
- return tokens;
-end
-
-local function get_service_url()
- -- get host.
- local host = ngx.var.host;
- --get port
- local port = ":"..ngx.var.server_port;
- local proto = "";
- --get protocol
- if (ngx.var.https == "on")
- then
- proto = "https://";
- else
- proto = "http://";
- end
- --get url
- local uri = ngx.var.uri;
- --form complete service url.
- --local complete_url = proto..host..port..url
- local complete_url = uri;
- local service = "?service="
- --add arguments if any.
- if ngx.var.args ~= nil
- then
- complete_url = complete_url.."?"..ngx.var.args;
- end
- ngx.log(ngx.ERR, "service url : ", complete_url);
- return service..ngx.escape_uri(complete_url);
-end
-
-local function redirect(url)
- local service = get_service_url();
- ngx.log(ngx.ERR, "redirect: ", url..service);
- ngx.redirect(url..service);
-end
-
-function _M.access()
-
- ngx.log(ngx.ERR, "==============start check token===============: ");
- local url = ngx.var.uri;
- ngx.log(ngx.ERR, "Url : ", url);
-
- -- ignore token validation if auth request.
- if (is_white_list(url))
- then
- return;
- end
-
-
-
- -- get auth token from cookies.
- local auth_tokens = get_cookies();
-
- -- check if auth token is empty,
- -- redirect it to login page in that case.
- if (nil == next(auth_tokens))
- then
- ngx.log(ngx.ERR, "Token Invalidate, redirect to ", redirect_url);
- redirect(redirect_url);
- return;
- end
-
- -- validate the token with auth module.
- -- continue if success, else redirect to login page.
- if(validate_token(auth_tokens))
- then
- ngx.log(ngx.ERR, "Token Validate.");
- return;
- else
- redirect(redirect_url);
- end
- ngx.log(ngx.INFO, "running auth plugin")
- end
-
-return _M \ No newline at end of file
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/driver_manager.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/driver_manager.lua
deleted file mode 100644
index 45d327d..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/driver_manager.lua
+++ /dev/null
@@ -1,127 +0,0 @@
---[[
-
- Copyright 2016 2015-2016 OPEN-O. and others. All rights reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-]]
-local _M = {}
-_M._VERSION = '1.0.0'
-local _HEADER = "X-Driver-Parameter"
-
---extract driver header if present in request
-local function get_driver_header()
- local header = ""
- local driver_header = ngx.req.get_headers()[_HEADER]
- if (driver_header ~= nil)
- then
- header = driver_header
- end
- return header
-end
-
--- generate query url
-local function get_query_url(x_driver_header)
- local drivermgr_uri = '/openoapi/drivermgr/v1/drivers'
- local url = drivermgr_uri.."?".._HEADER.."="..tostring(ngx.escape_uri(x_driver_header)).."&service_url="..ngx.var.uri
- return url
-end
-
--- generate driver url
-local function get_driver_url(driver_header)
- local cjson = require "cjson"
- local query_url = get_query_url(driver_header)
- local driver_header_value = get_driver_header();
- ngx.req.clear_header(_HEADER)
- local res = ngx.location.capture(query_url, { method = ngx.HTTP_GET})
- ngx.req.set_header(_HEADER, driver_header_value);
- ngx.log (ngx.ERR, "Driver manager resp url : ", tostring(res.body))
- if (res.status == 200 and res.body ~= nil and res.body ~= '')
- then
- return tostring(cjson.new().decode(res.body).url)
- else
- return ''
- end
-end
-
--- get the ori query param string
-local function get_ori_query()
- local args = ngx.req.get_uri_args();
- local ori_query_param = "?"..ngx.encode_args(args);
- ngx.log(ngx.ERR, "The original request query parameter is ", ori_query_param);
- return ori_query_param;
-end
-
--- get headers
-local function get_headers()
- local headers = {}
- local h = ngx.req.get_headers()
- for k, value in pairs(h)
- do
- headers[k] = value
- end
- return headers
-end
-
-local function get_body_params()
- ngx.req.read_body()
- local actual_body = ""
- local body_param = ngx.req.get_body_data()
- if(body_param ~= nil)
- then
- actual_body = tostring(body_param)
- end
- return actual_body
-end
-
-function _M.access()
- ngx.log(ngx.ERR, "DRIVER MANAGER LUA", "***********************")
-
- -- extract X-Driver-Parameter header param
- local driver_header = get_driver_header()
- ngx.log(ngx.ERR, "X-Driver-Parameter: ", driver_header)
-
-
- -- ignore driver redirection if not driver manager request.
- if (driver_header ~= "")
- then
-
- local driver_url = get_driver_url(driver_header)..get_ori_query();
- ngx.log (ngx.ERR, "Driver manager URl:: ", driver_url)
-
- local http = require "resty.http"
- local actual_headers = get_headers()
- local actual_body = get_body_params()
-
- ngx.log(ngx.ERR, "HTTP request to driver... ", " Request to driver manager")
- local httpc = http.new();
- httpc:set_timeout(300000);
- local res, err = httpc:request_uri(driver_url, {
- method = ngx.req.get_method(),
- body = actual_body,
- headers = actual_headers
- })
-
- if not res then
- ngx.say("Request to driver failed : ", err)
- return
- end
- ngx.log(ngx.ERR, "Response from driver : ", tostring(res.body))
- ngx.say(res.body)
-
- else
- ngx.log(ngx.ERR, "X-Driver-Parameter not present", " Redirect to same url")
- end
-end
-
-return _M \ No newline at end of file
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/setnocacheflag.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/setnocacheflag.lua
deleted file mode 100644
index 8b57660..0000000
--- a/msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/setnocacheflag.lua
+++ /dev/null
@@ -1,29 +0,0 @@
---[[
-
- Copyright 2016 ZTE Corporation.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Author: Zhaoxing Meng
- email: meng.zhaoxing1@zte.com.cn
-
-]]
-local from, to, err = ngx.re.find(ngx.var.uri, "\\.(gif|jpg|jpeg|png|bmp|ico)$", "jo")
---Based on the request file type to determine whether to cache
-if from then
- --use cache
- return 0
-else
- --do not use cache
- return 1
-end \ No newline at end of file