This commit is contained in:
2021-11-28 10:52:23 +08:00
parent fc51ac41f8
commit e2b9b33f4a
+13 -14
View File
@@ -9,7 +9,7 @@ local chunk_size = 4096
local form = upload:new(chunk_size)
uuid.seed()
TaskTypes = {
local TaskTypes = {
NOOP = 'NOOP',
UPLOAD_PICTURE = 'UPLOAD_PICTURE'
}
@@ -24,7 +24,7 @@ local files = {}
local http = require "resty.http"
local httpc = http.new()
function cleanupString(str, remove)
local function cleanupString(str, remove)
local lcSubStrTab = {}
while true do
local lcPos = string.find(str, remove)
@@ -49,7 +49,7 @@ function cleanupString(str, remove)
return lcMergeStr
end
function verifyJwtToken(encrypted_token)
local function verifyJwtToken(encrypted_token)
local http = require "resty.http"
local httpc = http.new()
@@ -85,8 +85,7 @@ function verifyJwtToken(encrypted_token)
end
function decodeJwtToken(encrypted_token)
local function decodeJwtToken(encrypted_token)
local jwt_key = "0xCAFEBABE0xCAFEBABE0xCAFEBABE0xCAFEBABE0xCAFEBABE0xCAFEBABE"
local jwt_obj = jwt:verify(jwt_key, encrypted_token)
if jwt_obj.verified == false then
@@ -101,11 +100,12 @@ function decodeJwtToken(encrypted_token)
ngx.log(ngx.INFO, "jwt object : payload : sub " .. jwt_obj.payload.sub)
local htytoken = cjson.decode(jwt_obj.payload.sub)
ngx.log(ngx.INFO, "htytoken : token_id " .. htytoken.token_id)
ngx.log(ngx.INFO, "htytoken : hty_id " .. htytoken.hty_id)
--ngx.log(ngx.INFO, "htytoken : app_id " .. htytoken.app_id)
ngx.log(ngx.INFO, "htytoken : app_id " .. htytoken.app_id)
ngx.log(ngx.INFO, "htytoken : ts " .. htytoken.ts)
--ngx.log(ngx.INFO, "htytoken : roles " .. htytoken.roles)
ngx.log(ngx.INFO, "htytoken : roles " .. htytoken.roles)
return htytoken
end
@@ -119,6 +119,7 @@ while true do
end
local authHeader = ngx.req.get_headers().Authorization
local sudoerToken = ngx.req.get_headers().HtySudoerToken
--
--if authHeader then
-- ngx.log(ngx.INFO, 'Check request authorization Authorization -> ', authHeader)
@@ -130,7 +131,7 @@ while true do
-- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
--end
--local sudoerToken = ngx.req.get_headers().HtySudoerToken
--
--if sudoerToken then
-- ngx.log(ngx.INFO, 'Check request authorization HtySudoerToken -> ', sudoerToken)
@@ -178,12 +179,10 @@ while true do
file_name = nil
file = nil
elseif type == "eof" then
local remote_url = string.format("%s/api/v1/ts/create_task", task_server)
ngx.log(ngx.INFO, 'remote_url -> ', remote_url)
ngx.log(ngx.INFO, 'Authorization -> ', ngx.req.get_headers().Authorization)
ngx.log(ngx.INFO, 'HtySudoerToken -> ', ngx.req.get_headers().HtySudoerToken)
ngx.log(ngx.INFO, 'Authorization -> ', authHeader)
ngx.log(ngx.INFO, 'HtySudoerToken -> ', sudoerToken)
local body_text = cjson.encode({ task_type = TaskTypes.UPLOAD_PICTURE, data = { images = files } })
@@ -194,8 +193,8 @@ while true do
method = "POST",
headers = {
["Content-Type"] = "application/json",
["Authorization"] = ngx.req.get_headers().Authorization,
["HtySudoerToken"] = ngx.req.get_headers().HtySudoerToken
["Authorization"] = authHeader,
["HtySudoerToken"] = sudoerToken,
},
body = body_text,
}