From 7b2cba8657c191dc54137400003770e506dad70f Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 11 Feb 2021 09:51:05 -0800 Subject: [PATCH] Make container name prefix more generic Currently the proxy expects the container name as the first element of the path. It then adds a prefix followed by a "-" character to the container name before using it. To additionally support the case where no prefix is desired (so that the path that the Zuul base job returns is the entire path used by the proxy), remove the automatic addition of the "-" character. This means that if no prefix is supplied, then the path is used as given. To obtain the previous behavior, add a "-" character to the end of the CONTAINER_PREFIX environment variable. Change-Id: Ia480a11f78621ea0b2417f4b47878640f52db5da --- zuul_storage_proxy/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/zuul_storage_proxy/__init__.py b/zuul_storage_proxy/__init__.py index 7dad075..b249542 100644 --- a/zuul_storage_proxy/__init__.py +++ b/zuul_storage_proxy/__init__.py @@ -156,12 +156,12 @@ def swift_proxy(environ, start_response, clouds, container_prefix): return if len(components) < 2: - # no path inside tenant given, redirect to root index + # no container or path given, redirect to root index return redirect_directory(start_response, path) - tenant = components[0] + container = components[0] path = components[1] - container = '-'.join([container_prefix, tenant]) + container = container_prefix + container print('%s request %s/%s' % (method, container, path)) try: @@ -195,8 +195,10 @@ class CloudCache(object): for cloud_name in cloud_names: self.log.warning('Using cloud %s', cloud_name) self.clouds.append(openstack.connect(cloud=cloud_name)) - self.container_prefix = os.environ['CONTAINER_PREFIX'] - self.log.warning('Using container prefix %s', self.container_prefix) + self.container_prefix = os.environ.get('CONTAINER_PREFIX', '') + if self.container_prefix: + self.log.warning('Using container prefix %s', + self.container_prefix) def __call__(self, environ, start_response): for chunk in self.app(environ, start_response, self.clouds,