OCS-18 MSB-API Gateway add extension point for Auth and Driver Mgr.
authorYonggangWang <wang.yonggang131@zte.com.cn>
Wed, 14 Sep 2016 03:31:53 +0000 (11:31 +0800)
committerYonggangWang <wang.yonggang131@zte.com.cn>
Wed, 14 Sep 2016 03:31:53 +0000 (11:31 +0800)
Issue-id: OCS-18
MSB-API Gateway add extension point for Auth and Driver Mgr., these modules only need to fill in own logical code.

Change-Id: Ib54e807ae532bfb91c58bcbf8c9c56ee7e0d4ebf
Signed-off-by: YonggangWang <wang.yonggang131@zte.com.cn>
msb-core/openresty-ext/src/assembly/resources/openresty/nginx/conf/nginx.conf
msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/execute_auth.lua [new file with mode: 0644]
msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/msbconf.lua [new file with mode: 0644]
msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/auth.lua [new file with mode: 0644]
msb-core/openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/driver_manager.lua [new file with mode: 0644]
msb-core/openresty-ext/src/assembly/resources/openresty/nginx/sites-enabled/openomsb.conf

index c5dc770..1ac9aff 100644 (file)
@@ -55,7 +55,7 @@ http {
     access_log off;
 
     # Lua settings
-    lua_package_path "$prefix/../lualib/?.lua;;";
+    lua_package_path "$prefix/../lualib/?.lua;$prefix/luaext/?.lua;;";
 
     lua_shared_dict ceryx 10M;
     lua_code_cache on;
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
new file mode 100644 (file)
index 0000000..c8ea047
--- /dev/null
@@ -0,0 +1,25 @@
+--[[
+
+    Copyright 2016 2015-2016 ZTE, Inc. 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.
+
+        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
new file mode 100644 (file)
index 0000000..4e820f5
--- /dev/null
@@ -0,0 +1,26 @@
+--[[
+
+    Copyright 2016 2015-2016 ZTE, Inc. 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.
+
+        Author: Zhaoxing Meng
+        email: meng.zhaoxing1@zte.com.cn
+
+]]
+local _M = {}
+_M._VERSION = '1.0.0'
+
+return {
+    auth_plugin_status = "on"
+}
\ 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
new file mode 100644 (file)
index 0000000..a1fecf2
--- /dev/null
@@ -0,0 +1,29 @@
+--[[
+
+    Copyright 2016 2015-2016 ZTE, Inc. 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.
+
+        Author: Zhaoxing Meng
+        email: meng.zhaoxing1@zte.com.cn
+
+]]
+local _M = {}
+_M._VERSION = '1.0.0'
+
+function _M.access()
+       --add your own code here
+       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
new file mode 100644 (file)
index 0000000..a53ec21
--- /dev/null
@@ -0,0 +1,30 @@
+--[[
+
+    Copyright 2016 2015-2016 ZTE, Inc. 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.
+
+        Author: Zhaoxing Meng
+        email: meng.zhaoxing1@zte.com.cn
+
+]]
+local _M = {}
+_M._VERSION = '1.0.0'
+
+function _M.access()
+       ngx.log(ngx.INFO, "running driver_manager plugin")
+       --add your own code here
+       --choose the right backend server,and then tell nginx, e.g. ngx.var.backend = XX.XX.XX.XX:8888
+end
+
+return _M
\ No newline at end of file
index b529d94..88ab447 100644 (file)
@@ -33,6 +33,7 @@ server {
                  
                  # Lua files
           rewrite_by_lua_file luaext/customrouter.lua;
+                 access_by_lua_file luaext/execute_auth.lua;
                  
                  proxy_pass http://$server;
    }
@@ -42,6 +43,16 @@ server {
     location ~ ^/iui/(.*) {
                rewrite ^/iui/(.*) /openoui/$1 last;
        }
+       
+       location ^~ /openoapi/driver_vmware_vcloud/v1 {
+                 set $backend "";
+                 # Lua files
+          access_by_lua_block {
+                       local driver_manager   =  require('plugins.driver_manager')
+                       driver_manager.access()
+                }
+                proxy_pass http://$backend;
+    }
    location ~ ^/openoapi/([^/]+)(/[Vv][^/]*)?(.*) {
           set $apiname $1;
                  set $apiversion $2;
@@ -50,6 +61,7 @@ server {
 
           # Lua files
           rewrite_by_lua_file luaext/openoapirouter.lua;
+                 access_by_lua_file luaext/execute_auth.lua;
                  
           proxy_pass http://$apiserver;
    }
@@ -63,6 +75,7 @@ server {
                  
                          # Lua files
                                  rewrite_by_lua_file luaext/openouirouter.lua;
+                                 access_by_lua_file luaext/execute_auth.lua;
 
                                  proxy_cache nginx_cache;
                                  proxy_cache_key $host$uri$is_args$args;
@@ -80,6 +93,7 @@ server {
 
           # Lua files
           rewrite_by_lua_file luaext/openouirouter.lua;
+                 access_by_lua_file luaext/execute_auth.lua;
                  
                  proxy_pass http://$iuiserver;
    }
@@ -92,6 +106,7 @@ server {
                  
                  # Lua files
           rewrite_by_lua_file luaext/openoadminrouter.lua;
+                 access_by_lua_file luaext/execute_auth.lua;
                  
                  proxy_pass http://$apiserver;
    }
@@ -105,6 +120,7 @@ server {
                                  
                          # Lua files
                                  rewrite_by_lua_file luaext/openoapijsonrouter.lua;
+                                 access_by_lua_file luaext/execute_auth.lua;
 
                                  proxy_cache nginx_cache;
                                  proxy_cache_key $host$uri$is_args$args;
@@ -122,6 +138,7 @@ server {
                  
                  # Lua files
           rewrite_by_lua_file luaext/openoapijsonrouter.lua;
+                 access_by_lua_file luaext/execute_auth.lua;
                  
                  proxy_pass http://$apiserver;
    }
@@ -133,6 +150,7 @@ server {
                  
                   # Lua files
                   rewrite_by_lua_file luaext/customrouter.lua;
+                  access_by_lua_file luaext/execute_auth.lua;
 
                   proxy_cache nginx_cache;
                   proxy_cache_key $host$uri$is_args$args;