The oslo_context.context
Module¶
Base class for holding contextual information of a request
This class has several uses:
Used for storing security information in a web request.
Used for passing contextual details to oslo.log.
Projects should subclass this class if they wish to enhance the request context or provide additional information in their specific WSGI pipeline or logging context.
- class oslo_context.context.RequestContext(auth_token: Optional[str] = None, user_id: Optional[str] = None, project_id: Optional[str] = None, domain_id: Optional[str] = None, user_domain_id: Optional[str] = None, project_domain_id: Optional[str] = None, is_admin: bool = False, read_only: bool = False, show_deleted: bool = False, request_id: Optional[str] = None, resource_uuid: Optional[str] = None, overwrite: bool = True, roles: Optional[List[str]] = None, user_name: Optional[str] = None, project_name: Optional[str] = None, domain_name: Optional[str] = None, user_domain_name: Optional[str] = None, project_domain_name: Optional[str] = None, is_admin_project: bool = True, service_token: Optional[str] = None, service_user_id: Optional[str] = None, service_user_name: Optional[str] = None, service_user_domain_id: Optional[str] = None, service_user_domain_name: Optional[str] = None, service_project_id: Optional[str] = None, service_project_name: Optional[str] = None, service_project_domain_id: Optional[str] = None, service_project_domain_name: Optional[str] = None, service_roles: Optional[List[str]] = None, global_request_id: Optional[str] = None, system_scope: Optional[str] = None)¶
Bases:
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.
- FROM_DICT_EXTRA_KEYS: List[str] = []¶
- property domain: Any¶
- property domain_id: Any¶
- classmethod from_dict(values: Dict[str, Any], **kwargs: Any) oslo_context.context.RequestContext ¶
Construct a context object from a provided dictionary.
- classmethod from_environ(environ: Dict[str, Any], **kwargs: Any) oslo_context.context.RequestContext ¶
Load a context object from a request environment.
If keyword arguments are provided then they override the values in the request environment.
- Parameters
environ (dict) – The environment dictionary associated with a request.
- get_logging_values() Dict[str, Any] ¶
Return a dictionary of logging specific context attributes.
- property global_id: str¶
Return a sensible value for global_id to pass on.
When we want to make a call with to another service, it’s important that we try to use global_request_id if available, and fall back to the locally generated request_id if not.
- property project_domain: Any¶
- property project_domain_id: Any¶
- property project_id: Any¶
- to_dict() Dict[str, Any] ¶
Return a dictionary of context attributes.
- to_policy_values() oslo_context.context._DeprecatedPolicyValues ¶
A dictionary of context attributes to enforce policy with.
oslo.policy enforcement requires a dictionary of attributes representing the current logged in user on which it applies policy enforcement. This dictionary defines a standard list of attributes that should be available for enforcement across services.
It is expected that services will often have to override this method with either deprecated values or additional attributes used by that service specific policy.
- update_store() None ¶
Store the context in the current thread.
- property user: Any¶
- property user_domain: Any¶
- property user_domain_id: Any¶
- property user_id: Any¶
- user_idt_format = '{user} {project_id} {domain} {user_domain} {p_domain}'¶
- oslo_context.context.generate_request_id() str ¶
Generate a unique request id.
- oslo_context.context.get_admin_context(show_deleted: bool = False) oslo_context.context.RequestContext ¶
Create an administrator context.
- oslo_context.context.get_context_from_function_and_args(function: Callable, args: List[Any], kwargs: Dict[str, Any]) Optional[oslo_context.context.RequestContext] ¶
Find an arg of type RequestContext and return it.
This is useful in a couple of decorators where we don’t know much about the function we’re wrapping.
- oslo_context.context.get_current() Optional[oslo_context.context.RequestContext] ¶
Return this thread’s current context
If no context is set, returns None
- oslo_context.context.is_user_context(context: oslo_context.context.RequestContext) bool ¶
Indicates if the request context is a normal user.