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
This commit is contained in:
James E. Blair 2021-02-11 09:51:05 -08:00
parent 022c80a9a2
commit 7b2cba8657

View File

@ -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,