• 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
     
  • 相关阅读:
    使用mybatis如果类属性名和数据库中的属性名不一样取值就会为null
    学习mybatis时出现了java.io.IOException: Could not find resource EmployeeMapper.xml
    配置mybatis-config.xml出现过很诡异的现象
    mybatis学习(一)
    报错cannot be cast to javassist.util.proxy.Proxy
    列车调度
    三角形
    土豪聪要请客(stol)
    Jams倒酒(pour)
    Data
  • 原文地址:https://www.cnblogs.com/yuhan-TB/p/4318032.html
Copyright © 2020-2023  润新知