cleanup
This commit is contained in:
+14
-26
@@ -1,8 +1,9 @@
|
||||
local upload = require "resty.upload"
|
||||
local uuid = require "resty.jit-uuid"
|
||||
local cjson = require "cjson"
|
||||
--# https://github.com/SkyLothar/lua-resty-jwt
|
||||
--$ opm get SkyLothar/lua-resty-jwt
|
||||
local jwt = require "resty.jwt"
|
||||
local redis = require "resty.redis"
|
||||
|
||||
local chunk_size = 4096
|
||||
local form = upload:new(chunk_size)
|
||||
@@ -23,19 +24,7 @@ local files = {}
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
|
||||
---- Redis init
|
||||
------ Connect to redis
|
||||
-- local redis_task_database = redis:new()
|
||||
|
||||
-- redis_task_database:set_timeouts(1000, 1000, 1000)
|
||||
|
||||
-- local ok, error = redis_task_database:connect("127.0.0.1", 6379)
|
||||
-- if not ok then
|
||||
-- ngx.log(ngx.ERR, "Fail to connect redis: ", error)
|
||||
-- ngx.exit(500)
|
||||
-- end
|
||||
|
||||
function LuaReomve(str,remove)
|
||||
function cleanupString(str, remove)
|
||||
local lcSubStrTab = {}
|
||||
while true do
|
||||
local lcPos = string.find(str, remove)
|
||||
@@ -60,15 +49,14 @@ function LuaReomve(str,remove)
|
||||
return lcMergeStr
|
||||
end
|
||||
|
||||
|
||||
function VerifyJwtToken(encrypted_token)
|
||||
function verifyJwtToken(encrypted_token)
|
||||
|
||||
local http = require "resty.http"
|
||||
local httpc = http.new()
|
||||
local remote_url = string.format("%s/api/v1/uc/verify_jwt_token", hty_uc_host)
|
||||
|
||||
ngx.log(ngx.INFO, 'htyuc remote_url -> ', remote_url)
|
||||
-- ngx.log(ngx.INFO, 'Authorization -> ', encrypted_token)
|
||||
ngx.log(ngx.INFO, 'Authorization -> ', encrypted_token)
|
||||
|
||||
local res, err = httpc:request_uri(
|
||||
remote_url,
|
||||
@@ -97,7 +85,7 @@ function VerifyJwtToken(encrypted_token)
|
||||
|
||||
end
|
||||
|
||||
function DecoderJwtToken(encrypted_token)
|
||||
function decodeJwtToken(encrypted_token)
|
||||
|
||||
local jwt_key = "0xCAFEBABE0xCAFEBABE0xCAFEBABE0xCAFEBABE0xCAFEBABE0xCAFEBABE"
|
||||
local jwt_obj = jwt:verify(jwt_key, encrypted_token)
|
||||
@@ -130,22 +118,22 @@ while true do
|
||||
return
|
||||
end
|
||||
|
||||
local authorization = ngx.req.get_headers().Authorization
|
||||
if authorization then
|
||||
ngx.log(ngx.INFO, 'Check request authorization Authorization -> ', authorization)
|
||||
local authHeader = ngx.req.get_headers().Authorization
|
||||
if authHeader then
|
||||
ngx.log(ngx.INFO, 'Check request authorization Authorization -> ', authHeader)
|
||||
-- local htytoken = DecoderJwtToken(authorization)
|
||||
VerifyJwtToken(authorization)
|
||||
verifyJwtToken(authHeader)
|
||||
else
|
||||
ngx.log(ngx.ERR, 'Request header no authorization ! ')
|
||||
ngx.status = 500
|
||||
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
|
||||
end
|
||||
|
||||
local authorization = ngx.req.get_headers().HtySudoerToken
|
||||
if authorization then
|
||||
ngx.log(ngx.INFO, 'Check request authorization HtySudoerToken -> ', authorization)
|
||||
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
||||
if sudoerToken then
|
||||
ngx.log(ngx.INFO, 'Check request authorization HtySudoerToken -> ', sudoerToken)
|
||||
-- local htytoken = DecoderJwtToken(authorization)
|
||||
VerifyJwtToken(authorization)
|
||||
verifyJwtToken(sudoerToken)
|
||||
|
||||
else
|
||||
ngx.log(ngx.ERR, 'Request header no hty sudoer token ! ')
|
||||
|
||||
Reference in New Issue
Block a user