如何进行NoAuthMiddlewareBase及NoAuthMiddleware解析
这期内容当中小编将会给大家带来有关如何进行NoAuthMiddlewareBase及NoAuthMiddleware解析,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
站在用户的角度思考问题,与客户深入沟通,找到淮安区网站设计与淮安区网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站制作、做网站、企业官网、英文网站、手机端网站、网站推广、域名与空间、网站空间、企业邮箱。业务覆盖淮安区地区。
NoAuthMiddlewareBase解析
class NoAuthMiddlewareBase(base_wsgi.Middleware):"""如果请求头里没有指定对应的请求令牌,则返回一个伪造的令牌.""" def base_call(self, req, project_id_in_path, always_admin=True):if 'X-Auth-Token' not in req.headers: user_id = req.headers.get('X-Auth-User', 'admin')#设置默认的用户ID project_id = req.headers.get('X-Auth-Project-Id', 'admin')#设置默认的项目IDif project_id_in_path: os_url = '/'.join([req.url.rstrip('/'), project_id])else: os_url = req.url.rstrip('/') res = webob.Response()# NOTE(vish): This is expecting and returning Auth(1.1), whereas # keystone uses 2.0 auth. We should probably allow # 2.0 auth here as well. res.headers['X-Auth-Token'] = '%s:%s' % (user_id, project_id)#伪造token res.headers['X-Server-Management-Url'] = os_url #设置url res.content_type = 'text/plain' #设置content-type res.status = '204' return res token = req.headers['X-Auth-Token'] user_id, _sep, project_id = token.partition(':') project_id = project_id or user_id remote_address = getattr(req, 'remote_address', '127.0.0.1')if CONF.api.use_forwarded_for: remote_address = req.headers.get('X-Forwarded-For', remote_address) is_admin = always_admin or (user_id == 'admin') ctx = context.RequestContext(user_id, project_id, is_admin=is_admin, remote_address=remote_address)#封装请求上下文 req.environ['nova.context'] = ctxreturn self.application
NoAuthMiddleware解析
class NoAuthMiddleware(NoAuthMiddlewareBase): #继承父类 @webob.dec.wsgify(RequestClass=wsgi.Request)def __call__(self, req): return self.base_call(req, True, always_admin=False) #调用父类的具体实现
上述就是小编为大家分享的如何进行NoAuthMiddlewareBase及NoAuthMiddleware解析了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。
当前标题:如何进行NoAuthMiddlewareBase及NoAuthMiddleware解析
转载来于:http://scyingshan.cn/article/gppdhj.html