您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關如何進行NoAuthMiddlewareBase及NoAuthMiddleware解析,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
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
class NoAuthMiddleware(NoAuthMiddlewareBase): #繼承父類 @webob.dec.wsgify(RequestClass=wsgi.Request)def __call__(self, req): return self.base_call(req, True, always_admin=False) #調用父類的具體實現
上述就是小編為大家分享的如何進行NoAuthMiddlewareBase及NoAuthMiddleware解析了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。