@ -36,30 +36,26 @@ class ContextBase(oslo_context.RequestContext):
"""
def __init__ ( self , user_id , tenant_id , is_admin = None , roles = None ,
timestamp = None , request_id = None , tenant_name = None ,
user_name = None , overwrite = True , auth_token = None ,
* * kwargs ) :
""" Object initialization.
: param overwrite : Set to False to ensure that the greenthread local
copy of the index is not overwritten .
: param kwargs : Extra arguments that might be present , but we ignore
because they possibly came in from older rpc messages .
"""
super ( ContextBase , self ) . __init__ ( auth_token = auth_token ,
user = user_id , tenant = tenant_id ,
is_admin = is_admin ,
request_id = request_id ,
overwrite = overwrite ,
roles = roles )
def __init__ ( self , user_id = None , tenant_id = None , is_admin = None ,
timestamp = None , tenant_name = None , user_name = None ,
is_advsvc = None , * * kwargs ) :
# NOTE(jamielennox): We maintain this argument in order for tests that
# pass arguments positionally.
kwargs . setdefault ( ' project_id ' , tenant_id )
# prefer project_name, as that's what's going to be set by
# keystone. Fall back to tenant_name if for some reason it's blank.
kwargs . setdefault ( ' project_name ' , tenant_name )
super ( ContextBase , self ) . __init__ (
is_admin = is_admin , user_id = user_id , * * kwargs )
self . user_name = user_name
self . tenant_name = tenant_name
if not timestamp :
timestamp = datetime . datetime . utcnow ( )
self . timestamp = timestamp
# self.is_advsvc = is_advsvc
# if self.is_advsvc is None:
# self.is_advsvc = self.is_admin or policy.check_is_advsvc(self)
if self . is_admin is None :
self . is_admin = policy . check_is_admin ( self )
@ -75,6 +71,14 @@ class ContextBase(oslo_context.RequestContext):
def tenant_id ( self , tenant_id ) :
self . tenant = tenant_id
@property
def tenant_name ( self ) :
return self . project_name
@tenant_name.setter
def tenant_name ( self , tenant_name ) :
self . project_name = tenant_name
@property
def user_id ( self ) :
return self . user
@ -98,7 +102,35 @@ class ContextBase(oslo_context.RequestContext):
@classmethod
def from_dict ( cls , values ) :
return cls ( * * values )
return cls ( user_id = values . get ( ' user_id ' , values . get ( ' user ' ) ) ,
tenant_id = values . get ( ' tenant_id ' , values . get ( ' project_id ' ) ) ,
is_admin = values . get ( ' is_admin ' ) ,
roles = values . get ( ' roles ' ) ,
timestamp = values . get ( ' timestamp ' ) ,
request_id = values . get ( ' request_id ' ) ,
tenant_name = values . get ( ' tenant_name ' ) ,
user_name = values . get ( ' user_name ' ) ,
auth_token = values . get ( ' auth_token ' ) )
def to_policy_values ( self ) :
values = super ( ContextBase , self ) . to_policy_values ( )
values [ ' tenant_id ' ] = self . project_id
values [ ' is_admin ' ] = self . is_admin
# NOTE(jamielennox): These are almost certainly unused and non-standard
# but kept for backwards compatibility. Remove them in Pike
# (oslo.context from Ocata release already issues deprecation warnings
# for non-standard keys).
values [ ' user ' ] = self . user_id
values [ ' tenant ' ] = self . project_id
values [ ' domain ' ] = self . domain_id
values [ ' user_domain ' ] = self . user_domain_id
values [ ' project_domain ' ] = self . project_domain_id
values [ ' tenant_name ' ] = self . project_name
values [ ' project_name ' ] = self . project_name
values [ ' user_name ' ] = self . user_name
return values
def elevated ( self ) :
""" Return a version of this context with admin flag set. """