From 3d9994fbad2ed85599b7c94088f6caeee4e2c02d Mon Sep 17 00:00:00 2001 From: Brian Scholer <1260690+briantist@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:11:30 -0400 Subject: [PATCH] Configurable server name (#3) * add configurable server name * cache stores raw responses, rewritten on read --- galactory/__main__.py | 2 ++ galactory/upstream.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/galactory/__main__.py b/galactory/__main__.py index e5d576c..e1c1e81 100644 --- a/galactory/__main__.py +++ b/galactory/__main__.py @@ -19,6 +19,7 @@ ) parser.add_argument('--listen-addr', default='0.0.0.0', type=str, help='The IP address to listen on.') parser.add_argument('--listen-port', default=5555, type=int, help='The TCP port to listen on.') + parser.add_argument('--server-name', type=str, help='The host name and port of the server, as seen from clients. Used for generating links.') parser.add_argument('--artifactory-path', type=str, required=True, help='The URL of the path in Artifactory where collections are stored.') parser.add_argument('--artifactory-api-key', default=os.environ.get('GALACTORY_ARTIFACTORY_API_KEY'), help='If set, is the API key used to access Artifactory.') parser.add_argument('--use-galaxy-key', action='store_true', help='If set, uses the Galaxy token as the Artifactory API key.') @@ -47,6 +48,7 @@ ARTIFACTORY_API_KEY=args.artifactory_api_key, USE_GALAXY_KEY=args.use_galaxy_key, PREFER_CONFIGURED_KEY=args.prefer_configured_key, + SERVER_NAME=args.server_name, ) print(app.url_map) diff --git a/galactory/upstream.py b/galactory/upstream.py index e338d9f..29db326 100644 --- a/galactory/upstream.py +++ b/galactory/upstream.py @@ -170,16 +170,15 @@ def proxy(self, request): # else: # abort(Response(resp.text, resp.status_code)) - else: current_app.logger.info(f"Cache miss: {request.url}") - data = self._rewrite_upstream_response(resp.json(), request.url_root) + data = resp.json() cache.data = data self._set_cache(request, cache) else: current_app.logger.info(f"Cache hit: {request.url}") - return cache.data + return self._rewrite_upstream_response(cache.data, request.url_root) def _rewrite_upstream_response(self, response_data, url_root) -> dict: ret = {}