The oslo_context.context Module

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=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, resource_uuid=None, overwrite=True, roles=None, user_name=None, project_name=None, domain_name=None, user_domain_name=None, project_domain_name=None, is_admin_project=True, service_token=None, service_user_id=None, service_user_name=None, service_user_domain_id=None, service_user_domain_name=None, service_project_id=None, service_project_name=None, service_project_domain_id=None, service_project_domain_name=None, service_roles=None, global_request_id=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.

domain
domain_id
classmethod from_dict(values, **kwargs)

Construct a context object from a provided dictionary.

classmethod from_environ(environ, **kwargs)

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()

Return a dictionary of logging specific context attributes.

global_id

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.

project_domain
project_domain_id
project_id
tenant
to_dict()

Return a dictionary of context attributes.

to_policy_values()

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()

Store the context in the current thread.

user
user_domain
user_domain_id
user_id
user_idt_format = u'{user} {tenant} {domain} {user_domain} {p_domain}'
oslo_context.context.generate_request_id()

Generate a unique request id.

oslo_context.context.get_admin_context(show_deleted=False)

Create an administrator context.

oslo_context.context.get_context_from_function_and_args(function, args, kwargs)

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()

Return this thread’s current context

If no context is set, returns None

oslo_context.context.is_user_context(context)

Indicates if the request context is a normal user.

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.