diff options
author | Kun Huang <gareth@unitedstack.com> | 2013-07-21 23:55:45 +0800 |
---|---|---|
committer | Kun Huang <academicgareth@gmail.com> | 2013-08-02 17:19:12 +0800 |
commit | 55938e8b6048fe7138f4577ed276b81a52071db4 (patch) | |
tree | 47cf8f1f482d003dce744a8f8b96e46312b677bc /keystone/middleware | |
parent | c6b7dd8959f96e4b5bf282860245603ff94b0084 (diff) | |
download | keystone-55938e8b6048fe7138f4577ed276b81a52071db4.tar.gz keystone-55938e8b6048fe7138f4577ed276b81a52071db4.tar.xz keystone-55938e8b6048fe7138f4577ed276b81a52071db4.zip |
remove swift dependency of s3 middleware
In middleware/s3_token.py, here only use swift for a logger and path
split functionality. We should remove swift dependency by using new
codes.
fixes bug #1178738
Change-Id: Icc2648720e220a873d1fb8e9961d777ceabef70b
Diffstat (limited to 'keystone/middleware')
-rw-r--r-- | keystone/middleware/s3_token.py | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/keystone/middleware/s3_token.py b/keystone/middleware/s3_token.py index 2b7f99a0..b346893b 100644 --- a/keystone/middleware/s3_token.py +++ b/keystone/middleware/s3_token.py @@ -34,14 +34,62 @@ This WSGI component: """ import httplib +import urllib import webob -from swift.common import utils as swift_utils - +from keystone.common import logging from keystone.openstack.common import jsonutils PROTOCOL_NAME = 'S3 Token Authentication' +LOG = logging.getLogger(__name__) + + +# TODO(kun): remove it after oslo merge this. +def split_path(path, minsegs=1, maxsegs=None, rest_with_last=False): + """Validate and split the given HTTP request path. + + **Examples**:: + + ['a'] = split_path('/a') + ['a', None] = split_path('/a', 1, 2) + ['a', 'c'] = split_path('/a/c', 1, 2) + ['a', 'c', 'o/r'] = split_path('/a/c/o/r', 1, 3, True) + + :param path: HTTP Request path to be split + :param minsegs: Minimum number of segments to be extracted + :param maxsegs: Maximum number of segments to be extracted + :param rest_with_last: If True, trailing data will be returned as part + of last segment. If False, and there is + trailing data, raises ValueError. + :returns: list of segments with a length of maxsegs (non-existant + segments will return as None) + :raises: ValueError if given an invalid path + """ + if not maxsegs: + maxsegs = minsegs + if minsegs > maxsegs: + raise ValueError('minsegs > maxsegs: %d > %d' % (minsegs, maxsegs)) + if rest_with_last: + segs = path.split('/', maxsegs) + minsegs += 1 + maxsegs += 1 + count = len(segs) + if (segs[0] or count < minsegs or count > maxsegs or + '' in segs[1:minsegs]): + raise ValueError('Invalid path: %s' % urllib.quote(path)) + else: + minsegs += 1 + maxsegs += 1 + segs = path.split('/', maxsegs) + count = len(segs) + if (segs[0] or count < minsegs or count > maxsegs + 1 or + '' in segs[1:minsegs] or + (count == maxsegs + 1 and segs[maxsegs])): + raise ValueError('Invalid path: %s' % urllib.quote(path)) + segs = segs[1:maxsegs] + segs.extend([None] * (maxsegs - 1 - len(segs))) + return segs class ServiceError(Exception): @@ -54,7 +102,7 @@ class S3Token(object): def __init__(self, app, conf): """Common initialization code.""" self.app = app - self.logger = swift_utils.get_logger(conf, log_route='s3token') + self.logger = LOG self.logger.debug('Starting the %s component' % PROTOCOL_NAME) self.reseller_prefix = conf.get('reseller_prefix', 'AUTH_') # where to find the auth service (we use this to validate tokens) @@ -119,7 +167,7 @@ class S3Token(object): self.logger.debug('Calling S3Token middleware.') try: - parts = swift_utils.split_path(req.path, 1, 4, True) + parts = split_path(req.path, 1, 4, True) version, account, container, obj = parts except ValueError: msg = 'Not a path query, skipping.' |