Skip to content

Commit 7c48118

Browse files
committed
Add support for getting paginated tags
1 parent 5c0fe41 commit 7c48118

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

files/nginx.conf

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ http {
1818
# this is necessary for us to be able to disable request buffering in all cases
1919
proxy_http_version 1.1;
2020

21+
# will run before forking out nginx worker processes
22+
init_by_lua_block { require "cjson" }
23+
2124
server {
2225
listen PORT default_server;
2326

@@ -55,12 +58,6 @@ http {
5558
proxy_set_header Authorization "Basic $http_authorization";
5659
proxy_set_header X-Forwarded-Proto $scheme;
5760

58-
# make Link header relative by stripping the https://<host> part from it.
59-
header_filter_by_lua_block {
60-
if ngx.header["Link"] ~= nil then
61-
ngx.header["Link"] = ngx.header["Link"]:gsub("https?://[^/]+", "")
62-
end
63-
}
6461
}
6562

6663
# Content addressable files like blobs.
@@ -97,5 +94,48 @@ http {
9794
http_500 http_502 http_503 http_504;
9895
proxy_cache_lock on;
9996
}
97+
98+
location ~ ^/v2/.*/.*/tags/list+$ {
99+
# get paginated list of tags
100+
content_by_lua_block {
101+
local location, tags, cjson = ngx.var.uri, {}, require "cjson"
102+
while true do
103+
local res = ngx.location.capture("/get_tags",
104+
{ args = { req_uri = location } }
105+
)
106+
if res.status == ngx.HTTP_NOT_FOUND and table.getn(tags) == 0 then
107+
ngx.status = ngx.HTTP_NOT_FOUND
108+
ngx.print(res.body)
109+
ngx.exit(0)
110+
end
111+
local data = cjson.decode(res.body)
112+
for _,v in ipairs(data['tags']) do
113+
table.insert(tags, v)
114+
end
115+
if res.header["Link"] ~= nil then
116+
location = res.header["Link"]:match("/v2[^>]+")
117+
else
118+
ngx.print(cjson.encode{name = data['name'], tags = tags })
119+
ngx.exit(ngx.HTTP_OK)
120+
end
121+
end
122+
}
123+
}
124+
125+
# Helper location for getting tags from upstream repository
126+
# used for getting paginated tags.
127+
location /get_tags {
128+
internal;
129+
set_unescape_uri $req_uri $arg_req_uri;
130+
proxy_pass UPSTREAM$req_uri;
131+
132+
# Add AWS ECR authentication headers
133+
proxy_set_header X-Real-IP $remote_addr;
134+
proxy_set_header X-Forwarded-For $remote_addr;
135+
proxy_set_header X-Forwarded-User "Basic $http_authorization";
136+
proxy_set_header Authorization "Basic $http_authorization";
137+
proxy_set_header X-Forwarded-Proto $scheme;
138+
139+
}
100140
}
101141
}

0 commit comments

Comments
 (0)