From f52b648c5bfbf2b6e77257cce1f6bb3375695ba5 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 18 Dec 2020 12:23:10 +0100 Subject: [PATCH] add tracking --- docker/kratos/oathkeeper/access-rules.yml | 2 +- docker/nginx/conf.d/client.conf | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docker/kratos/oathkeeper/access-rules.yml b/docker/kratos/oathkeeper/access-rules.yml index 478d9830..e7abc6a5 100644 --- a/docker/kratos/oathkeeper/access-rules.yml +++ b/docker/kratos/oathkeeper/access-rules.yml @@ -57,7 +57,7 @@ preserve_host: true url: "http://accounts:3000" match: - url: "http://oathkeeper:4455/<{user}>" + url: "http://oathkeeper:4455/<{user,user/**}>" methods: - GET authenticators: diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index 0366ab03..92c0f70e 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -291,6 +291,16 @@ server { # proxy this call to siad endpoint (make sure the ip is correct) proxy_pass http://siad/skynet/skyfile/$dir1/$dir2/$dir3/$dir4$is_args$args; + + # register the upload in accounts service (cookies should contain jwt) + log_by_lua_block { + local skylink = ngx.header["Skynet-Skylink"] + if skylink and ngx.status >= ngx.HTTP_OK and ngx.status < ngx.HTTP_SPECIAL_RESPONSE then + local http = require("socket.http") + local headers = { Cookie = ngx.req.get_headers()["Cookie"] } + http.request { url = "http://accounts:3000/track/upload/" .. skylink, method = "POST", headers = headers } + end + } } location ~ "^/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" { @@ -311,6 +321,16 @@ server { # decoded whitespaces and set will re-encode it for us before passing it to proxy_pass set $skylink $1; + # register the download in accounts service (cookies should contain jwt) + log_by_lua_block { + local skylink = ngx.var[2] + if skylink and ngx.status >= ngx.HTTP_OK and ngx.status < ngx.HTTP_SPECIAL_RESPONSE then + local http = require("socket.http") + local headers = { Cookie = ngx.req.get_headers()["Cookie"] } + http.request { url = "http://accounts:3000/track/download/" .. skylink, method = "POST", headers = headers } + end + } + proxy_read_timeout 600; proxy_set_header User-Agent: Sia-Agent; # proxy this call to siad /skynet/skylink/ endpoint (make sure the ip is correct)