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.6 / site-packages / dmapi / __pycache__ / policy.cpython-36.pyc
Size: Mime:
3

·‰Ec4"ã@sdZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZmZdd	l
mZejZejeƒZdad
gZgaejdƒZdd
„Zd'dd„Zdd„Zdd„Zd(dd„Z d)dd„Z!dd„Z"e
j#dƒGdd„de
j$ƒƒZ%dd „Z&d!d"„Z'd#d$„Z(d%d&„Z)dS)*zPolicy Engine For Dmapi.éN)Úcfg)Úlog)Úpolicy)Úexcutils)Ú	exception)Ú_LEÚ_LW)Úpolicieszos-keypairsz%\((\w+)\)scCstrtjƒdadS)N)Ú	_ENFORCERÚclear©rrú/usr/lib/python3.6/policy.pyÚreset"srTcCsTts(tjt||||dattƒtjƒtj}t|ƒ}t|krPt	|ƒt
j|ƒadS)aëInit an Enforcer class.

       :param policy_file: Custom policy file to use, if none is specified,
                           `CONF.policy_file` will be used.
       :param rules: Default dictionary / Rules to use. It will be
                     considered just in the first instantiation.
       :param default_rule: Default rule to use, CONF.default_rule will
                            be used if none is specified.
       :param use_conf: Whether to load rules from config file.
    )Úpolicy_fileÚrulesÚdefault_ruleÚuse_confN)r
rZEnforcerÚCONFÚregister_rulesZ
load_rulesZ
file_rulesÚ_serialize_rulesÚsaved_file_rulesÚ(_warning_for_deprecated_user_based_rulesÚcopyÚdeepcopy)rrrrZcurrent_file_rulesrrr
Úinit)srcCs&dd„t|jƒƒDƒ}t|dd„dS)zYSerialize all the Rule object as string which is used to compare the
    rules list.
    cSsg|]\}}|t|ƒf‘qSr)Ústr)Ú.0Z	rule_nameÚrulerrr
ú
<listcomp>Osz$_serialize_rules.<locals>.<listcomp>cSs|dS)Nrr)rrrr
Ú<lambda>Qsz"_serialize_rules.<locals>.<lambda>)Úkey)ÚlistÚitemsÚsorted)rÚresultrrr
rKsrcsLxF|D]>‰‡fdd„tDƒrqdtjˆdƒkrtjtdƒˆdƒqWdS)z`Warning user based policy enforcement used in the rule but the rule
    doesn't support it.
    csg|]}|ˆdkr|‘qS)rr)rZresource)rrr
r[sz<_warning_for_deprecated_user_based_rules.<locals>.<listcomp>Zuser_idézThe user_id attribute isn't supported in the rule '%s'. All the user_id based policy enforcement will be removed in the future.rN)ÚUSER_BASED_RESOURCESÚKEY_EXPRÚfindallÚLOGÚwarningr)rr)rr
rTs

rFcCstddtj|||ƒdS)a7Set rules based on the provided dict of rules.

       :param rules: New rules to use. It should be an instance of dict.
       :param overwrite: Whether to overwrite current rules or update them
                         with the new rules.
       :param use_conf: Whether to reload rules from config file.
    F)rN)rr
Ú	set_rules)rZ	overwriterrrr
r+es	
r+cCs¨tƒ|jƒ}|stj}ytj||||||d}Wnptjk
rjtj	ƒt
jtdƒƒWdQRXYn:tk
r¢tj	ƒt
j
d||dœƒWdQRXYnX|S)acVerifies that the action is valid on the target in this context.

       :param context: dmapi context
       :param action: string representing the action to be checked
           this should be colon separated for clarity.
           i.e. ``compute:create_instance``,
           ``compute:attach_volume``,
           ``volume:attach_volume``
       :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}``
       :param do_raise: if True (the default), raises PolicyNotAuthorized;
           if False, returns False
       :param exc: Class of the exception to raise if the check fails.
                   Any remaining arguments passed to :meth:`authorize` (both
                   positional and keyword arguments) will be passed to
                   the exception class. If not specified,
                   :class:`PolicyNotAuthorized` will be used.

       :raises dmapi.exception.PolicyNotAuthorized: if verification fails
           and do_raise is True. Or if 'exc' is specified it will raise an
           exception of that type.

       :return: returns a non-False value (not necessarily "True") if
           authorized, and the exact value False if not authorized and
           do_raise is False.
    )Údo_raiseÚexcÚactionzPolicy not registeredNzCPolicy check for %(action)s failed with credentials %(credentials)s)r.Úcredentials)rÚto_policy_valuesrZPolicyNotAuthorizedr
Ú	authorizerZPolicyNotRegisteredrZsave_and_reraise_exceptionr)rÚ	ExceptionÚdebug)Úcontextr.Útargetr,r-r/r$rrr
r1rs


r1cCs tƒ|jƒ}|}tjd||ƒS)zMWhether or not roles contains 'admin' role according to policy setting.

    Zcontext_is_admin)rr0r
r1)r4r/r5rrr
Úcheck_is_admin sr6Úis_admincs(eZdZdZ‡fdd„Zdd„Z‡ZS)ÚIsAdminCheckzAn explicit check for is_admin.cs*|jƒdk|_tt|ƒj|t|jƒƒdS)zInitialize the check.ÚtrueN)ÚlowerÚexpectedÚsuperr8Ú__init__r)ÚselfZkindÚmatch)Ú	__class__rr
r=°szIsAdminCheck.__init__cCs|d|jkS)z7Determine whether is_admin matches the requested value.r7)r;)r>r5ZcredsÚenforcerrrr
Ú__call__·szIsAdminCheck.__call__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r=rBÚ
__classcell__rr)r@r
r8¬sr8cCstr
tjSdS)N)r
rrrrr
Ú	get_rules½srHcCs|jtjƒƒdS)N)Zregister_defaultsr	Z
list_rules)rArrr
rÂsrcCsjg}d}xH|ttjƒkrPtj|jdƒdkr6|d7}q
|jtj|ƒ|d7}q
Wtj|ddtƒtS)	Nr%ú-Ú	namespaceúoutput-fileéÚdmapi)Zproject)rJrK)	ÚlenÚsysÚargvÚstripÚappendrrrr
)Z	conf_argsÚirrr
Úget_enforcerÆsrTcCsHtrttj|ƒ}nd}||kr@tjdj||ƒƒ|j|ƒdSdSdS)aCheck the rule of the deprecated policy action

    If the current rule of the deprecated policy action is set to a non-default
    value, then a warning message is logged stating that the new policy
    action should be used to dictate permissions as the old policy action is
    being deprecated.

    :param old_policy: policy action that is being deprecated
    :param new_policy: policy action that is replacing old_policy
    :param default_rule: the old_policy action default rule value
    :param context: the dmapi context
    NzvStart using the new action '{0}'. The existing action '{1}' is being deprecated and will be removed in future release.TF)r
rrr)r*ÚformatZcan)Z
old_policyZ
new_policyrr4Zcurrent_rulerrr
Úverify_deprecated_policyÚs
rV)NNNT)TF)TN)*rFrÚrerOZoslo_configrZoslo_logrZloggingZoslo_policyrZ
oslo_utilsrrMrZ
dmapi.i18nrrr	rZ	getLoggerrCr)r
r&rÚcompiler'rrrrr+r1r6ÚregisterZCheckr8rHrrTrVrrrr
Ú<module>s:


"	

.