openstack context
2024-10-12 04:34:10
之前一直不知道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
最新文章
- ((uchar*)(Img1->;imageData + Img1->;widthStep*pt.y))[pt.x] 的 具体含义
- CXF 动态创建客户端调用稳定版本号为2.7.18
- js转html实体
- 使用Ant打包工具 基本介绍
- AUPE学习第八章------进程控制
- ASP的高效率的分页算法.net,php同样可以参考
- VShell破解版
- Unix:关于一个file在file system和disk中占用空间
- 优雅地实现CSS Animation delay
- Python爬虫之ip代理池
- Redisson 分布式锁
- CodeBlocks无法调试的解决方法
- VSCode插件开发全攻略(六)开发调试技巧
- C#设计模式之6:抽象工厂模式
- WPS for Linux
- django过滤器,日期格式化
- PAT L3-010 是否完全二叉搜索树(二叉搜索树)
- Python urllib模块学习
- PostgreSQL的autovacuum 与 vacuum full
- bzoj 4552