Logging and fix 403 error
This commit is contained in:
parent
f2e1a425c6
commit
c57a6d072f
@ -3,5 +3,6 @@
|
||||
"secret_key": "you_secret_key",
|
||||
"auth_uri": "http://radosgw/auth/1.0",
|
||||
"rados_uri": "http://radosgw/swift/v1/",
|
||||
"bucket": "public"
|
||||
"bucket": "public",
|
||||
"logfile": "/var/log/nginx/swift.log"
|
||||
}
|
||||
|
33
swift.lua
33
swift.lua
@ -1,11 +1,17 @@
|
||||
local cjson = require "cjson"
|
||||
local cjson = require("cjson")
|
||||
local time = require("os")
|
||||
local ltn12 = require("ltn12")
|
||||
local io = require("io")
|
||||
|
||||
-- Load configuration
|
||||
function readConf(file)
|
||||
function readConf()
|
||||
local file = '/etc/nginx/etc/swift.json'
|
||||
local f, err = io.open(file, "rb")
|
||||
local content = f:read("*all")
|
||||
f:close()
|
||||
return content
|
||||
|
||||
local conf = cjson.decode(content)
|
||||
return conf
|
||||
end
|
||||
|
||||
-- Print nested tables
|
||||
@ -19,8 +25,15 @@ function content_from_table(tbl)
|
||||
end
|
||||
end
|
||||
|
||||
local json = readConf('/etc/nginx/etc/swift.json')
|
||||
local conf = cjson.decode(json)
|
||||
-- Write to log
|
||||
function write_to_logfile(string)
|
||||
local conf = readConf('/etc/nginx/etc/swift.json')
|
||||
local l, err = io.open(conf.logfile, "a")
|
||||
l:write(string .. "\n")
|
||||
l:close()
|
||||
end
|
||||
|
||||
local conf = readConf()
|
||||
|
||||
-- Make authentication request to Ceph
|
||||
headers_t = {}
|
||||
@ -35,7 +48,8 @@ local r, c, h = http.request{
|
||||
}
|
||||
|
||||
-- Return 403 if not authorized
|
||||
if c ~= 200 then
|
||||
if c ~= 204 then
|
||||
write_to_logfile(time.date() .. ' 403')
|
||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||
end
|
||||
|
||||
@ -46,8 +60,8 @@ auth_token = h["x-auth-token"]
|
||||
content_headers= {}
|
||||
content_headers["X-Auth-Token"] = auth_token
|
||||
|
||||
local ltn12 = require("ltn12")
|
||||
local io = require("io")
|
||||
write_to_logfile(time.date() .. " Auth OK. Token is: " .. auth_token)
|
||||
|
||||
|
||||
t = {}
|
||||
|
||||
@ -58,8 +72,11 @@ local resp, code, http_st = http.request{
|
||||
sink = ltn12.sink.table(t)
|
||||
}
|
||||
|
||||
write_to_logfile(time.date() .. " URI: " .. conf.rados_uri .. conf.bucket .. ngx.var.path)
|
||||
|
||||
-- Return 404 if object not found in Ceph
|
||||
if code ~= 200 then
|
||||
write_to_logfile(time.date() .. " Not found")
|
||||
ngx.exit(ngx.HTTP_NOT_FOUND)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user