BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/cloudinit/config/__pycache__/schema.cpython-36.pyc
3

�q�h	��@s*dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZmZmZmZmZmZmZddlZdd	lmZmZdd
lmZddl m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'ydd
l(m)Z*e*Z)Wne+k
�re,Z)YnXej-e.�Z/dZ0dZ1dddd�Z2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:e;dd�e!j<�D��Z=e�r�ddlZddl>m?Z?m@Z@Gdd �d e@�ZAneBZAGd!d"�d"e)�ZCGd#d$�d$e�ZDeeDZEdd%d&�eEeeFeFeFd'�d(d)�ZGGd*d+�d+eH�ZId,d-�ZJd�eBeFd/�d0d1�ZKeCfeLeBeFee,d2�d3d4�ZMeeMdd5�ZNeeMd6d5�ZOeCfee,d7�d8d9�ZPeCfee,d7�d:d;�ZQd<d=�ZRd�eBd?�d@dA�ZSd�eBeeBeLeLeLeLdB�dCdD�ZTGdEdF�dF�ZUdddG�eBeVeBeeEeeEeeFeVfdH�dIdJ�ZWd�eFeBeLeFdK�dLdM�ZXdNdO�ZYdPdQ�ZZeBeFeeFdR�dSdT�Z[eBeBeFdU�dVdW�Z\eFdX�dYdZ�Z]eBeBd[�d\d]�Z^eBd^�d_d`�Z_eBeFda�dbdc�Z`d�eBeBeFde�dfdg�ZaeAeFdh�didj�ZbeAeFdh�dkdl�Zcd�eAeeBeFdm�dndo�ZdeBdX�dpdq�ZeefeFdr�dsdt�ZgeFdX�dudv�ZheBdX�dwdx�Zid�dydz�Zjd{d|�Zkd}d~�Zle.dk�r&ejmel��dS)�zFschema.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)�read_cfg_paths)�INCLUSION_TYPES_MAP�type_from_starts_with)�
decode_binary�error�get_modules_from_dir�	load_file)�ValidationErrorz!versions.schema.cloud-config.jsonzschema-cloud-config-v1.json�trueZfalseZnull)TFNz�
{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: cCsg|]}|ddkr|�qS)r�#�)�.0�trr�/usr/lib/python3.6/schema.py�
<listcomp>Jsr)�NotRequired�	TypedDictc@sBeZdZUeeeeej	e
ej	eee
e	edS)�
MetaSchemaN)�__name__�
__module__�__qualname__�str�name�id�title�description�typingr�distros�examples�	frequencyr �activate_by_schema_keysrrrrr"Ts


r"c@seZdZdS)�SchemaDeprecationErrorN)r#r$r%rrrrr0bsr0c@s$eZdZUeeed�dd�ZdS)�
SchemaProblem)�returncCs|j�d|j��S)Nz: )�path�message)�selfrrr�formatjszSchemaProblem.formatN)r#r$r%r&r3r4r6rrrrr1fs
r1z, )�prefix�	separator)�schema_problemsr7r8r2cCs(|jtdd�|��}|r$|�|��}|S)NcSs|j�S)N)r6)�prrr�<lambda>wsz)_format_schema_problems.<locals>.<lambda>)�join�map)r9r7r8Z	formattedrrr�_format_schema_problemsqsr>cs@eZdZdZd	eeeed��fdd�
Zed�dd�Z�Z	S)
�SchemaValidationErrorz<Raised when validating a cloud-config file against a schema.N)�
schema_errors�schema_deprecationscs<d��fdd�}||dd�|_||dd�|_t�j��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),)
        �cs8|s|S�r�d7�ttt|���}�t||d�7�|S)Nz

)r7)�sorted�list�setr>)�problemsr7)r4rr�handle_problems�sz7SchemaValidationError.__init__.<locals>.handle_problemszCloud config schema errors: )r7z"Cloud config schema deprecations: N)r@rA�super�__init__)r5r@rArG)�	__class__)r4rrI�s


zSchemaValidationError.__init__)r2cCs
t|j�S)N)�boolr@)r5rrr�
has_errors�sz SchemaValidationError.has_errors)NN)
r#r$r%�__doc__r
�SchemaProblemsrIrKrL�
__classcell__rr)rJrr?}sr?cCs@yddlm}Wntk
r$dSX|jj|d�p>t|tf�S)zWTYPE_CHECKER override allowing bytes for string type

    For jsonschema v. 3.0.0+
    r)�Draft4ValidatorF�string)�
jsonschemarP�ImportError�TYPE_CHECKERZis_type�
isinstance�bytes)Zchecker�instancerPrrr�is_schema_byte_string�srXF)�configr2csRtd���fdd�}|r|ndddg}djt||��}�jdd�}|�|��j�S)	z�combine description with new/changed/deprecated message

    deprecated/changed/new keys require a _version key (this is verified
    in a unittest), a _description key is optional
    )�keycsr�j|��sdS�j|�d�d�}�j|�d�d|�d��}|j��d|�d|��}�rbd|��Sd	|j��d
�S)NrBZ_descriptionZ_versionz	<missing z'_version key, please file a bug report>z in version z. � z

*�*)�get�
capitalize�strip)rZZkey_description�v�msg)�annotaterYrr�format_message�s
z:_add_deprecated_changed_or_new_msg.<locals>.format_messager�changed�newrBr*)r&r<r=r]�rstrip)rYrb�
filter_keyrcZfilter_keysZchanged_new_deprecatedr*r)rbrYr�"_add_deprecated_changed_or_new_msg�s
	rh)r�schemarg�
error_typeccs"|rt|d|gd�}||�VdS)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.
    T)rbrgN)rh)�
_validatorrZ	_instancerirgrjrarrrrk�s
rk)rgrd)rjc
#s�ddlm}g}g}x�t|�D]b\}}	t|j||	|d��}
tt�fdd�|
��}tt�fdd�|
��}|sv|j|�P|j|�qW|d|f|d�V|Ed	Hd	S)
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`.
    r)r)�schema_pathcst|��S)N)rU)�e)rjrrr;sz_anyOf.<locals>.<lambda>cs
t|��S)N)rU)rm)rjrrr;sz.%r is not valid under any of the given schemas)�contextN)rRr�	enumeraterD�descend�filter�extend)
�	validator�anyOfrW�_schemarjr�
all_errors�all_deprecations�index�	subschema�all_errs�errs�deprecationsr)rjr�_anyOf�s"

r}c#s�ddlm}t|�}g}g}x�|D]f\}	}
t�j�|
|	d��}tt�fdd�|��}tt�fdd�|��}
|s~|
}|j|
�P|j|�q"W|d�f|d�V��fd	d
�|D�}|r�|j|�djdd
�|D��}|d�|f�Vn
|EdHdS)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`.
    r)r)rlcst|��S)N)rU)rm)rjrrr;(sz_oneOf.<locals>.<lambda>cs
t|��S)N)rU)rm)rjrrr;*sz.%r is not valid under any of the given schemas)rncs g|]\}}�j�|�r|�qSr)�is_valid)r�i�s)rWrsrrr7sz_oneOf.<locals>.<listcomp>z, css|]}t|�VqdS)N)�repr)rrirrr�	<genexpr>:sz_oneOf.<locals>.<genexpr>z%r is valid under each of %sN)	rRrrorDrprqrr�appendr<)rs�oneOfrWrurjrZ
subschemasrvrwrxryrzr{r|Zfirst_validZ
more_validZreprsr)rjrWrsr�_oneOfs2


r�c
Cs�ddlm}m}ddlm}t|j�}ddi|dd<i}t|d�rdd	|d
<|jj	dt
�}d|i}n|j}tt
f|d<d|i}t|j�}t|t<t|d
<t|d<t|d<|f||dd�|��}ddd�}	|	|_||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)rP�
FormatChecker)�create�typerQ�
properties�labelrTFZadditionalProperties�type_checkerZ
default_typesrdr�rtZdraft4)�meta_schema�
validators�versionNc[s$tdd�|j||��}t|d�dkS)zgOverride version of `is_valid`.

        It does ignore instances of `SchemaDeprecationError`.
        cSst|t�S)N)rUr0)rmrrrr;�sz<get_jsonschema_validator.<locals>.is_valid.<locals>.<lambda>N)rq�iter_errors�next)r5rWru�__�errorsrrrr~|sz*get_jsonschema_validator.<locals>.is_valid)N)rRrPr�Zjsonschema.validatorsr�rZMETA_SCHEMA�hasattrrTZredefinerXZ
DEFAULT_TYPESr&rV�dictZ
VALIDATORS�_validator_deprecated�DEPRECATED_KEY�_validator_changedr�r}r~)
rPr�r�r�Zvalidator_kwargsr��typesr��cloudinitValidatorr~rrr�get_jsonschema_validatorBs4





r�T)ricCszddlm}y|j|�WnZ|k
rt}z>|rXttdjdd�|jD��|j�gd�|�tj	d|�WYdd}~XnXdS)	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)�SchemaError�.cSsg|]}t|��qSr)r&)rr:rrrr�sz3validate_cloudconfig_metaschema.<locals>.<listcomp>)r@zGMeta-schema validation failed, attempting to validate config anyway: %sN)
Zjsonschema.exceptionsr�Zcheck_schemar?r1r<r3r4�LOG�warning)rsri�throwr��errrrr�validate_cloudconfig_metaschema�s
 r�)rYri�strict�strict_metaschema�log_details�log_deprecationsc
Cs(|dkrt�}y t�\}}|r,t||dd�Wntk
rLtjd�dSX|||�d�}g}	g}
x^t|j|�dd�d�D]D}d	jd
d�|j	D��}t
||j�f}
t|t
�r�|
|
7}
q||	|
7}	q|W|r�|
r�t|
dd
d�}tj|�|r�|	s�|
r�t|	|
��|	�r$|�rt|	dd
d�}nd}tj|�dS)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)Zformat_checkercSs|jS)N)r3)rmrrrr;�sz-validate_cloudconfig_schema.<locals>.<lambda>)rZr�cSsg|]}t|��qSr)r&)rr:rrrr�sz/validate_cloudconfig_schema.<locals>.<listcomp>z"Deprecated cloud-config provided:
�
)r7r8zInvalid cloud-config provided:
zeInvalid cloud-config provided: Please run 'sudo cloud-init schema --system' to see the schema errors.)�
get_schemar�r�rSr��debugrCr�r<r3r1r4rUr0r>rr?r�)rYrir�r�r�r�r�r�rsr�r|�schema_errorr3�problemr4Zdetailsrrr�validate_cloudconfig_schema�sJ





r�c	@s�eZdZeeed�dd�Zeeeeed�dd��Z	e
d�dd	�Zedeeeeeeeeed�dd
��Z
eeeeeed�dd�Ze
e
eeefd�dd�ZdS)�
_Annotator)�cloudconfig�original_content�schemamarkscCs||_||_||_dS)N)�_cloudconfig�_original_content�_schemamarks)r5r�r�r�rrrrIsz_Annotator.__init__)r)�contentr2cCsdj|�}d|�d|�d�S)Nr�z# z: -------------
z

)r<)r)r�Zbodyrrr�
_build_footers
z_Annotator._build_footer)r9cCs~tt�}xp|D]h\}}tjd|�}|rF|j�\}}|t|�j|�nd}||j|j|�|dk	rdj|||d�}qW|S)Nz&format-l(?P<line>\d+)\.c(?P<col>\d+).*zLine {line} column {col}: {msg})�line�colra)	rrD�re�match�groups�intr�r�r6)r5r9�errors_by_liner3rar�r�r�rrr�_build_errors_by_linesz _Annotator._build_errors_by_linerB)rF�labels�footerrx�label_prefixr2cCsFx@|D]8}|�|��}|j|�|jd|�d|���|d7}qW|S)Nz# z: �)r�)rFr�r�rxr�r�r�rrr�
_add_problems$s

z_Annotator._add_problems)�linesr��deprecations_by_liner2cs�g}g}g}d}d}x~t|d�D]p\}	}
||	}||	}|s@|r�g}
�j||
||dd�}�j||
||dd�}|j|
ddj|
��q |j|
�q W|jt�fdd�td	d�d
|fd|ff���|S)Nr��E)r��Dz		# �,cs
�j|�S)N)r�)�seq)r5rrr;Ssz._Annotator._annotate_content.<locals>.<lambda>cSst|d�S)Nr�)rK)r�rrrr;Us�ErrorsZDeprecations)ror�r�r<rrr=rq)r5r�r�r��annotated_contentZerror_footerZdeprecation_footerZerror_indexZdeprecation_indexZline_numberr�r�r|r�r)r5r�_annotate_content3s8
z_Annotator._annotate_content)r@rAr2cCst|r|r|jS|jj�jd�}t|jt�sHdj||jddg�g�S|j|�}|j|�}|j	|||�}dj|�S)Nr�r�z&# E1: Cloud-config is not a YAML dict.)
r��decode�splitrUr�r�r<r�r�r�)r5r@rAr�r�r�r�rrrrb_s


z_Annotator.annotateN)rB)r#r$r%r�rVrI�staticmethodr&rr�rNr�r�r�r�rrbrrrrr�s 
)r�)r@rA)r�r�r�r@rAr2cCst|||�j|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�rb)r�r�r�r@rArrr�annotated_cloudconfig_fileysr�)�config_pathrirb�instance_data_pathc0Cs�ddlm}m}m}t|dd�}t|�}d}	|sRtt|	d|�ddjt	����g��|d"krnt
d|�d��d
S|d
k�ry|t|�||�j�}Wnd|k
r�}
ztt|	d�g�|
�WYd
d
}
~
Xn2|k
r�}
zt
t|
�dd�WYd
d
}
~
XnXd}	t|�}|�sF|d
t|�jd��}tt|	d|�d|�ddjt	����g��y(|�r^tj|�\}}
ntj|�}i}
Wn�tjk
�rL}
z�d}}d
}t|
d��r�t|
d��r�t|
d�}n"t|
d��r�t|
d��r�t|
d�}|�r�|jd}|jd}tdj||d�dj|t|
���g}t|�}|�r6t
ti|i|jd��||
�WYd
d
}
~
XnXt|t��sh|�shtd��yt||ddd�Wnrtk
�r�}
zT|�r�t
t|||
|
j|
j d��n |
j �r�t!|
j d dd!�}t
|�|
j"��rނWYd
d
}
~
XnXd
S)#ayValidate 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.
    @param instance_data_path: Path to instance_data JSON, used for text/jinja
        rendering.

    @raises SchemaValidationError containing any of schema_errors encountered.
    @raises RuntimeError when config_path does not exist.
    r)�JinjaLoadError�
NotJinjaError�render_jinja_payload_from_fileF)r�zformat-l1.c1z(No valid cloud-init user-data header in z$.
Expected first line to be one of: z, �text/cloud-config�text/jinja2zUser-data type 'z.' not currently evaluated by cloud-init schemaNzRDetected type '{user_data_type}' from header. But, content is not a jinja templateT)�sys_exitzformat-l2.c1r�z!Unrecognized user-data header in z: z). Expected one of the following headers: r�Zcontext_markZproblem_markzformat-l{line}.c{col})r�r�zFile {0} is not valid yaml. {1})r@z Cloud-config is not a YAML dict.)r�r�)r@rAz"Cloud config schema deprecations: )r7r8)r�r�)#Z!cloudinit.handlers.jinja_templater�r�r�rrr?r1r<�USERDATA_VALID_HEADERS�printr�encoderr&�findrZload_with_marks�load�yamlZ	YAMLErrorr��getattrr��columnr6r�r@rUr��RuntimeErrorr�rAr>rL)r�rirbr�r�r�r�r�Zuser_data_typeZschema_positionrmZcontent_headerr�Zmarksr�r�Zmarkr�r�r4rrr�validate_cloudconfig_file�s�
""




r�cCs|dkrdS|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.
    Zarray��objectr�rr)�valuerrr�_sort_property_orders
r�ccsBx<|D]4}t|t�r4t|ttf�r4t|�EdHq|VqWdS)N)rUrr&rV�_flatten)Zxs�xrrrr�&s
r�)�
property_dict�	multi_keyr2cCsrg}x`|j|i�D]P}|jt�r"q|jd�rJ|jdd�|jdg�D��q|jd�r|j|d�qWtt|��S)N�enumcSs g|]}dtj||��d��qS)z``)�	_YAML_MAPr])rZ
enum_valuerrrr6sz,_collect_subschema_types.<locals>.<listcomp>r�)r]r�rrr�rDr�)r�r��property_typesryrrr�_collect_subschema_types.s


r�)r��defsr2c
Cs|t||�|jdg�}t|t�s&|g}|jd�rDdd�|dD�}n6|jd�r`|jt|d��n|jd�rz|jt|d��t|�dkr�|d}n|jtd	�d
j	|�}|jdi�}|jdg�}t|t�s�|g}t
|�}xHt|jdi�|jdi��D]*}t||�}|�r|dk�rq�|j
|�q�W|�rrt|�dk�rF|�d
|d��S|jtd	�dd
j	|��d�}	|�d
|	��S|�pzdS)zNReturn a string representing a property type from a given
    jsonschema.
    r�r�cSs g|]}dtj||��d��qS)z``)r�r])r�krrrrJsz&_get_property_type.<locals>.<listcomp>r�rtr�r)rZ�/�itemsZ	UNDEFINEDz of �(�))�_flatten_schema_refsr]rUrDrrr��len�sortr�r<rKr�_get_property_typer�)
r�r�r�Z
property_typer�Zsub_property_typesZprune_undefined�sub_itemZsub_typeZsub_property_docrrrr�?s>







 
r�)r2cCsB|d}tjdd|�}tjddj|�|�}tjddj|�|�}|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��subr6)r*r7Zlist_paragraphrrr�_parse_descriptionksr�)�src_cfgr�cCsd|kr(|jd�jdd�}|j||�d|kr�d|dkrd|djd�jdd�}|dj||�d|dkr�x<|ddD],}d|kr~|jd�jdd�}|j||�q~WxTt|jdg�|jdg�|jdg��D],}d|kr�|jd�jdd�}|j||�q�WdS)	zEFlatten schema: replace $refs in src_cfg with definitions from $defs.z$refz#/$defs/rBr�r�rt�allOfN)�pop�replace�updaterr])r�r�Z	reference�
sub_schemarrrr��s&

r�)r�cCs0|jdd�}|sdSx|D]}|j|�qWdS)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.
    r�N)r�r�)r�Zsub_schemasrrrr�_flatten_schema_all_of�s

r)�prop_configr2cCs�tttd�dd�}|jdi�}|jdi�}g}g}||||�xt||�D]}||||�qJWdjt||��}|r|d|��}|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 ":".
    )rY�descriptions�deprecated_descriptionscSs<tt|jd��r |jt|��n|jd�r8|jt|��dS)N�deprecated_version�changed_version�new_versionr*)rrr)�anyr=r]r�rh)rYrrrrr�assign_descriptions�s
z6_get_property_description.<locals>.assign_descriptionsr�rtz. r[)r�rDr]rr<)rr	r�rtrrr�r*rrr�_get_property_description�s
r
�    )rir�r2c
s�|d}g}�jd�dkrdS�fdd�dD�}�fd	d�|D�}�xh|D�]^}�xV|j�D�]H\}}	t|	|�t|	�|	jd�dkr�q\t|	�}
|	jd
|�}|jtj||t|
|�t	|	|�d��|	jd�}|�r�t||�|jd�s�|jd��r |jt
j||d
��|d7}|jt|||d��x^|jdg�D]N}
|
jd��sJ|
jd��r.|jt
j||d
��|d7}|jt|
||d���q.Wd|	k�s�d|	kr\|jt|	||d��q\WqJWdj|�S)zDReturn restructured text describing the supported schema properties.z    �hiddenTrBcs$g|]}d�ks|�dkr|�qS)rr)rrZ)rirrr�sz%_get_property_doc.<locals>.<listcomp>r��patternPropertiescsg|]}�j|i��qSr)r])rrZ)rirrr�sr�)r7�	prop_namer*Z	prop_typer�)r7r)r�r7r�z

)r�r
)
r]r�r�rr
r��SCHEMA_PROPERTY_TMPLr6r�r��SCHEMA_LIST_ITEM_TMPL�_get_property_docr<)rir�r7Z
new_prefixr�Z
property_keysZproperty_schemasZprop_schemaZprop_keyrr*r�r�Z
alt_schemar)rirr�s^




r)�metar2cCsn|jd�}|sdSt}xRt|�D]F\}}tj|d�jd�}|tkrX|jdtj|d��|dj	|�7}q W|S)zAReturn restructured text describing the meta examples if present.r-rBz    r�rr�)
r]�SCHEMA_EXAMPLES_HEADERro�textwrap�indentr��insert�SCHEMA_EXAMPLES_SPACER_TEMPLATEr6r<)rr-Zrst_content�countZexampleZindented_linesrrr�
_get_exampless
rcCs2|jd�sdSdjdd�|dD��}d|�d�S)Nr/rBz, css|]}d|�d�VqdS)z``Nr)rr�rrrr�.sz3_get_activate_by_schema_keys_doc.<locals>.<genexpr>z**Activate only on keys:** z

)r]r<)rZschema_keysrrr� _get_activate_by_schema_keys_doc*s

r)rrir2c	
Csp|dkrt�}|s|r"td��t|j��}ddddddd	h}d
h}d}||rbdj||�}n|||r|d
j||�}|r�t|��tt|��}d|d<|jdi�}|j|d�r�|j|di�}t	t|�}yt
||d�|d<Wn(tk
�rtj
d�d|d<YnX|d�r t|d<t|�|d<dj|d�|d<tjdd|d	�|d<t|�|d
<tjf|�}|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 schemar(r)r-r.r,r*r'r/rBz(Missing required keys in module meta: {}z3Additional unexpected keys found in module meta: {}Zproperty_headerz$defs)r�Zproperty_docz3Unable to render property_doc due to invalid schemaz, r��-Ztitle_underbar)r��
ValueErrorrE�keysr6�KeyErrorr�rr]r
r�AttributeErrorr�r��SCHEMA_PROPERTY_HEADERrr<r�r�r�SCHEMA_DOC_TMPL)	rrirZ
required_keysZ
optional_keysZ
error_messageZ	meta_copyr��templaterrr�get_meta_doc3sT




r#cCstjjtjjt��}t|�S)N)�osr3�dirname�abspath�__file__r)Zconfigs_dirrrr�get_modulesqsr()�requested_modulesr2cCs�d}tt�j��dg}t|�jt|��}|rLtdjt|�dj|��dd�xR|D]J}d|ksf||krRtj	|dgdg�\}}|rRtj
|d	�}||jp�d7}qRW|S)
zaLoad module docstrings

    Docstrings are generated on module load. Reduce, reuse, recycle.
    rB�allz+Invalid --docs value {}. Must be one of: {}z, T)r�zcloudinit.configrr)rDr(�valuesrE�
differencerr6r<r�find_module�
import_modulerM)r)�docsZall_modulesZinvalid_docsZmod_nameZmod_locs�_�modrrr�load_docvs"

r2cCstjjtjjtjjt��d�S)NZschemas)r$r3r<r%r&r'rrrr�get_schema_dir�sr3cCsxtjjt�t�}d}ytjt|��}Wn0tk
rV}zt	j
d||�WYdd}~XnX|stt	j
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#)z$defsz$schemar�)r$r3r<r3�USERDATA_SCHEMA_FILE�json�loadsr�	Exceptionr�r�)Zschema_file�full_schemarmrrrr��s r�cCs||stjddd�}|jdddd�|jdd	td
t�jd���d�|jd
dddd�|jddddd�|jddddd�|S)z0Return a parser for supported cmdline arguments.zcloudconfig-schemaz.Validate cloud-config files or document schema)�progr*z-cz
--config-filez.Path of the cloud-config yaml file to validate)�helpz-iz--instance-datazbPath to instance-data.json file for variable expansion of '##template: jinja' user-data. Default: �
instance_data)r�r:z--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_argumentr&r�get_runpath)�parserrrr�
get_parser�s:rFcCs|j|j|jg}tdd�|D��dkr2tddd�|jrJ|jrJtddd�t�}|jrhtt|j��dSt	d	d
�}|j
r�|j
}n"tj�dkr�|j
d�}n
|j
d
�}|jr�d|jff}n�tj�dkr�tddd�|jd�}|s�tddd�dSd|ff}d|jd�fd|jd�ff}x4|D],\}	}
|
�rtjj|
��r||	|
ff7}�qWtjj|dd��s|td|dd�d�ddd�d}tt|�dk�}|�r�tddjdd�|D���d}g}
�x&t|d�D�]\}\}	}|�r�td |�d!|	�d"|�d#��yt|||j|�Wn�tk
�rh}z>|j�sXt|�d$|���tt|�|d%d&�|
j|	�WYdd}~Xnvtk
�r�}z6t|�d$|	���tt|�|d%d&�|
j|	�WYdd}~Xn$X|j�r�|n|	}t|�d'|����q�W|
�rtdjd(d�|
D��d)dd�dS)*z@Handle provided schema args and perform the appropriate actions.cSsg|]}|r|�qSrr)r�argrrrr�sz&handle_schema_args.<locals>.<listcomp>r�z;Expected one of --config-file, --system or --docs argumentsT)r�z;Invalid flag combination. Cannot use --annotate with --docsNZtrust)Zfetch_existing_datasourcerr;Zinstance_data_sensitivez	user-datazNUnable to read system userdata or vendordata as non-root user. Try using sudo.Zcloud_configz;Unable to obtain user data file. No instance data availablezvendor-dataZvendor_cloud_configzvendor2-dataZvendor2_cloud_configzConfig file z does not existz	Error: {})�fmtr�rBz!Found cloud-config data types: %sz, css|]\}}|VqdS)Nr)r�cfg_typer0rrrr�sz%handle_schema_args.<locals>.<genexpr>z  r�z. z at �:zInvalid cloud-config z
Error: {}
)rHzValid cloud-config: css|]
}|VqdS)Nr)rrjrrrr�;sz'Error: Invalid cloud-config schema: {}
)Zconfig_filer/�systemr�rrbr�r�r2rr;r$�getuidrDZ	get_ipathr3�existsrKr<ror�r?r&r�r�)r'�argsZexclusive_argsr8�pathsr�Zconfig_filesZ
userdata_fileZvendor_config_filesrIZvendor_fileZnested_output_prefixZmulti_config_outputZerror_types�idxZcfg_filermZcfgrrr�handle_schema_args�s�



rQcCst�}td|j��dS)zDTool to validate schema of a cloud-config file or print schema docs.zcloudconfig-schemar)rFrQ�
parse_args)rErrr�mainAsrS�__main__)FN)T)NFFTF)FN)r)N)N)nrMrAr5Zloggingr$r��sysr�collectionsr�collections.abcr�copyr�	functoolsr�	itertoolsrr+rrr	r
rrr
r�Z	cloudinitrrZcloudinit.cmd.develrZcloudinit.handlersrrZcloudinit.utilrrrrrRrZ_ValidationErrorrSr7Z	getLoggerr#r�ZVERSIONED_USERDATA_SCHEMA_FILEr4r�r!r rrrrr�ZDEPRECATED_PREFIXrCrr�Ztyping_extensionsr r!r"r�r0r1rNr&r>rr?rXrhrKrkr�r�r}r�r�r�r�r�rVr�r�r�r�r�r�r�r�rr
rrrr#r(rDr2r3r�rFrQrS�exitrrrr�<module>s�$

)'$*L%Mz
,
*H	>
._