当前位置: 首页>>代码示例>>Python>>正文


Python Request.headers['Authorization']方法代码示例

本文整理汇总了Python中swift.common.swob.Request.headers['Authorization']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.headers['Authorization']方法的具体用法?Python Request.headers['Authorization']怎么用?Python Request.headers['Authorization']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swift.common.swob.Request的用法示例。


在下文中一共展示了Request.headers['Authorization']方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_request

# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers['Authorization'] [as 别名]
    def handle_request(self, env, start_response):
        req = Request(env)
        self.logger.debug('Calling Swift3 Middleware')
        self.logger.debug(req.__dict__)

        if 'AWSAccessKeyId' in req.params:
            try:
                req.headers['Date'] = req.params['Expires']
                req.headers['Authorization'] = \
                    'AWS %(AWSAccessKeyId)s:%(Signature)s' % req.params
            except KeyError:
                return get_err_response('InvalidArgument')(env, start_response)

        if 'Authorization' not in req.headers:
            return self.app(env, start_response)

        try:
            keyword, info = req.headers['Authorization'].split(' ')
        except:
            return get_err_response('AccessDenied')(env, start_response)

        if keyword != 'AWS':
            return get_err_response('AccessDenied')(env, start_response)

        try:
            account, signature = info.rsplit(':', 1)
        except:
            return get_err_response('InvalidArgument')(env, start_response)

        try:
            controller, path_parts = self.get_controller(req.path)
        except ValueError:
            return get_err_response('InvalidURI')(env, start_response)

        if 'Date' in req.headers:
            date = email.utils.parsedate(req.headers['Date'])
            if date is None:
                return get_err_response('AccessDenied')(env, start_response)

            d1 = datetime.datetime(*date[0:6])
            d2 = datetime.datetime.utcnow()
            epoch = datetime.datetime(1970, 1, 1, 0, 0, 0, 0)

            if d1 < epoch:
                return get_err_response('AccessDenied')(env, start_response)

            delta = datetime.timedelta(seconds=60 * 10)
            if d1 - d2 > delta or d2 - d1 > delta:
                return get_err_response('RequestTimeTooSkewed')(env,
                                                                start_response)

        token = base64.urlsafe_b64encode(canonical_string(req))

        controller = controller(env, self.app, account, token, conf=self.conf,
                                **path_parts)

        if hasattr(controller, req.method):
            res = getattr(controller, req.method)(env, start_response)
        else:
            return get_err_response('InvalidURI')(env, start_response)

        return res(env, start_response)
开发者ID:CiscoSystems,项目名称:swift-plugin-s3,代码行数:64,代码来源:middleware.py

示例2: handle_request

# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers['Authorization'] [as 别名]
    def handle_request(self, env, start_response):
        req = Request(env)
        self.logger.debug('Calling Swift3 Middleware')
        self.logger.debug(req.__dict__)

        if 'AWSAccessKeyId' in req.params:
            try:
                req.headers['Date'] = req.params['Expires']
                req.headers['Authorization'] = \
                    'AWS %(AWSAccessKeyId)s:%(Signature)s' % req.params
            except KeyError:
                return get_err_response('InvalidArgument')(env, start_response)

        if 'Authorization' not in req.headers:
            return self.app(env, start_response)

        try:
            keyword, info = req.headers['Authorization'].split(' ')
        except:
            return get_err_response('AccessDenied')(env, start_response)

        if keyword != 'AWS':
            return get_err_response('AccessDenied')(env, start_response)

        try:
            account, signature = info.rsplit(':', 1)
        except:
            return get_err_response('InvalidArgument')(env, start_response)

        try:
            controller, path_parts = self.get_controller(env, req.path)
        except ValueError:
            return get_err_response('InvalidURI')(env, start_response)

        if 'Date' in req.headers:
            date = email.utils.parsedate(req.headers['Date'])
            expdate = None
            if date is None and 'Expires' in req.params:
                d = email.utils.formatdate(float(req.params['Expires']))
                expdate = email.utils.parsedate(d)

                date = datetime.datetime.utcnow().timetuple()
            elif date is None:
                return get_err_response('AccessDenied')(env, start_response)

            epoch = datetime.datetime(1970, 1, 1, 0, 0, 0, 0)
            delta = datetime.timedelta(seconds=60 * 5)

            d1 = datetime.datetime(*date[0:6])
            now = datetime.datetime.utcnow()
            if d1 < epoch:
                return get_err_response('AccessDenied')(env, start_response)

            # If the standard date is too far ahead or behind, it is an error
            if abs(d1 - now) > delta:
                return get_err_response('RequestTimeTooSkewed')(env,
                                                                start_response)

            # If there was an expiration date in the parameters, check it also
            if expdate:
                ex = datetime.datetime(*expdate[0:6])
                if (now > ex and (now - ex) > delta):
                    return get_err_response('RequestTimeTooSkewed')(
                        env, start_response)

        token = base64.urlsafe_b64encode(canonical_string(req))

        controller = controller(env, self.app, account, token, conf=self.conf,
                                **path_parts)

        if hasattr(controller, req.method):
            res = getattr(controller, req.method)(env, start_response)
        else:
            return get_err_response('InvalidURI')(env, start_response)

        return res(env, start_response)
开发者ID:citrix-openstack-build,项目名称:swift3,代码行数:78,代码来源:middleware.py

示例3: handle_request

# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers['Authorization'] [as 别名]
    def handle_request(self, env, start_response):
        req = Request(env)
        self.logger.debug('Calling Swift3 Middleware')

        if 'AWSAccessKeyId' in req.params:
            try:
                req.headers['Date'] = req.params['Expires']
                req.headers['Authorization'] = \
                    'AWS %(AWSAccessKeyId)s:%(Signature)s' % req.params
            except KeyError:
                return get_err_response('InvalidArgument')(env, start_response)

        if 'Authorization' not in req.headers:
            return self.app(env, start_response)

        try:
            keyword, info = req.headers['Authorization'].split(' ')
        except:
            return get_err_response('AccessDenied')(env, start_response)

        if keyword != 'AWS':
            # This wasn't an S3 request
            return self.app(env, start_response)

        try:
            account, signature = info.rsplit(':', 1)
        except:
            return get_err_response('InvalidArgument')(env, start_response)

        path = req.path

        if path.startswith('/v1/'):
            path = path[3:]

        account, path = split_path(path, 1, 2, True)

        if account.startswith('AUTH_'):
            account = account[5:]

        path = '/' + path

        try:
            controller, path_parts = self.get_controller(env, path)
        except ValueError:
            return get_err_response('InvalidURI')(env, start_response)

        if 'Expires' in req.params:
            unix_date = float(req.params['Expires'])

            if unix_date < 0:
                return get_err_response('AccessDenied')(env, start_response)

            d = email.utils.formatdate(unix_date)
            date = email.utils.parsedate(d)
            date = datetime.datetime(*date[0:6])

            if date < datetime.datetime.utcnow():
                return get_err_response('AccessDenied')(env, start_response)

        elif 'Date' in req.headers:
            date = email.utils.parsedate(req.headers['Date'])

            if date is None:
                return get_err_response('AccessDenied')(env, start_response)

            d1 = datetime.datetime(*date[0:6])
            d2 = datetime.datetime.utcnow()
            epoch = datetime.datetime(1970, 1, 1, 0, 0, 0, 0)

            if d1 < epoch:
                return get_err_response('AccessDenied')(env, start_response)

            delta = datetime.timedelta(seconds=60 * 5)
            if d1 - d2 > delta or d2 - d1 > delta:
                return get_err_response('RequestTimeTooSkewed')(env,
                                                                start_response)

        token = base64.urlsafe_b64encode(canonical_string(req))

        controller = controller(env, self.app, account, token, conf=self.conf,
                                **path_parts)

        if hasattr(controller, req.method):
            res = getattr(controller, req.method)(env, start_response)
        else:
            return get_err_response('InvalidURI')(env, start_response)

        return res(env, start_response)
开发者ID:CloudVPS,项目名称:swift3,代码行数:90,代码来源:middleware.py

示例4: handle_request

# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers['Authorization'] [as 别名]
    def handle_request(self, env, start_response):
        req = Request(env)
        self.logger.debug('Calling S3Multipart Helper Middleware')
        #self.logger.debug(req.__dict__)
        #self.logger.info('S3MULTI --')
        #self.logger.info('S3MULTI: %s %s' % (req.method, req.url))
        #self.logger.info('S3MULTI --')

        #
        # Check that the request has the correct AA headers
        #
        if 'AWSAccessKeyId' in req.params:
            try:
                req.headers['Date'] = req.params['Expires']
                req.headers['Authorization'] = \
                    'AWS %(AWSAccessKeyId)s:%(Signature)s' % req.params
            except KeyError:
                return get_err_response('InvalidArgument')(env, start_response)

        if 'Authorization' not in req.headers:
            return self.app(env, start_response)
        try:
            keyword, info = req.headers['Authorization'].split(' ')
        except:
            return get_err_response('AccessDenied')(env, start_response)

        if keyword != 'AWS':
            return get_err_response('AccessDenied')(env, start_response)
        try:
            account, signature = info.rsplit(':', 1)
        except:
            return get_err_response('InvalidArgument')(env, start_response)

        if req.method == 'GET':
            return self.GET(env, start_response)
        elif req.method == 'HEAD':
            return self.HEAD(env, start_response)
        elif req.method == 'POST':
            return self.POST(env, start_response)
        elif req.method == 'DELETE':
            return self.DELETE(env, start_response)
        elif req.method != 'PUT':
            return self.app(env, start_response)

        #
        # If none of the above, it must be a PUT
        #
        if 'QUERY_STRING' in env:
            args = dict(urlparse.parse_qsl(env['QUERY_STRING'], 1))
        else:
            args = {}

        path = None

        if 'partNumber' in args:
            partNo = args['partNumber']

        uploadId = None
        if 'uploadId' in args:
            uploadId = args['uploadId']
        if 'QUERY_STRING' in env:
            del env['QUERY_STRING']

        if 'HTTP_CONTENT_MD5' in env.items():
            value = env['HTTP_CONTENT_MD5']
            if value == '':
                return get_err_response('InvalidDigest')
            try:
                env['HTTP_ETAG'] = value.decode('base64').encode('hex')
            except:
                return get_err_response('InvalidDigest')

            if env['HTTP_ETAG'] == '':
                return get_err_response('SignatureDoesNotMatch')

        #
        # If this is part of an S3 multipart upload, then put the parts
        # into the proper segment container instead of the primary container
        # that was requested.  This mimics the SWIFT multipart upload behavior
        # and leaves the objects so that they can be accessed by SWIFT or S3
        # API calls.
        #
        path = env['PATH_INFO']
        if path is not None and uploadId is not None and partNo is not None:
            version, account, container, obj = split_path(path, 0, 4, True)
            env['PATH_INFO'] = ('/%s/%s/%s_segments/%s/%s/%d' %
                                (version, account, container, obj, uploadId,
                                 int(partNo)))
            env['RAW_PATH_INFO'] = ('/%s_segments/%s/%s/%08d' %
                                    (container, obj, uploadId, int(partNo)))

        return self.app(env, start_response)
开发者ID:Grindizer,项目名称:s3multi,代码行数:94,代码来源:middleware.py

示例5: handle_request

# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers['Authorization'] [as 别名]
    def handle_request(self, env, start_response):
        req = Request(env)
        self.logger.debug('Calling Swift3 Middleware')
        self.logger.debug(req.__dict__)

        # Let's add a translation layer for tempurl so the QS resembles the amazon one.
        if env and 'QUERY_STRING' in env:
            self.logger.debug("Swift3 Middleware pre-TRANSLATE: %s" % env['QUERY_STRING'])
            env['QUERY_STRING'] = swift_tempurl_translate(env['QUERY_STRING'])
            self.logger.debug("Swift3 Middleware post-TRANSLATE: %s" % env['QUERY_STRING'])

        if 'AWSAccessKeyId' in req.params:
            try:
                req.headers['Date'] = req.params['Expires']
                req.headers['Authorization'] = \
                    'AWS %(AWSAccessKeyId)s:%(Signature)s' % req.params
            except KeyError:
                return get_err_response('InvalidArgument')(env, start_response)

        if 'Authorization' not in req.headers:
            return self.app(env, start_response)

        try:
            keyword, info = req.headers['Authorization'].split(' ')
        except:
            return get_err_response('AccessDenied')(env, start_response)

        if keyword != 'AWS':
            return get_err_response('AccessDenied')(env, start_response)

        try:
            account, signature = info.rsplit(':', 1)
        except:
            return get_err_response('InvalidArgument')(env, start_response)

        try:
            controller, path_parts = self.get_controller(env['PATH_INFO'])
        except ValueError:
            return get_err_response('InvalidURI')(env, start_response)

        if 'Date' in req.headers:
            date = email.utils.parsedate(req.headers['Date'])
            if date is None:
                return get_err_response('AccessDenied')(env, start_response)

            d1 = datetime.datetime(*date[0:6])
            d2 = datetime.datetime.utcnow()
            epoch = datetime.datetime(1970, 1, 1, 0, 0, 0, 0)

            if d1 < epoch:
                return get_err_response('AccessDenied')(env, start_response)

            delta = datetime.timedelta(seconds=60 * 10)
            if d1 - d2 > delta or d2 - d1 > delta:
                return get_err_response('RequestTimeTooSkewed')(env,
                                                                start_response)

        token = (base64.urlsafe_b64encode(canonical_string(req)),
                  base64.urlsafe_b64encode(canonical_string(req, alt=True)))


        controller = controller(env, self.app, account, token, conf=self.conf, logger=self.logger,
                                **path_parts)

        if hasattr(controller, req.method):
            res = getattr(controller, req.method)(env, start_response)
        else:
            return get_err_response('InvalidURI')(env, start_response)

        return res(env, start_response)
开发者ID:kostecky,项目名称:swift3,代码行数:72,代码来源:middleware.py


注:本文中的swift.common.swob.Request.headers['Authorization']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。