Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
python3-dmapi / usr / lib / python3 / dist-packages / dmapi / __pycache__ / context.cpython-35.pyc
Size: Mime:


çáþ\Ù8ã@s©dZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZddlZdd
lmZddlmZddlmZdd
lmZejeƒZeƒZeƒZGdd„dejƒZ ej!Gdd„de
j"ƒƒZ"dd„Z#ddd„Z$dd„Z%dd„Z&dd„Z'dd„Z(dd „Z)ia*d!d"„Z+ed#d$„ƒZ,dS)%zGRequestContext: context for requests that persist through all of dmapi.éN)Úcontextmanager)Úservice_catalog)Úplugin)Úcontext)Úenginefacade)Úlog)Ú	timeutils)Ú	exception)Ú_)Úpolicy)ÚutilscsLeZdZdZ‡fdd†Zdd„Zdddddd„Z‡S)	Ú_ContextAuthPluginzñA keystoneauth auth plugin that uses the values from the Context.

    Ideally we would use the plugin provided by auth_token middleware however
    this plugin isn't serialized yet so we construct one from the serialized
    auth data.
    cs2tt|ƒjƒ||_tj|ƒ|_dS)N)Úsuperr
Ú__init__Ú
auth_tokenÚksa_service_catalogZServiceCatalogV2r)ÚselfrZsc)Ú	__class__©ú//usr/lib/python3/dist-packages/dmapi/context.pyr)s	z_ContextAuthPlugin.__init__cOs|jS)N)r)rÚargsÚkwargsrrrÚ	get_token/sz_ContextAuthPlugin.get_tokenNc	Ks%|jjd|d|d|d|ƒS)NÚservice_typeÚservice_nameÚ	interfaceÚregion_name)rZurl_for)rZsessionrrrrrrrrÚget_endpoint2sz_ContextAuthPlugin.get_endpoint)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rrrrr)rrr
!s
r
c
sñeZdZdZdddddddddd‡fdd†
Zdd„Zd	d
„Zdd„Zd
d„Ze	eeeƒZ
‡fdd†Ze‡fdd†ƒZ
ddd„Zdddd„Z‡fdd†Zdd„Z‡S)ÚRequestContextzpSecurity context and request information.

    Represents the user taking a given action within the system.
    NÚnoFcsò|r||d<|r ||d<tt|ƒjd||||_||_|s`tjƒ}t|tj	ƒrtj
|ƒ}||_|r©dd„|Dƒ|_n	g|_|	|_
||_|
|_|jdkrîtj|ƒ|_dS)aÉ:param read_deleted: 'no' indicates deleted records are hidden,
                'yes' indicates deleted records are visible,
                'only' indicates that *only* deleted records are visible.

           :param overwrite: Set to False to ensure that the greenthread local
                copy of the index is not overwritten.

           :param user_auth_plugin: The auth plugin for the current request's
                authentication data.
        ÚuserZtenantÚis_adminc
Ss+g|]!}|jdƒdkr|‘qS)	ÚtypeÚimageú
block-storageÚvolumev2Úvolumev3úkey-managerÚ	placementÚnetwork)r'r(r)r*r+r,znetwork)Úget)Ú.0Úsrrrú
<listcomp>cs	z+RequestContext.__init__.<locals>.<listcomp>N)rr"rÚread_deletedÚremote_addressrÚutcnowÚ
isinstanceÚsixÚstring_typesZ
parse_strtimeÚ	timestamprÚinstance_lock_checkedÚquota_classÚuser_auth_pluginr%rZcheck_is_admin)rÚuser_idÚ
project_idr%r2r3r8r:rr9r;r)rrrr@s(

							zRequestContext.__init__cCs'|jr|jSt|j|jƒSdS)N)r;r
rr)rrrrÚget_auth_pluginvs	zRequestContext.get_auth_plugincCs|jS)N)Ú
_read_deleted)rrrrÚ_get_read_deleted|sz RequestContext._get_read_deletedcCs/|dkr"ttdƒ|ƒ‚||_dS)Nr#ÚyesÚonlyz=read_deleted can only be one of 'no', 'yes' or 'only', not %r)znozyeszonly)Ú
ValueErrorr
r?)rr2rrrÚ_set_read_deleteds
z RequestContext._set_read_deletedcCs
|`dS)N)r?)rrrrÚ_del_read_deleted…sz RequestContext._del_read_deletedcs2tt|ƒjƒ}|jdt|ddƒdt|ddƒdt|ddƒdt|ddƒdt|ddƒdt|dƒr™tj|jƒnddt|ddƒd	t|d	dƒd
t|d
dƒdt|ddƒdt|ddƒd
t|d
dƒiƒ|jdt|ddƒiƒ|S)Nr<r=r%r2r#r3r8Z
request_idr:Z	user_namerÚproject_namer9FZis_admin_projectT)	rr"Úto_dictÚupdateÚgetattrÚhasattrrZstrtimer8)rÚvalues)rrrrG‹s&!
zRequestContext.to_dictcs”tt|ƒj|d|jdƒd|jdƒd|jddƒd|jdƒd|jdƒd|jdƒd|jdƒd	|jd	d
ƒƒS)Nr<r=r2r#r3r8r:rr9F)rr"Ú	from_dictr.)ÚclsrK)rrrrL©szRequestContext.from_dictcCsetj|ƒ}tj|jƒ|_d|_d|jkrL|jjdƒ|dk	ra||_|S)z5Return a version of this context with admin flag set.TZadminN)ÚcopyÚdeepcopyZrolesr%Úappendr2)rr2rrrrÚelevatedºs		zRequestContext.elevatedTcCsd|dkr$d|jd|ji}ytj|||ƒSWn"tjk
r_|rW‚dSYnXdS)aRVerifies that the given action is valid on the target in this context.

        :param action: string representing the action to be checked.
        :param target: dictionary representing the object of the action
            for object creation this should be a dictionary representing the
            location of the object e.g. ``{'project_id': context.project_id}``.
            If None, then this default target will be considered:
            {'project_id': self.project_id, 'user_id': self.user_id}
        :param fatal: if False, will return False when an exception.Forbidden
           occurs.

        :raises dmapi.exception.Forbidden: if verification fails and fatal is
            True.

        :return: returns a non-False value (not necessarily "True") if
            authorized and False if not authorized and fatal is False.
        Nr=r<F)r=r<rZ	authorizer	Ú	Forbidden)rÚactionÚtargetÚfatalrrrÚcanÊs	zRequestContext.cancs&tt|ƒjƒ}|j|d<|S)Nr%)rr"Úto_policy_valuesr%)rr)rrrrWçs
zRequestContext.to_policy_valuescCsd|jƒS)Nz<Context %s>)rG)rrrrÚ__str__ìszRequestContext.__str__)rrr r!rr>r@rDrEÚpropertyr2rGÚclassmethodrLrQrVrWrXrr)rrr":s"		3		r"c	CstddddddddƒS)z·A helper method to get a blank context.

    Note that overwrite is False here so this context will not update the
    greenthread-local stored context that is used when logging.
    r<Nr=r%FÚ	overwrite)r"rrrrÚget_contextðsr\r#cCs%tddddddd|ddƒS)Nr<r=r%Tr2r[F)r")r2rrrÚget_admin_contextüs
r]cCs3|s
dS|jrdS|js+|jr/dSdS)z2Indicates if the request context is a normal user.FT)r%r<r=)rrrrÚis_user_context
s	r^cCs'|jr#t|ƒr#tjƒ‚dS)zRRaise exception.Forbidden() if context is not a user or an
    admin context.
    N)r%r^r	rR)ZctxtrrrÚrequire_contextsr_cCsCt|ƒr?|js$tjƒ‚n|j|kr?tjƒ‚dS)z=Ensures a request has permission to access the given project.N)r^r=r	rR)rr=rrrÚauthorize_project_contexts
	r`cCsCt|ƒr?|js$tjƒ‚n|j|kr?tjƒ‚dS)z:Ensures a request has permission to access the given user.N)r^r<r	rR)rr<rrrÚauthorize_user_context&s
	racCsCt|ƒr?|js$tjƒ‚n|j|kr?tjƒ‚dS)zAEnsures a request has permission to access the given quota class.N)r^r:r	rR)rÚ
class_namerrrÚauthorize_quota_class_context/s
	rccsyˆdk	rcddlm‰ddlm‰tjˆjƒ‡‡‡‡fdd†ƒ}|ƒndˆ_dˆ_dS)a¯Adds database connection information to the context
    for communicating with the given target_cell.

    This is used for permanently targeting a cell in a context.
    Use this when you want all subsequent code to target a cell.

    Passing None for cell_mapping will untarget the context.

    :param context: The RequestContext to add connection information
    :param cell_mapping: An objects.CellMapping object or None
    Nr)Údb)ÚrpccsŸytˆj}Wnmtk
r€ˆj}ˆj|ƒˆ_ˆjjdƒscˆjˆjƒˆ_	ˆjˆj	ftˆj<YnX|dˆ_|dˆ_	dS)NZnoneré)
Ú
CELL_CACHEÚuuidÚKeyErrorZdatabase_connectionZcreate_context_managerÚ
db_connectionZ
transport_urlÚ
startswithZcreate_transportÚ
mq_connection)Z
cell_tupleZdb_connection_string)Úcell_mappingrrdrerrÚ*get_or_set_cached_cell_and_set_connectionsLs
	
zCset_target_cell.<locals>.get_or_set_cached_cell_and_set_connections)ÚdmapirdrerZsynchronizedrhrjrl)rrmrnr)rmrrdrerÚset_target_cell9s
-
	rpccs+tj|jƒƒ}t||ƒ|VdS)a¡Yields a new context with connection information for a specific cell.

    This function yields a copy of the provided context, which is targeted to
    the referenced cell for MQ and DB connections.

    Passing None for cell_mapping will yield an untargetd copy of the context.

    :param context: The RequestContext to add connection information
    :param cell_mapping: An objects.CellMapping object or None
    N)r"rLrGrp)rrmZcctxtrrrÚtarget_cellcs
rq)-r!rNÚ
contextlibrZkeystoneauth1.accessrrZ
keystoneauth1rZoslo_contextrZoslo_db.sqlalchemyrZoslo_logrÚloggingZ
oslo_utilsrr6ror	Z
dmapi.i18nr
rrÚ	getLoggerrZLOGÚobjectZdid_not_respond_sentinelZraised_exception_sentinelZBaseAuthPluginr
Ztransaction_context_providerr"r\r]r^r_r`rarcrgrprqrrrrÚ<module>s:		µ			*