Merge pull request #1106 from SkynetLabs/fix-account-endpoints

fix account endpoint nginx subrequests
This commit is contained in:
Ivaylo Novakov 2021-08-30 11:03:29 +02:00 committed by GitHub
commit 9a1f2ad655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
local limits = json.decode(res.body)
ngx.say(json.encode{authenticated = limits.tier > 0})
return ngx.exit(ngx.HTTP_OK) return ngx.exit(ngx.HTTP_OK)
end else
ngx.log(ngx.ERR, "Failed accounts service request /user: ", err or ("[HTTP " .. res.status .. "] " .. res.body))
ngx.say(json.encode{authenticated = false}) ngx.say(json.encode{authenticated = false})
return ngx.exit(ngx.HTTP_OK) return ngx.exit(ngx.HTTP_OK)
end
} }
} }