HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/self/root/usr/lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib/python3/dist-packages/cloudinit/config/__pycache__/schema.cpython-311.pyc
�

܍~c$�����dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZmZmZmZmZmZmZddlZdd	lmZmZdd
lmZddl m!Z!m"Z"m#Z#	ddl$m%Z&e&Z%n
#e'$re(Z%YnwxYwee!d
���Z!ej)e*��Z+dZ,dZ-dddd�Z.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7erddlZddl8m9Z9m:Z:Gd�d e:��Z;ne<Z;Gd!�d"e%��Z=Gd#�d$e��Z>ee>Z?dd%d&�d'e?d(ee@d)e@d*e@fd+�ZAGd,�d-eB��ZCd.�ZDdfd/ee@d*e@fd0�ZEe=fdeFd1e<d2ee(fd3�ZGe=fd2ee(fd4�ZHe=fd2ee(fd5�ZId6�ZJdgd1e<fd7�ZK					dhd9e<d1e<d:eFd;eFd<eFd=eFfd>�ZLGd?�d@��ZMdddA�dBe<dCeNdDe<dEee?dFee?d*ee@eNffdG�ZOdidH�ZPdI�ZQdJ�ZRdKe<dLe@d*ee@fdM�ZSdKe<dNe<d*e@fdO�ZTd*e@fdP�ZUdQe<dNe<fdR�ZVdQe<fdS�ZWdTe<d*e@fdU�ZXdjd1e<dNe<d*e@fdW�ZYdXe;d*e@fdY�ZZdXe;d*e@fdZ�Z[dfdXe;d1ee<d*e@fd[�Z\d*e<fd\�Z]d]e^d*e@fd^�Z_d*e@fd_�Z`d*e<fd`�Zad*e<fda�Zbdfdb�Zcdc�Zddd�Zee*dekrejfee����dSdS)kzFschema.py: Set of module functions for processing cloud-config schema.�N)�defaultdict)�Iterable)�deepcopy)�partial)�chain)�
TYPE_CHECKING�List�
NamedTuple�Optional�Type�Union�cast)�importer�safeyaml)�Init)�error�get_modules_from_dir�	load_file��ValidationErrorT)�sys_exitz!versions.schema.cloud-config.jsonzschema-cloud-config-v1.json�true�false�null)TFNs
#cloud-configz�
{name}
{title_underbar}
**Summary:** {title}

{description}

**Internal name:** ``{id}``

**Module frequency:** {frequency}

**Supported distros:** {distros}

{activate_by_schema_keys}{property_header}
{property_doc}

{examples}
z**Config schema**:z3{prefix}**{prop_name}:** ({prop_type}){description}zH{prefix}Each object in **{prop_name}** list supports the following keys:z**Examples**::

z
    # --- Example{0} ---�
deprecatedzDEPRECATED: )�NotRequired�	TypedDictc��eZdZUeed<eed<eed<eed<ejeed<ejeed<eed<eeeed<d	S)
�
MetaSchema�name�id�title�description�distros�examples�	frequency�activate_by_schema_keysN)�__name__�
__module__�__qualname__�str�__annotations__�typingr	r���9/usr/lib/python3/dist-packages/cloudinit/config/schema.pyrrMs}��������	�	�	������
�
�
�������S�!�!�!�!��+�c�"�"�"�"�����!,�T�#�Y�!7�7�7�7�7�7r/rc��eZdZdS)�SchemaDeprecationErrorN)r(r)r*r.r/r0r2r2[s�������Dr/r2c�0�eZdZUeed<eed<defd�ZdS)�
SchemaProblem�path�message�returnc�$�|j�d|j��S)N�: )r5r6��selfs r0�formatzSchemaProblem.formatcs���)�-�-�t�|�-�-�-r/N)r(r)r*r+r,r<r.r/r0r4r4_sC�������

�I�I�I�
�L�L�L�.��.�.�.�.�.�.r/r4�, ��prefix�	separator�schema_problemsr?r@r7c�^�|�td�|����}|r|�|��}|S)Nc�*�|���S�N)r<)�ps r0�<lambda>z)_format_schema_problems.<locals>.<lambda>ps��Q�X�X�Z�Z�r/)�join�map)rAr?r@�	formatteds    r0�_format_schema_problemsrJjsA�����s�#7�#7��I�I�J�J�I�
�+��*�y�*�*�	��r/c�V��eZdZdZ		ddeedeef�fd�
Zdefd�Z�xZ	S)	�SchemaValidationErrorz<Raised when validating a cloud-config file against a schema.N�
schema_errors�schema_deprecationsc����d}|r|t|d���z
}|r|r|dz
}|t|d���z
}t���|��||_||_dS)z�Init the exception an n-tuple of schema errors.

        @param schema_errors: An n-tuple of the format:
            ((flat.config.key, msg),)
        @param schema_deprecations: An n-tuple of the format:
            ((flat.config.key, msg),)
        �zCloud config schema errors: )r?�

�"Cloud config schema deprecations: N)rJ�super�__init__rMrN)r;rMrNr6�	__class__s    �r0rTzSchemaValidationError.__init__ys�������	��.��&D����
�G��	��
"��6�!���.�#�;����
�G�	������!�!�!�*���#6�� � � r/r7c�*�t|j��SrD)�boolrMr:s r0�
has_errorsz SchemaValidationError.has_errors�s���D�&�'�'�'r/)NN)
r(r)r*�__doc__r�SchemaProblemsrTrWrX�
__classcell__)rUs@r0rLrLvs��������F�F�37�8<�7�7���/�7�&�n�5�7�7�7�7�7�7�8(�D�(�(�(�(�(�(�(�(r/rLc��	ddlm}n#t$rYdSwxYw|j�|d��pt|tf��S)zWTYPE_CHECKER override allowing bytes for string type

    For jsonschema v. 3.0.0+
    r)�Draft4ValidatorF�string)�
jsonschemar]�ImportError�TYPE_CHECKER�is_type�
isinstance�bytes)�checker�instancer]s   r0�is_schema_byte_stringrg�sr��
�.�.�.�.�.�.�.�������u�u������'�/�/��(���(�	�H�u�h�	'�	'�(s�	�
�r#c�v�|rt�|��St�dd�����S)N�:�.)�DEPRECATED_PREFIX�replace�strip)r#s r0�_add_deprecation_msgrn�s=���3�#�2�[�2�2�2��$�$�S�#�.�.�4�4�6�6�6r/�schema�
error_typec#�tK�|r3|�d��}t|��}||��V�dSdS)z�Jsonschema validator for `deprecated` items.

    It raises a instance of `error_type` if deprecated that must be handled,
    otherwise the instance is consider faulty.
    r#N)�getrn)�
_validatorr�	_instancerorpr#�msgs       r0�_validator_deprecatedrv�sR�������j�j��/�/��"�;�/�/���j��o�o�������r/c#��K�ddlm}g}g}t|��D]�\}}	t|�||	|�����}
tt�fd�|
����}tt�fd�|
����}|s|�|��n(|�|����||�d�|���V�|Ed{V��dS)	z�Jsonschema validator for `anyOf`.

    It treats occurrences of `error_type` as non-errors, but yield them for
    external processing. Useful to process schema annotations, as `deprecated`.
    rr��schema_pathc�&��t|���SrD�rc��erps �r0rFz_anyOf.<locals>.<lambda>������A�z�)B�)B�%B�r/c�$��t|���SrDr{r|s �r0rFz_anyOf.<locals>.<lambda>�����Z��:�6�6�r/�, is not valid under any of the given schemas��contextN)r_r�	enumerate�list�descend�filter�extend)
�	validator�anyOfrf�_schemarpr�
all_errors�all_deprecations�index�	subschema�all_errs�errs�deprecationss
    `        r0�_anyOfr��s<�����+�*�*�*�*�*��J���%�e�,�,�
�
���y�����h�	�u��E�E�
�
���F�B�B�B�B�H�M�M�N�N����6�6�6�6��A�A�
�
���	��#�#�L�1�1�1��E����$������o�@H���J��
�
�
�	
�	
�	
� ���������r/c#�b���K�ddlm}t|��}g}g}|D]�\}	}
t���|
|	�����}tt�fd�|����}tt�fd�|����}
|s|
}|�|
��n(|�|����|��d�|���V���fd�|D��}|rH|�|��d	�d
�|D����}|��d|����V�dS|Ed{V��dS)
z�Jsonschema validator for `oneOf`.

    It treats occurrences of `error_type` as non-errors, but yield them for
    external processing. Useful to process schema annotations, as `deprecated`.
    rrrxc�&��t|���SrDr{r|s �r0rFz_oneOf.<locals>.<lambda>�r~r/c�$��t|���SrDr{r|s �r0rFz_oneOf.<locals>.<lambda>�r�r/r�r�c�F��g|]\}}���|���|��Sr.)�is_valid)�.0�i�srfr�s   ��r0�
<listcomp>z_oneOf.<locals>.<listcomp>s2���N�N�N���1�i�.@�.@��1�.M�.M�N�!�N�N�Nr/r=c3�4K�|]}t|��V��dSrD)�repr)r�ros  r0�	<genexpr>z_oneOf.<locals>.<genexpr>
s(����@�@�6�$�v�,�,�@�@�@�@�@�@r/z is valid under each of N)	r_rr�r�r�r�r��appendrG)r��oneOfrfr�rpr�
subschemasr�r�r�r�r�r�r��first_valid�
more_valid�reprss` ` `            r0�_oneOfr��s��������+�*�*�*�*�*��5�!�!�J��J���&�
�
���y�����h�	�u��E�E�
�
���F�B�B�B�B�H�M�M�N�N����6�6�6�6��A�A�
�
���	�#�K��#�#�L�1�1�1��E����$������o�@H���J��
�
�
�	
�	
�	
�
O�N�N�N�N�
�N�N�N�J��$����+�&�&�&��	�	�@�@�Z�@�@�@�@�@���o�.6�h�h���>�
�
�	
�	
�	
�	
�	
�$�#�#�#�#�#�#�#�#�#r/c��ddlm}m}ddlm}t|j��}d|d<ddi|dd	<i}t|d
��r%|j�	dt��}d|i}n|j}ttf|d<d|i}t|j��}t |t"<t$|d
<t&|d<|d||dd�|��}dd�}	|	|_||fS)z�Get metaschema validator and format checker

    Older versions of jsonschema require some compatibility changes.

    @returns: Tuple: (jsonschema.Validator, FormatChecker)
    @raises: ImportError when jsonschema is not present
    r)r]�
FormatChecker)�createF�additionalProperties�typer^�
properties�labelra�type_checker�
default_typesr�r��draft4)�meta_schema�
validators�versionNc�p�td�|�||����}t|d��duS)zgOverride version of `is_valid`.

        It does ignore instances of `SchemaDeprecationError`.
        c�.�t|t��SrD)rcr2�r}s r0rFz<get_jsonschema_validator.<locals>.is_valid.<locals>.<lambda>Ps��*��)����r/N)r��iter_errors�next)r;rfr��__�errorss     r0r�z*get_jsonschema_validator.<locals>.is_validJsI��
�
�
�
���X�w�/�/�	
�
���F�D�!�!�T�)�)r/r.rD)r_r]r��jsonschema.validatorsr�r�META_SCHEMA�hasattrra�redefinerg�
DEFAULT_TYPESr+rd�dict�
VALIDATORSrv�DEPRECATED_KEYr�r�r�)
r]r�r��strict_metaschema�validator_kwargsr��typesr��cloudinitValidatorr�s
          r0�get_jsonschema_validatorr�sY��:�9�9�9�9�9�9�9�,�,�,�,�,�,�!��!<�=�=��05��,�-�17��/A��l�#�G�,������/�/�
4�&�3�<�<��+�
�
��
�L�
��� �-����,��h��+�U�3���o�0�1�1�J�!6�J�~�� �J�w�� �J�w�����%������	���*�*�*�*�#+����
�.�.r/c	�,�ddlm}	|�|��dS#|$ro}|rGtt	d�d�|jD����|j��g���|�t�	d|��Yd}~dSd}~wwxYw)a Validate provided schema meets the metaschema definition. Return strict
    Validator and FormatChecker for use in validation
    @param validator: Draft4Validator instance used to validate the schema
    @param schema: schema to validate
    @param throw: Sometimes the validator and checker are required, even if
        the schema is invalid. Toggle for whether to raise
        SchemaValidationError or log warnings.

    @raises: ImportError when jsonschema is not present
    @raises: SchemaValidationError when the schema is invalid
    r)�SchemaErrorrjc�,�g|]}t|����Sr.�r+�r�rEs  r0r�z3validate_cloudconfig_metaschema.<locals>.<listcomp>ts��!;�!;�!;�Q�#�a�&�&�!;�!;�!;r/�rMzGMeta-schema validation failed, attempting to validate config anyway: %sN)
�jsonschema.exceptionsr��check_schemarLr4rGr5r6�LOG�warning)r�ro�throwr��errs     r0�validate_cloudconfig_metaschemar�\s���2�1�1�1�1�1�
����v�&�&�&�&�&���
�
�
��	�'�!����!;�!;�#�(�!;�!;�!;�<�<�c�k��������

�	���
��	
�	
�	
�	
�	
�	
�	
�	
�	
�����
���s��B�A$B�BF�config�strictr��log_details�log_deprecationsc��|�t��}	t��\}}|rt||d���n+#t$rt�d��YdSwxYw|||�����}g}	g}
t
|�|��d����D]\}d�d	�|j	D����}t||j��f}
t|t��r|
|
z
}
�W|	|
z
}	�]|r.|
r,t|
d
d���}t�|��|r|	s|
rt!|	|
���|	r3|rt|	d
d���}nd}t�|��dSdS)aValidate provided config meets the schema definition.

    @param config: Dict of cloud configuration settings validated against
        schema. Ignored if strict_metaschema=True
    @param schema: jsonschema dict describing the supported schema definition
       for the cloud config module (config.cc_*). If None, validate against
       global schema.
    @param strict: Boolean, when True raise SchemaValidationErrors instead of
       logging warnings.
    @param strict_metaschema: Boolean, when True validates schema using strict
       metaschema definition at runtime (currently unused)
    @param log_details: Boolean, when True logs details of validation errors.
       If there are concerns about logging sensitive userdata, this should
       be set to False.
    @param log_deprecations: Controls whether to log deprecations or not.

    @raises: SchemaValidationError when provided config does not validate
        against the provided schema.
    @raises: RuntimeError when provided config sourced from YAML is not a dict.
    NF)r�z5Ignoring schema validation. jsonschema is not present)�format_checkerc��|jSrD)r5r�s r0rFz-validate_cloudconfig_schema.<locals>.<lambda>�s��Q�V�r/��keyrjc�,�g|]}t|����Sr.r�r�s  r0r�z/validate_cloudconfig_schema.<locals>.<listcomp>�s��4�4�4�A��Q���4�4�4r/z"Deprecated cloud-config provided:
�
r>zInvalid cloud-config provided:
zeInvalid cloud-config provided: Please run 'sudo cloud-init schema --system' to see the schema errors.)�
get_schemar�r�r`r��debug�sortedr�rGr5r4r6rcr2rJr�rL)r�ror�r�r�r�r�r�r�r�r�rr5�problemr6�detailss                r0�validate_cloudconfig_schemar�s���8�~������.F�.H�.H�+�	�]��	�+�"�F�%�
�
�
�
��������	�	�I�J�J�J��������#�"�6�-�-�/�/�J�J�J�I��F�#%�L��	�-�-�f�5�5�;K�;K�L�L�L�����x�x�4�4���4�4�4�5�5�� ��u�}�5�5�7���e�3�4�4�	��G�#�L�L��g��F�F���L��)��8��
�
�
��
	���G����
�:�6�:�\�:�#�F�L�9�9�9�
�
��	�-��9�����G�G�)�
�
	���G������
�
s�%8�$A �A c�
�eZdZdededefd�Zededeedefd���Z	d	e
fd
�Ze	ddeed
eedeedededefd���Z
deedededeefd�Zde
de
deeeffd�ZdS)�
_Annotator�cloudconfig�original_content�schemamarksc�0�||_||_||_dSrD)�_cloudconfig�_original_content�_schemamarks)r;r�r�r�s    r0rTz_Annotator.__init__�s"��(���!1���'����r/r"�contentr7c�>�d�|��}d|�d|�d�S)Nr��# z: -------------
rQ)rG)r"r��bodys   r0�
_build_footerz_Annotator._build_footer�s,���y�y��!�!��6�E�6�6�D�6�6�6�6r/rAc�p�tt��}|D]�\}}tjd|��}|r@|���\}}|t|���|��n(d}||j|�|��|�d�|||���}��|S)Nz&format-l(?P<line>\d+)\.c(?P<col>\d+).*zLine {line} column {col}: {msg})�line�colru)	rr��re�match�groups�intr�r�r<)r;rA�errors_by_liner5rur�r�r�s        r0�_build_errors_by_linez _Annotator._build_errors_by_line�s���$�T�*�*��*�	�	�K�T�3��H�F��M�M�E��
D�!�L�L�N�N�	��c��s�4�y�y�)�0�0��5�5�5�5����t�0��6�7�>�>�s�C�C�C���7�>�>��3�C�?������r/rP�problems�labels�footerr��label_prefixc��|D]=}|�|��}|�|��|�d|�d|����|dz
}�>|S)Nr�r9�)r�)r�r�r�r�rr�r�s       r0�
_add_problemsz_Annotator._add_problems�sh�� �	�	�G�#�,�U�,�,�E��M�M�%� � � ��M�M�1�u�1�1��1�1�2�2�2��Q�J�E�E��r/�linesr��deprecations_by_linec����g}g}g}d}d}t|d��D]�\}	}
||	}||	}|s|reg}
��||
||d���}��||
||d���}|�|
dzd�|
��z���~|�|
����|�t�fd�t
d�d	|fd
|ff������|S)Nr�E)r�Dz		# �,c����j|�SrD)r�)�seqr;s �r0rFz._Annotator._annotate_content.<locals>.<lambda>s���.�D�.��4�r/c�,�t|d��S)Nr)rW)rs r0rFz._Annotator._annotate_content.<locals>.<lambda>s���S��V���r/�Errors�Deprecations)r�rr�rGr�rHr�)r;rr�r�annotated_content�error_footer�deprecation_footer�error_index�deprecation_index�line_numberr�r�r�r�s`             r0�_annotate_contentz_Annotator._annotate_content�s_�����"$��(*������!*�5�!�!4�!4�	/�	/��K��#�K�0�F�/��<�L��
/��
/�$&��"�0�0��F�L�+�C�1����%)�$6�$6� ��&�%�!$�%7�%�%�!�"�(�(����3�8�8�F�;K�;K�)K�L�L�L�L�!�(�(��.�.�.�.�� � ��4�4�4�4��,�,�!�<�0�'�);�<����	
�	
�	
�	
�	
�!� r/rMrNc��|s	|s|jS|j����d��}t|jt
��s.d�||�ddg��gz��S|�|��}|�|��}|�	|||��}d�|��S)Nr�r
z&# E1: Cloud-config is not a YAML dict.)
r��decode�splitrcr�r�rGr�r�r)r;rMrNrr�rrs       r0�annotatez_Annotator.annotate's���
�	*�%8�	*��)�)��&�-�-�/�/�5�5�d�;�;���$�+�T�2�2�		��9�9���&�&� �#K�"L�������
��3�3�M�B�B��#�9�9�:M�N�N�� �2�2��>�#7�
�
���y�y�*�+�+�+r/N)rP)r(r)r*r�rdrT�staticmethodr+r	r�rZr�r�rrr
rr.r/r0r�r��s�������(��(� �(��	(�(�(�(��7�S�7�4��9�7��7�7�7��\�7��^����� �����s�)���S�	���S�	���	�
��

�
����\��*!��C�y�*!��*!�#�	*!�

�c��*!�*!�*!�*!�X,�%�,�,�,�
�s�E�z�	�	,�,�,�,�,�,r/r��rMrNr�r�r�rMrNc�T�t|||���|pg|pg��S)a�Return contents of the cloud-config file annotated with schema errors.

    @param cloudconfig: YAML-loaded dict from the original_content or empty
        dict if unparseable.
    @param original_content: The contents of a cloud-config file
    @param schemamarks: Dict with schema marks.
    @param schema_errors: Instance of `SchemaProblems`.
    @param schema_deprecations: Instance of `SchemaProblems`.

    @return Annotated schema
    )r�r)r�r�r�rMrNs     r0�annotated_cloudconfig_filerAs9��&�k�#3�[�A�A�J�J����0�6�B���r/c
���|��tj��dkrtd���tg���}|�d���|���t
|j�d��d�	��}nRtj	�
|��s"td
�|�����t
|d�	��}|�t��sttdd�|t�������g}t!|��}|r%t#t%i|i|j�
����|�	|rt)j|��\}}nt)j|��}i}�n#t.j$�r}	dx}
}d}t3|	d��r!t5|	d��rt5|	d��}n0t3|	d��r t5|	d��rt5|	d��}|r|jdz}
|jdz}td�|
|���d�|t;|	������g}t!|��}|r%t#t%i|i|j�
����||	�d}	~	wwxYwt=|t>��s|std���	tA||dd���dS#t $rt}	|r,t#t%||||	j|	j!�����n&tE|	j!dd���}
t#|
��|	�#��r�Yd}	~	dSd}	~	wwxYw)aValidate cloudconfig file adheres to a specific jsonschema.

    @param config_path: Path to the yaml cloud-config file to parse, or None
        to default to system userdata from Paths object.
    @param schema: Dict describing a valid jsonschema to validate against.
    @param annotate: Boolean set True to print original config file with error
        annotations on the offending lines.

    @raises SchemaValidationError containing any of schema_errors encountered.
    @raises RuntimeError when config_path does not exist.
    Nrz?Unable to read system userdata as non-root user. Try using sudo)�ds_deps�trust)�existing�cloud_configF)rzConfigfile {0} does not existzformat-l1.c1z"File {0} needs to begin with "{1}"r�r�context_mark�problem_markzformat-l{line}.c{col})r�r�zFile {0} is not valid yaml. {1}z Cloud-config is not a YAML dict.T)r�r�rrRr=r>)$�os�getuid�RuntimeErrorr�fetch�consume_datar�paths�	get_ipathr5�existsr<�
startswith�CLOUD_CONFIG_HEADERr4rrL�printrrMr�load_with_marks�load�yaml�	YAMLErrorr��getattrr��columnr+rcr�r�rNrJrX)�config_pathror�initr�r�rr��marksr}r�r5�markr6s              r0�validate_cloudconfig_filer:Ys����
�9�;�;�!����"���
��B������
�
�G�
�$�$�$��������D�J�0�0��@�@��O�O�O����w�~�~�k�*�*�	��/�6�6�{�C�C���
��K��6�6�6�����1�2�2����4�;�;��!4�!;�!;�!=�!=���
�
�
��&�f�-�-���	��*����5�3F����
�
�
�
����	�!)�!9�'�!B�!B��K���"�-��0�0�K��E����N�������v����1�n�%�%�	.�'�!�^�*D�*D�	.��1�n�-�-�D�D�
�Q��
'�
'�	.�G�A�~�,F�,F�	.��1�n�-�-�D��	%��9�q�=�D��[�1�_�F��'�.�.�D�f�.�E�E�1�8�8��c�!�f�f�M�M�
�
�
��&�f�-�-���	��*����5�3F����
�
�
�
�������/����0�k�4�(�(�C��	C��A�B�B�B��#����u�	
�	
�	
�	
�	
�	
��!�����	��*����"#�/�()�(=����
�
�
�
�.��%�;�����G�

�'�N�N�N��<�<�>�>�	��	�	�	�	�	�	�����%���s2�.0F � J2�0C=J-�-J2�K1�1
M/�;A)M*�*M/c�&�|dkrdS|dkrdSdS)z�Provide a sorting weight for documentation of property types.

    Weight values ensure 'array' sorted after 'object' which is sorted
    after anything else which remains unsorted.
    �array��objectrrr.)�values r0�_sort_property_orderr@�s)��
�����q�	�(�	�	��q��1r/c#�K�|D]M}t|t��r2t|ttf��st	|��Ed{V���I|V��NdSrD)rcrr+rd�_flatten)�xs�xs  r0rBrB�sr����
�����a��"�"�	�:�a�#�u��+F�+F�	���{�{�"�"�"�"�"�"�"�"��G�G�G�G�	�r/�
property_dict�	multi_keyc��g}|�|i��D]�}|�t��r�|�d��r4|�d�|�dg��D�����f|�d��r|�|d����t	t|����S)N�enumc�L�g|]!}dt�||���d���"S��``��	_YAML_MAPrr)r��
enum_values  r0r�z,_collect_subschema_types.<locals>.<listcomp>�sB�����"�C����z�:�>�>�B�B�B���r/r�)rrr�r�r�r�rB)rErF�property_typesr�s    r0�_collect_subschema_typesrP�s����N�"�&�&�y�"�5�5�5�5�	��=�=��(�(�	���=�=�� � �	5��!�!���&/�m�m�F�B�&?�&?����
�
�
�
��]�]�6�
"�
"�	5��!�!�)�F�"3�4�4�4�����(�(�)�)�)r/�defsc��t||��|�dg��}t|t��s|g}|�d��rd�|dD��}nq|�d��r$|�t|d����n8|�d��r#|�t|d����t
|��dkr	|d}n0|�t���d	�	|��}|�d
i��}|�dg��}t|t��s|g}t|��}t|�di��|�di����D]0}t||��}|r|dkr�|�
|���1|r[t
|��dkr
|�d|d��S|�t���d
d	�	|���d�}	|�d|	��S|pdS)zNReturn a string representing a property type from a given
    jsonschema.
    r�rHc�L�g|]!}dt�||���d���"SrJrL�r��ks  r0r�z&_get_property_type.<locals>.<listcomp>�s?��
�
�
�-.�(����q�!�$�$�(�(�(�
�
�
r/r�r�rrr��/�items�	UNDEFINEDz of �(�))�_flatten_schema_refsrrrcr�r�rP�len�sortr@rGrWr�_get_property_typer�)
rErQrO�
property_typerW�sub_property_types�prune_undefined�sub_item�sub_type�sub_property_docs
          r0r^r^�s������-�-�-�"�&�&�v�r�2�2�N��n�d�+�+�*�(�)������ � �P�
�
�2?��2G�
�
�
���
�	�	�7�	#�	#�P����6�}�g�N�N�O�O�O�O�	�	�	�7�	#�	#�P����6�}�g�N�N�O�O�O�
�>���a���&�q�)�
�
���� 4��5�5�5�����0�0�
����g�r�*�*�E����6�2�.�.���(�$�/�/�2�0�1���-�.�.�O��%�)�)�G�R�0�0�%�)�)�G�R�2H�2H�I�I�,�,��%�h��5�5���	�x�;�6�6�
��!�!�(�+�+�+�+��8��!�"�"�a�'�'�#�@�@�);�A�)>�@�@�@����$8��9�9�9�>�s�x�x�(:�;�;�>�>�>���7�7�%5�7�7�7��'�K�'r/c���|dz}tjdd|��}tjdd�|��|��}tjdd�|��|��}|S)a�Parse description from the meta in a format that we can better
    display in our docs. This parser does three things:

    - Guarantee that a paragraph will be in a single line
    - Guarantee that each new paragraph will be aligned with
      the first paragraph
    - Proper align lists of items

    @param description: The original description in the meta.
    @param prefix: The number of spaces used to align the current description
    �z
(\S)\n(\S)z\1 \2z\n\nz\n\n{}z\n( +)-z\n{}-)r��subr<)r#r?�list_paragraphs   r0�_parse_descriptionrism���a�Z�N��&���+�>�>�K��&��)�"2�"2�6�":�":�K�H�H�K��&��H�O�O�N�3�3�[���K��r/�src_cfgc�H�d|vrD|�d���dd��}|�||��d|vr�d|dvrP|d�d���dd��}|d�||��d|dvrY|ddD]J}d|vrD|�d���dd��}|�||���Kt|�dg��|�dg��|�dg����D]J}d|vrD|�d���dd��}|�||���KdS)	zEFlatten schema: replace $refs in src_cfg with definitions from $defs.z$refz#/$defs/rPrWr�r��allOfN)�poprl�updaterrr)rjrQ�	reference�
sub_schemas    r0r[r[+s���
�����K�K��'�'�/�/�
�B�?�?�	����t�I��'�'�'��'����W�W�%�%�%���(�,�,�V�4�4�<�<�Z��L�L�I��G��#�#�D��O�4�4�4��g�g�&�&�&�%�g�.�w�7�
7�
7�
��Z�'�'� *���v� 6� 6� >� >�z�2� N� N�I��%�%�d�9�o�6�6�6������G�R� � ����G�R� � ����G�R� � ���/�/�
�
�Z���"���v�.�.�6�6�z�2�F�F�I����d�9�o�.�.�.��/�/r/c�n�|�dd��}|sdS|D]}|�|���dS)z�Flatten schema: Merge allOf.

    If a schema as allOf, then all of the sub-schemas must hold. Therefore
    it is safe to merge them.
    rlN)rmrn)rj�sub_schemasrps   r0�_flatten_schema_all_ofrsEsR���+�+�g�t�,�,�K�����!�#�#�
����z�"�"�"�"�#�#r/�prop_configc�,�|�dd��}|�di��}|�di��}g}g}|rg|�d��}|�t��s|�|��n"|�t	|����t||��D]�}|�d��s�|�t��s/|�|d�d�����a|�t�|d�d��������d�t||����}|rd|��}|dd	kr|dz
}|S)
aGReturn accumulated property description.

    Account for the following keys:
    - top-level description key
    - any description key present in each subitem under anyOf or allOf

    Order and deprecated property description after active descriptions.
    Add a trailing stop "." to any description not ending with ":".
    r#rPr�r�rjz. � ���ri)rr�rstripr�r�rnrrkrG)rt�
prop_descrr�r��descriptions�deprecated_descriptionsrbr#s        r0�_get_property_descriptionr|Rs��������3�3�J��O�O�G�R�(�(�E��O�O�G�R�(�(�E��L� ���M��&�&�s�+�+�
����~�.�.�	M����
�+�+�+�+�#�*�*�+?�
�+K�+K�L�L�L��%��'�'�����|�|�M�*�*�	���|�|�N�+�+�	������ 7� >� >�s� C� C�D�D�D�D�#�*�*�$�K�h�}�&=�&D�&D�S�&I�&I�K�K�
�
�
�
��)�)�E�,�0G�H�H�I�I�K���'�+�'�'���r�?�c�!�!��3��K��r/�    c
�&��|dz}g}��d��durdS�fd�dD��}�fd�|D��}|D�]<}|���D�]#\}}	t|	|��t|	��|	�d��dur�=t	|	��}
|	�d|��}|�t�||t|
|��t|	|���	����|	�d
��}|�r/t||��|�d��s|�d��rY|�t�||�
����|dz
}|�t|||�����|�dg��D]�}
|
�d��s|
�d��rY|�t�||�
����|dz
}|�t|
||�������d|	vsd|	vr%|�t|	||�������%��>d�|��S)zDReturn restructured text describing the supported schema properties.r}�hiddenTrPc�0��g|]}d�vs
|�dv�|��S)rr.�r�r�ros  �r0r�z%_get_property_doc.<locals>.<listcomp>s=��������6�!�!�S��x�0@�%@�%@�	�%@�%@�%@r/)r��patternPropertiesc�<��g|]}��|i����Sr.)rrr�s  �r0r�z%_get_property_doc.<locals>.<listcomp>�s'���E�E�E���
�
�3��+�+�E�E�Er/r�)r?�	prop_namer#�	prop_typerWr�r�)r?r�)rQr?r�rQ)
rrrWr[rsr|r��SCHEMA_PROPERTY_TMPLr<rir^�SCHEMA_LIST_ITEM_TMPL�_get_property_docrG)rorQr?�
new_prefixr��
property_keys�property_schemas�prop_schema�prop_keyrtr#r�rW�
alt_schemas`             r0r�r�ys.����&��J��J�
�z�z�(���t�#�#��r�����6����M�
F�E�E�E�}�E�E�E��'�7�7��%0�%6�%6�%8�%8�6	�6	�!�H�k� ��d�3�3�3�"�;�/�/�/����x�(�(�D�0�0��3�K�@�@�K� �O�O�G�X�6�6�E����$�+�+�!�#� 2�;�� G� G�0��d�C�C�	,���
�
�
� �O�O�G�,�,�E��
�$�U�D�1�1�1��9�9�\�*�*�	�e�i�i�8K�.L�.L�	��%�%�-�4�4�#-��5������
�&�(�J��%�%�)�%�d�:�N�N�N����#(�)�)�G�R�"8�"8���J�!�~�~�l�3�3�
�z�~�~�+�8�8�
�#�)�)�1�8�8�'1�U�9������
#�f�,�
�"�)�)�-� *��j����������+�+�&�+�5�5��!�!�%�#�$�z��������e6	�n�;�;�z�"�"�"r/�metac�h�|�d��}|sdSt}t|��D]�\}}tj|d���d��}|tkr1|�dt�|dz����|d�	|��z
}��|S)zAReturn restructured text describing the meta examples if present.r%rPr}r�rr)
rr�SCHEMA_EXAMPLES_HEADERr��textwrap�indentr�insert�SCHEMA_EXAMPLES_SPACER_TEMPLATEr<rG)r�r%�rst_content�count�example�indented_liness      r0�
_get_examplesr��s����x�x�
�#�#�H����r�(�K�#�H�-�-�1�1���w�!���&�9�9�?�?��E�E���0�0�0��!�!��2�9�9�%�!�)�D�D�
�
�
�	�t�y�y��0�0�0����r/c��|�d��sdSd�d�|dD����}d|�d�S)Nr'rPr=c3�"K�|]
}d|�d�V��dS)rKNr.rTs  r0r�z3_get_activate_by_schema_keys_doc.<locals>.<genexpr>�s;�������
�Q�
�
�
������r/z**Activate only on keys:** rQ)rrrG)r��schema_keyss  r0� _get_activate_by_schema_keys_docr��sd���8�8�-�.�.���r��)�)��� �!:�;������K�;��:�:�:�:r/c���|�t��}|r|std���t|�����}hd�}dh}d}||z
rd�||z
��}n ||z
|z
rd�||z
��}|rt|���t
t|����}d|d<|�d	i��}|�|d
��r1|�|d
i��}tt|��}	t||���|d<n/#t$r"t�
d
��d|d<YnwxYw|dr
t|d<t|��|d<d�|d��|d<t#jdd|d��|d<t'|��|d<t)jdi|��}|S)z�Return reStructured text rendering the provided metadata.

    @param meta: Dict of metadata to render.
    @param schema: Optional module schema, if absent, read global schema.
    @raise KeyError: If metadata lacks an expected key.
    Nz"Expected non-empty meta and schema>r!r r"r$r%r&r#r'rPz(Missing required keys in module meta: {}z3Additional unexpected keys found in module meta: {}�property_header�$defsr!)rQ�property_docz3Unable to render property_doc due to invalid schemar%r=r$rj�-r �title_underbarr.)r��
ValueError�set�keysr<�KeyErrorr�rrrrr��AttributeErrorr�r��SCHEMA_PROPERTY_HEADERr�rGr�rgr��SCHEMA_DOC_TMPL)	r�ror��
required_keys�
optional_keys�
error_message�	meta_copyrQ�templates	         r0�get_meta_docr��sC���~������?�v�?��=�>�>�>��t�y�y�{�{���D����M�/�/�M��M��t��	
�B�I�I��D� �
�
�
�
�
�
�	�
�	-�
�A�H�H��}�$�
�
�	�
�&��}�%�%�%��X�d�^�^�$�$�I�#%�I�� ��:�:�g�r�"�"�D��x�x��T�
���$����$�t�*�b�)�)���d�F�#�#��'�$5�f�4�$H�$H�$H�	�.�!�!���'�'�'����I�J�J�J�$&�	�.�!�!�!�'������ �>�'=�	�#�$�)�$�/�/�I�j���9�9�T�)�_�5�5�I�i��"$�&��s�D��L�"A�"A�I���+K��,�,�I�'�(��%�2�2�	�2�2�H��Os�!D6�6)E"�!E"c��tj�tj�t����}t|��SrD)r%r5�dirname�abspath�__file__r)�configs_dirs r0�get_modulesr�s1���'�/�/�"�'�/�/�(�";�";�<�<�K���,�,�,r/�requested_modulesc���d}tt�������dgz}t|���t|����}|rCtd�t|��d�|������|D]M}d|vs||vrCtj	|dgdg��\}}|r&tj
|d��}||jpdz
}�N|S)zaLoad module docstrings

    Docstrings are generated on module load. Reduce, reuse, recycle.
    rP�allz+Invalid --docs value {}. Must be one of: {}r=�cloudinit.configr�r)r�r��valuesr��
differencerr<rGr�find_module�
import_modulerY)r��docs�all_modules�invalid_docs�mod_name�mod_locs�_�mods        r0�load_docr�s��
�D��{�}�}�+�+�-�-�.�.�%��8�K��(�)�)�4�4�S��5E�5E�F�F�L��
�
�9�@�@��\�"�"��	�	�+�&�&�
�
�	
�	
�	
� �*�*���%�%�%��5F�)F�)F�$�0��-�.�����M�X�q��
*��,�X�a�[�9�9�����)�r�)����Kr/c��tj�tj�tj�t
����d��S)N�schemas)r%r5rGr�r�r�r.r/r0�get_schema_dirr�7s4��
�7�<�<����������(A�(A�B�B�I�N�N�Nr/c�^�tj�t��t��}d}	tjt|����}n3#t$r&}t�
d||��Yd}~nd}~wwxYw|s!t�
d|��idgd�}|S)z?Return jsonschema coalesced from all cc_* cloud-config modules.Nz$Cannot parse JSON schema file %s. %szCNo base JSON schema files found at %s. Setting default empty schemaz'http://json-schema.org/draft-04/schema#)r�z$schemarl)r%r5rGr��USERDATA_SCHEMA_FILE�json�loadsr�	Exceptionr�r�)�schema_file�full_schemar}s   r0r�r�;s����'�,�,�~�/�/�1E�F�F�K��K�L��j��;�!7�!7�8�8�����L�L�L����:�K��K�K�K�K�K�K�K�K�����L�����

����
,��	
�	
�	
��@��
�
��
�s�!A�
B�!B�Bc��t��}t�����D]Q\}}tj|dgdg��\}}|r/tj|d��}|j||jd<�R|S)z<Return metadata coalesced from all cc_* cloud-config module.r�r�rr!)r�r�rWrr�r�r�)�	full_metar�r�r�r�s     r0�get_metar�Zs������I�$���,�,�.�.�1�1�
��H��*��)�*�V�H�
�
���!��	1��(��!��5�5�C�(+��I�c�h�t�n�%���r/c��|stjdd���}|�ddd���|�dd	d
d���|�d
ddd���|�dd	d
d���|S)z0Return a parser for supported cmdline arguments.�cloudconfig-schemaz.Validate cloud-config files or document schema)�progr#z-cz
--config-filez.Path of the cloud-config yaml file to validate)�helpz--system�
store_trueFz)Validate the system cloud-config userdata)�action�defaultr�z-dz--docs�+zCPrint schema module docs. Choices: all or space-delimited cc_names.)�nargsr�z
--annotatez/Annotate existing cloud-config file with errors)�argparse�ArgumentParser�add_argument��parsers r0�
get_parserr�gs����
��(�%�H�
�
�
�������
=�����
������
8�	����������
)�����������
>�	�����Mr/c��|j|j|jg}td�|D����dkrt	d��|jr|jrt	d��t
��}|js|jr�	t|j||j��|j�d}n|j}td|��dS#t$r4}|js"t	t|����Yd}~dSYd}~dSd}~wt$r'}t	t|����Yd}~dSd}~wwxYw|jr#tt|j����dSdS)z@Handle provided schema args and perform the appropriate actions.c��g|]}|�|��Sr.r.)r��args  r0r�z&handle_schema_args.<locals>.<listcomp>�s��1�1�1�C�S�1�C�1�1�1r/rz;Expected one of --config-file, --system or --docs argumentsz;Invalid flag combination. Cannot use --annotate with --docsNzsystem userdatazValid cloud-config:)
�config_filer��systemr\rrr�r:r/rLr+r'r�)r �args�exclusive_argsr��cfg_namer}s      r0�handle_schema_argsr��s����&��	�4�;�?�N�
�1�1�>�1�1�1�2�2�a�7�7�
�K�L�L�L��}�M���M�
�K�L�L�L��,�,�K���#�4�;�#�	3�%�� �+�t�}�
�
�
���'�,����+���'��2�2�2�2�2��%�	�	�	��=�
��c�!�f�f�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
������	�	�	��#�a�&�&�M�M�M�M�M�M�M�M�M�����	����
��#�
�h�t�y�!�!�"�"�"�"�"�#�#s$�;B9�9
D&�#C2�2
D&�?D!�!D&c�f�t��}td|�����dS)zDTool to validate schema of a cloud-config file or print schema docs.r�r)r�r��
parse_argsr�s r0�mainr��s-��
�\�\�F��+�V�->�->�-@�-@�A�A�A��1r/�__main__rD)T)NFFTF)F)r})grYr�r��loggingr%r��sysr��collectionsr�collections.abcr�copyr�	functoolsr�	itertoolsrr-rr	r
rrr
rr2�	cloudinitrr�cloudinit.stagesr�cloudinit.utilrrrr_r�_ValidationErrorr`r��	getLoggerr(r��VERSIONED_USERDATA_SCHEMA_FILEr�rMr.r�r�r�r�r�r�r�rk�typing_extensionsrrrr�r2r4rZr+rJr�rLrgrnrWrvr�r�r�r�r�r�rdrr:r@rBrPr^rir[rsr|r�r�r�r�r�r�r�r�r�r�r�r�r��exitr.r/r0�<module>rs���L�L�������������	�	�	�	�	�	�	�	�
�
�
�
�����#�#�#�#�#�#�$�$�$�$�$�$�������������������O�O�O�O�O�O�O�O�O�O�O�O�O�O�O�O�O�O�����(�(�(�(�(�(�(�(�!�!�!�!�!�!�A�A�A�A�A�A�A�A�A�A� �>�>�>�>�>�>�&�O�O��� � � ��O�O�O� ����	����%�%�%���g���!�!��!D��5���'��8�8�	�&����$.��L��N��.��">����"��
���M�M�M�8�8�8�8�8�8�8�8�8�8�8�8�8�Y�8�8�8�8��J�	�	�	�	�	�_�	�	�	�.�.�.�.�.�J�.�.�.��m�$��!��		�	�	�#�	�
�S�M�	��		�
	�	�	�	�	� (� (� (� (� (�J� (� (� (�F(�(�(�7�7�h�s�m�7�s�7�7�7�7�#9�����
�	�
�Y������.#9�! �! �
�Y��! �! �! �! �R#9�,$�,$�
�Y��,$�,$�,$�,$�^G/�G/�G/�T 
� 
�t� 
� 
� 
� 
�J��#��"�
J�J��J��J�
�J��	J�
�J��
J�J�J�J�Zr,�r,�r,�r,�r,�r,�r,�r,�t/3�48�
���������
�N�+��"�.�1�
��3��:������0g�g�g�g�T

�

�

����*�D�*�S�*�T�#�Y�*�*�*�*�")(�d�)(�$�)(�3�)(�)(�)(�)(�X�s�����,/�$�/�d�/�/�/�/�4
#�D�
#�
#�
#�
#�$�4�$�C�$�$�$�$�NE#�E#�d�E#�$�E#�#�E#�E#�E#�E#�P
�
�
�s�
�
�
�
� ;�:�;�#�;�;�;�;�;�;�z�;�8�D�>�;�S�;�;�;�;�|-�T�-�-�-�-�
��������4O��O�O�O�O��D�����>
�$�
�
�
�
�!�!�!�!�H#�#�#�8
�
�
��z����C�H�T�T�V�V�������s�,A5�5A?�>A?