首页 > 其他 > 详细

openstack context

时间:2015-03-06 14:06:00      阅读:311      评论:0      收藏:0      [点我收藏+]
之前一直不知道context模块中存储的是什么东西,这回看一下代码;
其中最主要的类是:RequestContext;
class RequestContext(object):
 
"""Helper class to represent useful information about a request context.
 
Stores information about the security context under which the user
accesses the system, as well as additional request information.
"""
 
    user_idt_format = ‘{user} {tenant} {domain} {user_domain} {p_domain}‘
 
    def __init__(self, auth_token=None, user=None, tenant=None, domain=None,
                       user_domain=None, project_domain=None, is_admin=False,
                       read_only=False, show_deleted=False, request_id=None,
                       instance_uuid=None):
        self.auth_token = auth_token
        self.user = user
        self.tenant = tenant
        self.domain = domain
        self.user_domain = user_domain
        self.project_domain = project_domain
        self.is_admin = is_admin
        self.read_only = read_only
        self.show_deleted = show_deleted
        self.instance_uuid = instance_uuid
        if not request_id:
            request_id = generate_request_id()
        self.request_id = request_id
        …...
"""Helper class to represent useful information about a request context.
 
Stores information about the security context under which the user
accesses the system, as well as additional request information.
"""
RequestContext类主要保存了一次web请求的useful context information,主要包括安全验证信息和其他一些信息;
如果用户想要对request的上下文新增一些信息,或加强功能,可以继承这个类;
 
其中两个函数分别获取admin上下文信息,和判断一个context是不是一个normal user:
def get_admin_context(show_deleted=False):
    context = RequestContext(None,
                    tenant=None,
                    is_admin=True,
                    show_deleted=show_deleted)
    return context
 
def is_user_context(context):
"""Indicates if the request context is a normal user."""
    if not context:
        return False
    if context.is_admin:
        return False
    if not context.user_id or not context.project_id:
        return False
    return True
 

openstack context

原文:http://www.cnblogs.com/yuhan-TB/p/4318032.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!