fix account endpoint nginx subrequests

This commit is contained in:
Karol Wypchlo 2021-08-27 18:33:27 +02:00
parent a972b54d3d
commit 9ff776fdea
No known key found for this signature in database
GPG Key ID: C92C016317A964D0
3 changed files with 11 additions and 13 deletions

View File

@ -58,7 +58,7 @@ access_by_lua_block {
-- 10.10.10.70 points to accounts service (alias not available when using resty-http) -- 10.10.10.70 points to accounts service (alias not available when using resty-http)
local res, err = httpc:request_uri("http://10.10.10.70:3000/user/limits", { local res, err = httpc:request_uri("http://10.10.10.70:3000/user/limits", {
headers = { ["User-Agent"] = "Sia-Agent", ["Cookie"] = "skynet-jwt=" .. ngx.var.skynet_jwt } headers = { ["Cookie"] = "skynet-jwt=" .. ngx.var.skynet_jwt }
}) })
-- fail gracefully in case /user/limits failed -- fail gracefully in case /user/limits failed

View File

@ -17,7 +17,7 @@ access_by_lua_block {
-- 10.10.10.70 points to accounts service (alias not available when using resty-http) -- 10.10.10.70 points to accounts service (alias not available when using resty-http)
local res, err = httpc:request_uri("http://10.10.10.70:3000/user/limits", { local res, err = httpc:request_uri("http://10.10.10.70:3000/user/limits", {
headers = { ["User-Agent"] = "Sia-Agent", ["Cookie"] = "skynet-jwt=" .. ngx.var.skynet_jwt } headers = { ["Cookie"] = "skynet-jwt=" .. ngx.var.skynet_jwt }
}) })
-- fail gracefully in case /user/limits failed -- fail gracefully in case /user/limits failed

View File

@ -175,7 +175,7 @@ location /skynet/tus {
-- fetch account limits and set max upload size accordingly -- fetch account limits and set max upload size accordingly
local res, err = httpc:request_uri("http://10.10.10.70:3000/user/limits", { local res, err = httpc:request_uri("http://10.10.10.70:3000/user/limits", {
headers = { ["User-Agent"] = "Sia-Agent", ["Cookie"] = "skynet-jwt=" .. ngx.var.skynet_jwt } headers = { ["Cookie"] = "skynet-jwt=" .. ngx.var.skynet_jwt }
}) })
-- fail gracefully in case /user/limits failed -- fail gracefully in case /user/limits failed
@ -274,20 +274,18 @@ location /__internal/do/not/use/authenticated {
-- 10.10.10.70 points to accounts service (alias not available when using resty-http) -- 10.10.10.70 points to accounts service (alias not available when using resty-http)
local res, err = httpc:request_uri("http://10.10.10.70:3000/user", { local res, err = httpc:request_uri("http://10.10.10.70:3000/user", {
headers = { ["User-Agent"] = "Sia-Agent", ["Cookie"] = "skynet-jwt=" .. ngx.var.skynet_jwt } headers = { ["Cookie"] = "skynet-jwt=" .. ngx.var.skynet_jwt }
}) })
-- fail gracefully in case /user failed -- endpoint /user should return HTTP_OK for authenticated and HTTP_UNAUTHORIZED for not authenticated
if err or (res and res.status ~= ngx.HTTP_OK) then if res and (res.status == ngx.HTTP_OK or res.status == ngx.HTTP_UNAUTHORIZED) then
ngx.log(ngx.ERR, "Failed accounts service request /user/limits: ", err or ("[HTTP " .. res.status .. "] " .. res.body)) ngx.say(json.encode{authenticated = res.status == ngx.HTTP_OK})
elseif res and res.status == ngx.HTTP_OK then return ngx.exit(ngx.HTTP_OK)
local limits = json.decode(res.body) else
ngx.say(json.encode{authenticated = limits.tier > 0}) ngx.log(ngx.ERR, "Failed accounts service request /user: ", err or ("[HTTP " .. res.status .. "] " .. res.body))
ngx.say(json.encode{authenticated = false})
return ngx.exit(ngx.HTTP_OK) return ngx.exit(ngx.HTTP_OK)
end end
ngx.say(json.encode{authenticated = false})
return ngx.exit(ngx.HTTP_OK)
} }
} }