2021-06-04 11:23:07 +00:00
|
|
|
# register the registry access in accounts service (cookies should contain jwt)
|
|
|
|
log_by_lua_block {
|
|
|
|
-- this block runs only when accounts are enabled
|
2021-12-23 14:09:54 +00:00
|
|
|
if require("skynet.account").accounts_enabled() then
|
2022-01-04 13:57:20 +00:00
|
|
|
local function track(premature, request_method, jwt)
|
|
|
|
if premature then return end
|
2021-06-04 11:23:07 +00:00
|
|
|
|
2022-01-04 13:57:20 +00:00
|
|
|
local httpc = require("resty.http").new()
|
2022-01-07 12:36:04 +00:00
|
|
|
|
|
|
|
-- based on request method we assign a registry action string used
|
|
|
|
-- in track endpoint namely "read" for GET and "write" for POST
|
|
|
|
local registry_action = request_method == "GET" and "read" or "write"
|
2021-08-27 12:15:22 +00:00
|
|
|
|
2022-01-04 13:57:20 +00:00
|
|
|
-- 10.10.10.70 points to accounts service (alias not available when using resty-http)
|
2022-01-07 12:36:04 +00:00
|
|
|
local res, err = httpc:request_uri("http://10.10.10.70:3000/track/registry/" .. registry_action, {
|
2022-01-04 13:57:20 +00:00
|
|
|
method = "POST",
|
|
|
|
headers = { ["Cookie"] = "skynet-jwt=" .. jwt },
|
|
|
|
})
|
|
|
|
|
|
|
|
if err or (res and res.status ~= ngx.HTTP_NO_CONTENT) then
|
2022-01-07 12:36:04 +00:00
|
|
|
ngx.log(ngx.ERR, "Failed accounts service request /track/registry/" .. registry_action .. ": ", err or ("[HTTP " .. res.status .. "] " .. res.body))
|
2022-01-04 13:57:20 +00:00
|
|
|
end
|
2021-06-04 11:23:07 +00:00
|
|
|
end
|
2021-08-27 12:15:22 +00:00
|
|
|
|
2022-01-04 13:57:20 +00:00
|
|
|
if ngx.var.skynet_jwt ~= "" and (ngx.status == ngx.HTTP_OK or ngx.status == ngx.HTTP_NOT_FOUND) then
|
|
|
|
local ok, err = ngx.timer.at(0, track, ngx.req.get_method(), ngx.var.skynet_jwt)
|
|
|
|
if err then ngx.log(ngx.ERR, "Failed to create timer: ", err) end
|
|
|
|
end
|
2021-08-27 12:15:22 +00:00
|
|
|
end
|
2021-06-04 11:23:07 +00:00
|
|
|
}
|