• openstack context


    之前一直不知道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
     
  • 相关阅读:
    占位
    JavaScript(13):用jQuery实现复选框的全、反、取选
    JavaScript(12):jQuery(1)
    JavaScript(11):词法分析
    JavaScript(10):行为(HTML)、结构(CSS)、样式(JS)相分离的页面
    JavaScript(9):非常规form表单提交、弹出框、URL和刷新、定时器
    JavaScript(8):搜索框示例实现、样式操作、属性操作、标签操作
    JavaScript(7):DOM直接查找与间接查找的补充
    JavaScript(6):作用域、面向对象
    开篇杂谈
  • 原文地址:https://www.cnblogs.com/yuhan-TB/p/4318032.html
Copyright © 2020-2023  润新知