a )g_@sddlmZmZmZeZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZddlmZddlmZdd lmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$dd l%m&Z&m'Z'dd l(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/dd l0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6dd l7m8Z8m9Z9m:Z:m;Z;mZ>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHedZIe:de#de;de"ded% ZMd&d'ZNdLd(d)ZOdMd*d+ZPdNd,d-ZQdOd/d0ZRd1d2ZSd3d4ZTd5d6ZUdPd8d9ZVd:d;ZWdQdd?ZYdSd@dAZZdTdBdCZ[dDdEZ\dFdGZ]e^fdHdIZ_dJdKZ`dS)U)absolute_importdivisionprint_functionN)deque)chain) is_iterable)to_bytes to_nativeto_text)lenient_lowercase)warn) AliasErrorAnsibleFallbackNotFoundAnsibleValidationErrorMultipleArgumentTypeErrorArgumentValueError ElementErrorMutuallyExclusiveError NoLogErrorRequiredByError RequiredErrorRequiredIfErrorRequiredOneOfErrorRequiredTogetherErrorSubParameterTypeError)BOOLEANS_FALSE BOOLEANS_TRUE)KeysViewSetSequenceMappingMutableMapping MutableSetMutableSequence) binary_type integer_types string_types text_typePY2PY3)check_mutually_exclusivecheck_required_argumentscheck_required_togethercheck_required_one_ofcheck_required_ifcheck_required_bycheck_type_bitscheck_type_boolcheck_type_bytescheck_type_dictcheck_type_floatcheck_type_intcheck_type_jsonargcheck_type_listcheck_type_pathcheck_type_rawcheck_type_strZrequired_together)funcattrerrZrequired_one_ofZ required_ifZ required_by) check_modeF)Z_debugF)Z_diffF)Z_keep_remote_filesF)_nameN)no_logF)Z _remote_tmpNZ_selinux_special_fs)ZfusenfsZvboxsfZramfsZ9pZvfat)Z_shellz/bin/sh)Z _socket_pathN)Z_string_conversion_actionr )Z_syslog_facilityINFO)Z_tmpdirN)Z _verbosityr)Zansible_versionz0.0)r>debugdiffkeep_remote_filesZ module_namer@Z remote_tmpZselinux_special_fsZshell_executableZsocketZstring_conversion_actionZsyslog_facilityZtmpdir verbosityversion)r>rCrDrEr@) strlistdictboolintfloatpathrawZjsonargZjsonbytesbitscCs@t|s |durd}t|}n|}t|dtt|}||fS)aReturns the callable used to validate a wanted type and the type name. :arg wanted: String or callable. If a string, get the corresponding validation function from DEFAULT_TYPE_VALIDATORS. If callable, get the name of the custom callable and return that for the type_checker. :returns: Tuple of callable function or None, and a string that is the name of the wanted type. NrH__name__)callableDEFAULT_TYPE_VALIDATORSgetgetattrr type)wanted type_checkerrZJ/usr/lib/python3.9/site-packages/ansible/module_utils/common/parameters.py_get_type_validator{s  r\cCs*|durt||}t|t|SN)_handle_aliasesrIkeys) argument_spec parametersaliasesrZrZr[_get_legal_inputss rcc Cs|durt||}t}|D]r}||vr |}|rBt||g}|||dur t||}g} |D]} | |vrtqf| | qf||| |fiq |S)aCheck keys in parameters against those provided in legal_inputs to ensure they contain legal values. If legal_inputs are not supplied, they will be generated using the argument_spec. :arg argument_spec: Dictionary of parameters, their type, and valid values. :arg parameters: Dictionary of parameters. :arg legal_inputs: List of valid key names property names. Overrides values in argument_spec. :arg options_context: List of parent keys for tracking the context of where a parameter is defined. :returns: Set of unsupported parameters. Empty set if no unsupported parameters are found. N)rcsetr_tupleaddr^appendupdate) r`ra legal_inputsoptions_contextstore_supportedunsupported_parameterskcontextZsupported_aliasesZsupported_paramsoptionrZrZr[_get_unsupported_parameterss$     rpc Csi}|D]\}}|dd}|dd}|dd} |durn||dgD]} | d|vrP|| qP|dur| rtd||durq t|rt|ttfrtd |D]>} ||| <| |vr||vr|dur||| f|| ||<qq |S) aUProcess aliases from an argument_spec including warnings and deprecations. Modify ``parameters`` by adding a new key for each alias with the supplied value from ``parameters``. If a list is provided to the alias_warnings parameter, it will be filled with tuples (option, alias) in every case where both an option and its alias are specified. If a list is provided to alias_deprecations, it will be populated with dictionaries, each containing deprecation information for each alias found in argument_spec. :param argument_spec: Dictionary of parameters, their type, and valid values. :type argument_spec: dict :param parameters: Dictionary of parameters. :type parameters: dict :param alias_warnings: :type alias_warnings: list :param alias_deprecations: :type alias_deprecations: list rbNdefaultrequiredFZdeprecated_aliasesnamezBinternal error: required and default are mutually exclusive for %sz/internal error: aliases must be a list or tuple) itemsrUrg ValueErrorr isinstancer$r' TypeError) r`raalias_warningsalias_deprecationsZaliases_resultsrmvrbrqrraliasrZrZr[r^s,      r^c Csg}|D]\}}||vr |r.d||f}n|}|ddurd|d||d|ddn0|ddur|d||d|dd|d }|dur ||}t|tr|g}t|tr |D]"} t| tr|t|| |d qq |S) aReturn a list of deprecations :arg argument_spec: An argument spec dictionary :arg parameters: Dictionary of parameters :returns: List of dictionaries containing a message and version in which the deprecated parameter will be removed, or an empty list. :Example return: .. code-block:: python [ { 'msg': "Param 'deptest' is deprecated. See the module docs for more information", 'version': '2.9' } ] z%s["%s"]Zremoved_at_dateNzBParam '%s' is deprecated. See the module docs for more informationZremoved_from_collection)msgdatecollection_nameZremoved_in_version)r}rGroptions)prefix)rtrUrgrvr rIextend_list_deprecations) r`rarZ deprecationsarg_namearg_optsZ sub_prefixsub_argument_specZ sub_argumentsZ sub_paramsrZrZr[rs8     rc Cs0t}|D]\}}|ddr||d}|rz|t|Wn8ty~}z td|t|fWYd}~n d}~00|d}|dur|d}||} | dur|dks|dkr|d d dkrt| ts| g} | D]F} t| t rt | } t| t std || ||t || qq|S) zReturn set of no log values :arg argument_spec: An argument spec dictionary :arg params: Dictionary of all parameters :returns: :class:`set` of strings that should be hidden from output: r@FNzFailed to convert "%s": %srrWrJrIelementsr|zXValue '{1}' in the sub parameter field '{0}' must by a {2}, not '{1.__class__.__name__}')rdrtrUrh_return_datastructure_namerwr rvrIr&r3r format_list_no_log_values) r`params no_log_valuesrrZ no_log_objecter wanted_typesub_parametersZ sub_paramrZrZr[r5s4   *       rccst|ttfr$|r t|ddVdSt|trV|D]}t|dD] }|VqFq6nvt|r~|D]}t|D] }|VqnqbnN|dust|trdSt|t t t t grt|ddVnt dt|dS)zu Return native stringified values from datastructures. For use with removing sensitive values pre-jsonification.surrogate_or_stricterrorsNZ simplerepr)Z nonstringzUnknown parameter type: %s)rvr'r$r r rtrrrKrerIr%rMrwrW)objelementZ subelementrZrZr[res"     rcCst|ttfr|}t|tr2d}trPt|dd}nt|trPd}trPt|dd}||vr\dS|D]}||d}q`|rt|trt|ddd }n"|st|trt|ddd }n|}n z6 is of type %s and we were unable to convert to %s: %s)rr\rvr&rJrIr_rgrwrujoinrWr r) rZ parametervaluesrjrrYZwanted_element_typeZvalidated_parameterskwargsrrr}rZrZr[_validate_elements's(    &rc Cs|durt}|D]x\}}||vr*q||}|durz-_validate_argument_values..z, cSsg|] }t|qSrZr rcrZrZr[rrz.Z_ansibleNzIUnknown container type encountered when removing private values from keys) rrpopleftrvr rt startswithrr#rgr"rfrw) rrrrrold_datanew_dataold_keyold_elemZnew_keyelemnew_elemrZrZr[ sanitize_keysas&        rc Cst}dd|D}t|||}|r|\}}t|trb|D]\}}t|||}|||<qBq |D]D} t| ||}t|tr||qft|tr| |qft dqfq |S)avRemove strings in ``no_log_strings`` from value. If value is a container type, then remove a lot more. Use of ``deferred_removals`` exists, rather than a pure recursive solution, because of the potential to hit the maximum recursion depth when dealing with large amounts of data (see `issue #24560 `_). cSsg|]}t|ddqSrrrrZrZr[rrz!remove_values..zKUnknown container type encountered when removing private values from output) rrrrvr rtr#rgr"rfrw) rrrrrrrrrrrZrZr[ remove_valuess"            r)N)NNN)NN)r|)T)NN)r|NN)NN)r|NNNNNN)aZ __future__rrrrWZ __metaclass__rr collectionsr itertoolsrZ'ansible.module_utils.common.collectionsrZ+ansible.module_utils.common.text.convertersrr r Z+ansible.module_utils.common.text.formattersr Z$ansible.module_utils.common.warningsr Zansible.module_utils.errorsr rrrrrrrrrrrrrZ)ansible.module_utils.parsing.convert_boolrrZ/ansible.module_utils.common._collections_compatrrrr r!r"r#Zansible.module_utils.sixr$r%r&r'r(r)Z&ansible.module_utils.common.validationr*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:rrZ PASS_VARSZ PASS_BOOLSrTr\rcrpr^rrrrrrrrrrrrrrrrZrZrZr[s     @$ L        ) 9 60^ %&  F 5  ,