~notmyname/swift/allowed_headers_head

« back to all changes in this revision

Viewing changes to swift/common/middleware/swift3.py

  • Committer: Tarmac
  • Author(s): Michael Barton
  • Date: 2011-04-16 17:32:51 UTC
  • mfrom: (263.4.3 signedurls)
  • Revision ID: tarmac-20110416173251-2jjkqvhfl9kq6la0
Adds param-signed URLs to swift3 middleware.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
"""
17
17
The swift3 middleware will emulate the S3 REST api on top of swift.
18
18
 
19
 
The boto python library is necessary to use this middleware (install
20
 
the python-boto package if you use Ubuntu).
21
 
 
22
19
The following opperations are currently supported:
23
20
 
24
21
    * GET Service
438
435
            return BucketController, d
439
436
        return ServiceController, d
440
437
 
441
 
    def get_account_info(self, env, req):
442
 
        try:
443
 
            account, user, _junk = \
444
 
                req.headers['Authorization'].split(' ')[-1].split(':')
445
 
        except Exception:
446
 
            return None, None
447
 
 
448
 
        h = canonical_string(req)
449
 
        token = base64.urlsafe_b64encode(h)
450
 
        return '%s:%s' % (account, user), token
451
 
 
452
438
    def __call__(self, env, start_response):
453
439
        req = Request(env)
454
 
        if not'Authorization' in req.headers:
 
440
 
 
441
        if 'AWSAccessKeyId' in req.GET:
 
442
            try:
 
443
                req.headers['Date'] = req.GET['Expires']
 
444
                req.headers['Authorization'] = \
 
445
                    'AWS %(AWSAccessKeyId)s:%(Signature)s' % req.GET
 
446
            except KeyError:
 
447
                return get_err_response('InvalidArgument')(env, start_response)
 
448
 
 
449
        if not 'Authorization' in req.headers:
455
450
            return self.app(env, start_response)
 
451
 
 
452
        try:
 
453
            account, signature = \
 
454
                req.headers['Authorization'].split(' ')[-1].rsplit(':', 1)
 
455
        except Exception:
 
456
            return get_err_response('InvalidArgument')(env, start_response)
 
457
 
456
458
        try:
457
459
            controller, path_parts = self.get_controller(req.path)
458
460
        except ValueError:
459
461
            return get_err_response('InvalidURI')(env, start_response)
460
462
 
461
 
        account_name, token = self.get_account_info(env, req)
462
 
        if not account_name:
463
 
            return get_err_response('InvalidArgument')(env, start_response)
464
 
 
465
 
        controller = controller(env, self.app, account_name, token,
466
 
                                **path_parts)
 
463
        token = base64.urlsafe_b64encode(canonical_string(req))
 
464
 
 
465
        controller = controller(env, self.app, account, token, **path_parts)
 
466
 
467
467
        if hasattr(controller, req.method):
468
468
            res = getattr(controller, req.method)(env, start_response)
469
469
        else: