Skip to content
Snippets Groups Projects
Unverified Commit bc442cbe authored by Andrej Shadura's avatar Andrej Shadura
Browse files

Make sure srcserver requests are proxied to the srcserver


Signed-off-by: default avatarAndrej Shadura <andrew.shadura@collabora.co.uk>
parent 7e55033b
No related branches found
No related tags found
1 merge request!47Fix path-prefixed proxies
......@@ -549,8 +549,27 @@ async def worker_build(worker_id: str = None):
def proxied_uri():
"""
Construct a URI of the backend's resource corresponding to the proxy's URI
>>> config.backend.repserver_uri = "http://repserver:1234"
>>> config.backend.srcserver_uri = "http://srcserver:5678"
>>> async def test_app_context(uri):
... async with app.test_request_context(uri, method="GET"):
... return proxied_uri()
>>> asyncio.run(test_app_context('/repserver/worker:0/badpackagebinaryversionlist'))
'http://repserver:1234/badpackagebinaryversionlist'
>>> asyncio.run(test_app_context('/srcserver/worker:0/badpackagebinaryversionlist'))
'http://srcserver:5678/badpackagebinaryversionlist'
>>> asyncio.run(test_app_context('/repserver/worker:1/build/project/repository/arch/package'))
'http://repserver:1234/build/project/repository/arch/package'
>>> asyncio.run(test_app_context('/srcserver/worker:1/source/project/package'))
'http://srcserver:5678/source/project/package'
"""
path = request.path.split(request.root_path, 1)[1] if request.root_path else request.path
return config.backend.repserver_uri + '/' + '/'.join(path.split('/')[3:])
_, backend, worker_id, *args = path.split('/')
backend_uri = config.backend.repserver_uri if backend == "repserver" else config.backend.srcserver_uri
return backend_uri + '/' + '/'.join(path.split('/')[3:])
@app.route('/repserver/<path:worker_id>/badpackagebinaryversionlist')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment