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-el9 / usr / lib / python3.9 / site-packages / dmapi / __pycache__ / context.cpython-39.pyc
Size: Mime:
a

[r`e9ã@s.dZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZddlZdd
lmZddlmZddlmZdd
lmZe e¡ZeƒZeƒZGdd„dejƒZ ej!Gdd„de
j"ƒƒZ"dd„Z#d%dd„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)Úutilscs2eZdZdZ‡fdd„Zdd„Zd	dd„Z‡ZS)
Ú_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.
    cs$tt|ƒ ¡||_t |¡|_dS©N)ÚsuperrÚ__init__Ú
auth_tokenÚksa_service_catalogZServiceCatalogV2r)ÚselfrZsc©Ú	__class__©ú1/usr/lib/python3.9/site-packages/dmapi/context.pyr)sz_ContextAuthPlugin.__init__cOs|jSr)r)rÚargsÚkwargsrrrÚ	get_token/sz_ContextAuthPlugin.get_tokenNcKs|jj||||dS)N)Úservice_typeÚservice_nameÚ	interfaceÚregion_name)rZurl_for)rZsessionrrrrrrrrÚget_endpoint2s
ýz_ContextAuthPlugin.get_endpoint)NNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rrr Ú
__classcell__rrrrr!sÿrc
s’eZdZdZd‡fdd„	Zdd„Zd	d
„Zdd„Zd
d„Ze	eeeƒZ
‡fdd„Ze‡fdd„ƒZ
ddd„Zddd„Z‡fdd„Zdd„Z‡ZS)ÚRequestContextzpSecurity context and request information.

    Represents the user taking a given action within the system.
    NÚnoFcsº|r||d<|r||d<| dd¡tt|ƒjfd|i|¤Ž||_||_|sVt ¡}t|t	j
ƒrlt |¡}||_|rˆdd„|Dƒ|_
ng|_
|	|_||_|
|_|jdur¶t |¡|_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.
        ÚuserÚ
project_idZtenantNÚis_admincSsg|]}| d¡dvr|‘qS)Útype)Zimagez
block-storageZvolumev2Zvolumev3zkey-managerZ	placementZnetwork)Úget)Ú.0ÚsrrrÚ
<listcomp>dsÿz+RequestContext.__init__.<locals>.<listcomp>)Úpoprr&rÚread_deletedÚremote_addressr	ZutcnowÚ
isinstanceÚsixZstring_typesZ
parse_strtimeÚ	timestamprÚinstance_lock_checkedÚquota_classÚuser_auth_pluginr*rZcheck_is_admin)rÚuser_idr)r*r1r2r5r7rr6r8rrrrr@s*

zRequestContext.__init__cCs|jr|jSt|j|jƒSdSr)r8rrr©rrrrÚget_auth_pluginwszRequestContext.get_auth_plugincCs|jSr©Ú
_read_deletedr:rrrÚ_get_read_deleted}sz RequestContext._get_read_deletedcCs"|dvrttdƒ|ƒ‚||_dS)N)r'ZyesZonlyz=read_deleted can only be one of 'no', 'yes' or 'only', not %r)Ú
ValueErrorrr=)rr1rrrÚ_set_read_deleted€s
ÿz RequestContext._set_read_deletedcCs|`dSrr<r:rrrÚ_del_read_deleted†sz RequestContext._del_read_deletedcsºtt|ƒ ¡}| t|ddƒt|ddƒt|ddƒt|ddƒt|ddƒt|dƒrZt |j¡ndt|ddƒt|d	dƒt|d
dƒt|ddƒt|ddƒt|d
dƒdœ¡| dt|ddƒi¡|S)Nr9r)r*r1r'r2r5Ú
request_idr7Ú	user_namerÚproject_namer6F)r9r)r*r1r2r5rBr7rCrrDr6Zis_admin_projectT)	rr&Úto_dictÚupdateÚgetattrÚhasattrr
Zstrtimer5)rÚvaluesrrrrEŒs0




ÿ




ÿóÿzRequestContext.to_dictc
sVtt|ƒj|| d¡| d¡| dd¡| d¡| d¡| d¡| d¡| d	d
¡d	S)Nr9r)r1r'r2r5r7rr6F)r9r)r1r2r5r7rr6)rr&Ú	from_dictr,)ÚclsrIrrrrJªs


ôzRequestContext.from_dictcCsFt |¡}t |j¡|_d|_d|jvr4|j d¡|durB||_|S)z5Return a version of this context with admin flag set.TZadminN)ÚcopyÚdeepcopyZrolesr*Úappendr1)rr1rrrrÚelevated»s

zRequestContext.elevatedTcCsH|dur|j|jdœ}zt |||¡WStjyB|r<‚YdS0dS)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.
        N)r)r9F)r)r9rZ	authorizer
Ú	Forbidden)rÚactionÚtargetZfatalrrrÚcanËsÿzRequestContext.cancstt|ƒ ¡}|j|d<|S)Nr*)rr&Úto_policy_valuesr*)rrrrrrTès
zRequestContext.to_policy_valuescCsd| ¡S)Nz<Context %s>)rEr:rrrÚ__str__íszRequestContext.__str__)
NNNr'NNNNFN)N)NT)r!r"r#r$rr;r>r@rAÚpropertyr1rEÚclassmethodrJrOrSrTrUr%rrrrr&:s(ý7ÿ

r&cCstddddd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.
    NF)r9r)r*Ú	overwrite©r&rrrrÚget_contextñs
ýrZr'cCstddd|ddS)NTF)r9r)r*r1rXrY)r1rrrÚget_admin_contextýsür[cCs&|sdS|jrdS|jr|js"dSdS)z2Indicates if the request context is a normal user.FT)r*r9r)rrrrÚis_user_contextsr\cCs|jst|ƒst ¡‚dS)zRRaise exception.Forbidden() if context is not a user or an
    admin context.
    N)r*r\r
rP)ZctxtrrrÚrequire_contextsr]cCs.t|ƒr*|jst ¡‚n|j|kr*t ¡‚dS)z=Ensures a request has permission to access the given project.N)r\r)r
rP)rr)rrrÚauthorize_project_contexts


r^cCs.t|ƒr*|jst ¡‚n|j|kr*t ¡‚dS)z:Ensures a request has permission to access the given user.N)r\r9r
rP)rr9rrrÚauthorize_user_context's


r_cCs.t|ƒr*|jst ¡‚n|j|kr*t ¡‚dS)zAEnsures a request has permission to access the given quota class.N)r\r7r
rP)rÚ
class_namerrrÚauthorize_quota_class_context0s


racsVˆdurFddlm‰ddlm‰t ˆj¡‡‡‡‡fdd„ƒ}|ƒndˆ_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)Úrpccsxztˆj}WnPty^ˆj}ˆ |¡ˆ_ˆj d¡sHˆ ˆj¡ˆ_	ˆjˆj	ftˆj<Yn0|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_mappingrrbrcrrÚ*get_or_set_cached_cell_and_set_connectionsMs ÿÿÿ
zCset_target_cell.<locals>.get_or_set_cached_cell_and_set_connections)Údmapirbrcr
Zsynchronizedrfrhrj)rrlrmrrkrÚset_target_cell:s

roccs"t | ¡¡}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&rJrEro)rrlZcctxtrrrÚtarget_cellds
rp)r')-r$rLÚ
contextlibrZkeystoneauth1.accessrrZ
keystoneauth1rZoslo_contextrZoslo_db.sqlalchemyrZoslo_logrZloggingZ
oslo_utilsr	r4rnr
Z
dmapi.i18nrrr
Z	getLoggerr!ZLOGÚobjectZdid_not_respond_sentinelZraised_exception_sentinelZBaseAuthPluginrZtransaction_context_providerr&rZr[r\r]r^r_rarerorprrrrÚ<module>s>
7
			*