%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core18/2887/usr/lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Create Path :
Current File : //snap/core18/2887/usr/lib/python3/dist-packages/cloudinit/config/__pycache__/schema.cpython-36.pyc

3

�Ad���@sdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZmZmZmZmZmZmZddlZdd	lmZmZdd
lmZddl m!Z!m"Z"m#Z#yddl$m%Z&e&Z%Wne'k
�re(Z%YnXej)e*�Z+d
Z,dZ-dddd�Z.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7e�rvddlZddl8m9Z9m:Z:Gdd�de:�Z;ne<Z;Gdd �d e%�Z=Gd!d"�d"e�Z>ee>Z?dd#d$�e?ee@e@e@d%�d&d'�ZAGd(d)�d)eB�ZCd*d+�ZDde<e@d-�d.d/�ZEe=feFe<e@ee(d0�d1d2�ZGeeGdd3�ZHeeGd4d3�ZIe=fee(d5�d6d7�ZJe=fee(d5�d8d9�ZKd:d;�ZLd�e<d=�d>d?�ZMd�e<ee<eFeFeFeFd@�dAdB�ZNGdCdD�dD�ZOdddE�e<ePe<ee?ee?ee@ePfdF�dGdH�ZQd�dIdJ�ZRdKdL�ZSdMdN�ZTe<e@ee@dO�dPdQ�ZUe<e<e@dR�dSdT�ZVe@dU�dVdW�ZWe<e<dX�dYdZ�ZXe<d[�d\d]�ZYe<e@d^�d_d`�ZZd�e<e<e@db�dcdd�Z[e;e@de�dfdg�Z\e;e@de�dhdi�Z]d�e;ee<e@dj�dkdl�Z^e<dU�dmdn�Z_e`e@do�dpdq�Zae@dU�drds�Zbe<dU�dtdu�Zce<dU�dvdw�Zdd�dxdy�Zedzd{�Zfd|d}�Zge*d~k�rejheg��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)�Init)�error�get_modules_from_dir�	load_file)�ValidationErrorz!versions.schema.cloud-config.jsonzschema-cloud-config-v1.json�trueZfalseZnull)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@sBeZdZUeeeeej	e
ej	eee
e	edS)�
MetaSchemaN)�__name__�
__module__�__qualname__�str�name�id�title�description�typingr�distros�examples�	frequencyr�activate_by_schema_keys�r'r'�9/usr/lib/python3/dist-packages/cloudinit/config/schema.pyrKs


rc@seZdZdS)�SchemaDeprecationErrorN)rrrr'r'r'r(r)Ysr)c@s$eZdZUeeed�dd�ZdS)�
SchemaProblem)�returncCs|j�d|j��S)Nz: )�path�message)�selfr'r'r(�formataszSchemaProblem.formatN)rrrrr,r-r/r'r'r'r(r*]s
r*z, )�prefix�	separator)�schema_problemsr0r1r+cCs(|jtdd�|��}|r$|�|��}|S)NcSs|j�S)N)r/)�pr'r'r(�<lambda>nsz)_format_schema_problems.<locals>.<lambda>)�join�map)r2r0r1Z	formattedr'r'r(�_format_schema_problemshsr7cs@eZdZdZd	eeeed��fdd�
Zed�dd�Z�Z	S)
�SchemaValidationErrorz<Raised when validating a cloud-config file against a schema.N)�
schema_errors�schema_deprecationscsTd}|r|t|dd�7}|r8|r(|d7}|t|dd�7}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),)
        �zCloud config schema errors: )r0z

z"Cloud config schema deprecations: N)r7�super�__init__r9r:)r.r9r:r-)�	__class__r'r(r=ws
zSchemaValidationError.__init__)r+cCs
t|j�S)N)�boolr9)r.r'r'r(�
has_errors�sz SchemaValidationError.has_errors)NN)
rrr�__doc__r
�SchemaProblemsr=r?r@�
__classcell__r'r')r>r(r8tsr8cCs@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)�
jsonschemarD�ImportError�TYPE_CHECKERZis_type�
isinstance�bytes)Zchecker�instancerDr'r'r(�is_schema_byte_string�srLF)�configr+csRtd���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)Nr;Z_descriptionZ_versionz	<missing z'_version key, please file a bug report>z in version z. � z

*�*)�get�
capitalize�strip)rNZkey_description�v�msg)�annotaterMr'r(�format_message�s
z:_add_deprecated_changed_or_new_msg.<locals>.format_messager�changed�newr;r!)rr5r6rQ�rstrip)rMrV�
filter_keyrWZfilter_keysZchanged_new_deprecatedr!r')rVrMr(�"_add_deprecated_changed_or_new_msg�s
	r\)r�schemar[�
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)rVr[N)r\)�
_validatorrZ	_instancer]r[r^rUr'r'r(r_�s
r_)r[rX)r^c
#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)rI)�e)r^r'r(r4�sz_anyOf.<locals>.<lambda>cs
t|��S)N)rI)ra)r^r'r(r4�sz.%r is not valid under any of the given schemas)�contextN)rFr�	enumerate�list�descend�filter�extend)
�	validator�anyOfrK�_schemar^r�
all_errors�all_deprecations�index�	subschema�all_errs�errs�deprecationsr')r^r(�_anyOf�s"

rrc#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)r`cst|��S)N)rI)ra)r^r'r(r4sz_oneOf.<locals>.<lambda>cs
t|��S)N)rI)ra)r^r'r(r4sz.%r is not valid under any of the given schemas)rbcs g|]\}}�j�|�r|�qSr')�is_valid)�.0�i�s)rKrhr'r(�
<listcomp>(sz_oneOf.<locals>.<listcomp>z, css|]}t|�VqdS)N)�repr)rtr]r'r'r(�	<genexpr>+sz_oneOf.<locals>.<genexpr>z%r is valid under each of %sN)	rFrrcrdrerfrg�appendr5)rh�oneOfrKrjr^rZ
subschemasrkrlrmrnrorprqZfirst_validZ
more_validZreprsr')r^rKrhr(�_oneOfs2


r|c
Cs�ddlm}m}ddlm}t|j�}d|d<ddi|dd	<i}t|d
�rd|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)rD�
FormatChecker)�createFZadditionalProperties�typerE�
properties�labelrH�type_checkerZ
default_typesrXr{riZdraft4)Zmeta_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)rIr))rar'r'r(r4rsz<get_jsonschema_validator.<locals>.is_valid.<locals>.<lambda>N)rf�iter_errors�next)r.rKrj�__�errorsr'r'r(rslsz*get_jsonschema_validator.<locals>.is_valid)N)rFrDr}Zjsonschema.validatorsr~rZMETA_SCHEMA�hasattrrHZredefinerLZ
DEFAULT_TYPESrrJ�dictZ
VALIDATORS�_validator_deprecated�DEPRECATED_KEY�_validator_changedr|rrrs)
rDr}r~�strict_metaschemaZvalidator_kwargsr��typesr��cloudinitValidatorrsr'r'r(�get_jsonschema_validator3s4





r�T)r]cCszddlm}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)rtr3r'r'r(rw�sz3validate_cloudconfig_metaschema.<locals>.<listcomp>)r9zGMeta-schema validation failed, attempting to validate config anyway: %sN)
Zjsonschema.exceptionsr�Zcheck_schemar8r*r5r,r-�LOG�warning)rhr]�throwr��errr'r'r(�validate_cloudconfig_metaschema~s
 r�)rMr]�strictr��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)r,)rar'r'r(r4�sz-validate_cloudconfig_schema.<locals>.<lambda>)rNr�cSsg|]}t|��qSr')r)rtr3r'r'r(rw�sz/validate_cloudconfig_schema.<locals>.<listcomp>z"Deprecated cloud-config provided:
�
)r0r1zInvalid cloud-config provided:
zeInvalid cloud-config provided: Please run 'sudo cloud-init schema --system' to see the schema errors.)�
get_schemar�r�rGr��debug�sortedr�r5r,r*r-rIr)r7r�r8)rMr]r�r�r�r�r�r}rhr�rqZschema_errorr,�problemr-Zdetailsr'r'r(�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)r.r�r�r�r'r'r(r=�sz_Annotator.__init__)r �contentr+cCsdj|�}d|�d|�d�S)Nr�z# z: -------------
z

)r5)r r�Zbodyr'r'r(�
_build_footer�s
z_Annotator._build_footer)r2cCs~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�colrU)	rrd�re�match�groups�intrzr�r/)r.r2�errors_by_liner,rUr�r�r�r'r'r(�_build_errors_by_linesz _Annotator._build_errors_by_liner;)�problems�labels�footerrm�label_prefixr+cCsFx@|D]8}|�|��}|j|�|jd|�d|���|d7}qW|S)Nz# z: �)rz)r�r�r�rmr�r�r�r'r'r(�
_add_problemss

z_Annotator._add_problems)�linesr��deprecations_by_liner+cs�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)r.r'r(r4Asz._Annotator._annotate_content.<locals>.<lambda>cSst|d�S)Nr�)r?)r�r'r'r(r4Cs�ErrorsZDeprecations)rcr�rzr5rgr6rf)r.r�r�r��annotated_contentZerror_footerZdeprecation_footerZerror_indexZdeprecation_indexZline_numberr�r�rqr�r')r.r(�_annotate_content!s8
z_Annotator._annotate_content)r9r:r+cCst|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�splitrIr�r�r5r�r�r�)r.r9r:r�r�r�r�r'r'r(rVMs


z_Annotator.annotateN)r;)rrrr�rJr=�staticmethodrrr�rBr�r�r�r�rrVr'r'r'r(r��s 
)r�)r9r:)r�r�r�r9r:r+cCst|||�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�rV)r�r�r�r9r:r'r'r(�annotated_cloudconfig_filegsr�c
"Cs�t|dd�}|jt�sTtddj|tj���g}t|�}|rPtti|i|j	d��|�y&|rjt
j|�\}}nt
j|�}i}Wn�t
jk
�rN}z�d}	}
d}t|d�r�t|d�r�t|d�}nt|d	�r�t|d	�r�t|d	�}|r�|jd}	|jd}
td
j|	|
d�dj|t|���g}t|�}|�r8tti|i|j	d��||�WYdd}~XnXt|t��sj|�sjtd
��yt||ddd�Wnrtk
�r�}zT|�r�tt||||j	|jd��n |j�r�t|jddd�}t|�|j��r�WYdd}~XnXdS)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.
    F)r�zformat-l1.c1z"File {0} needs to begin with "{1}")r9r�NZcontext_markZ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�)r9r:z"Cloud config schema deprecations: z, )r0r1)r�
startswith�CLOUD_CONFIG_HEADERr*r/r�r8�printr�r9rZload_with_marks�load�yamlZ	YAMLErrorr��getattrr��columnrrIr��RuntimeErrorr�r:r7r@)
Zconfig_pathr]rVr�r�rr�Zmarksrar�r�Zmarkr-r'r'r(�validate_cloudconfig_filesv





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')�valuer'r'r(�_sort_property_order�s
r�ccsBx<|D]4}t|t�r4t|ttf�r4t|�EdHq|VqWdS)N)rIrrrJ�_flatten)Zxs�xr'r'r(r��s
r�)�
property_dict�	multi_keyr+cCsrg}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_MAPrQ)rtZ
enum_valuer'r'r(rw�sz,_collect_subschema_types.<locals>.<listcomp>r)rQr�rgrzrdr�)r�r��property_typesrnr'r'r(�_collect_subschema_types�s


r�)r��defsr+c
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.
    rr�cSs g|]}dtj||��d��qS)z``)r�rQ)rt�kr'r'r(rw
sz&_get_property_type.<locals>.<listcomp>r{rir�r)rN�/�itemsZ	UNDEFINEDz of �(�))�_flatten_schema_refsrQrIrdrgr��len�sortr�r5r?r�_get_property_typerz)
r�r�r�Z
property_typer�Zsub_property_typesZprune_undefined�sub_itemZsub_typeZsub_property_docr'r'r(r��s>







 
r�)r+cCsB|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��subr/)r!r0Zlist_paragraphr'r'r(�_parse_description+s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/r;r�r{ri�allOfN)�pop�replace�updaterrQ)r�r�Z	reference�
sub_schemar'r'r(r�As&

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_schemasr�r'r'r(�_flatten_schema_all_of[s

r�)�prop_configr+cCs�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 ":".
    )rM�descriptions�deprecated_descriptionscSs<tt|jd��r |jt|��n|jd�r8|jt|��dS)N�deprecated_version�changed_version�new_versionr!)r�r�r�)�anyr6rQrzr\)rMr�r�r'r'r(�assign_descriptionsss
z6_get_property_description.<locals>.assign_descriptionsr{riz. rO)r�rdrQrr5)r�r�r{rir�r�r�r!r'r'r(�_get_property_descriptionhs
r��    )r]r�r+c
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    �hiddenTr;cs$g|]}d�ks|�dkr|�qS)r�r')rtrN)r]r'r(rw�sz%_get_property_doc.<locals>.<listcomp>r��patternPropertiescsg|]}�j|i��qSr')rQ)rtrN)r]r'r(rw�sr�)r0�	prop_namer!Z	prop_typer�)r0r�)r�r0r{z

)r�r�)
rQr�r�r�r�rz�SCHEMA_PROPERTY_TMPLr/r�r��SCHEMA_LIST_ITEM_TMPL�_get_property_docr5)r]r�r0Z
new_prefixr�Z
property_keysZproperty_schemasZprop_schemaZprop_keyr�r!r�r�Z
alt_schemar')r]r(r��s^




r�)�metar+cCsn|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$r;z    r�rr�)
rQ�SCHEMA_EXAMPLES_HEADERrc�textwrap�indentr��insert�SCHEMA_EXAMPLES_SPACER_TEMPLATEr/r5)rr$Zrst_content�countZexampleZindented_linesr'r'r(�
_get_examples�s
rcCs2|jd�sdSdjdd�|dD��}d|�d�S)Nr&r;z, css|]}d|�d�VqdS)z``Nr')rtr�r'r'r(ry�sz3_get_activate_by_schema_keys_doc.<locals>.<genexpr>z**Activate only on keys:** z

)rQr5)rZschema_keysr'r'r(� _get_activate_by_schema_keys_doc�s

r)rr]r+c	
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 schemarr r$r%r#r!rr&r;z(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��
ValueError�set�keysr/�KeyErrorr�rrQr
r��AttributeErrorr�r��SCHEMA_PROPERTY_HEADERrr5r�r�r�SCHEMA_DOC_TMPL)	rr]rZ
required_keysZ
optional_keysZ
error_messageZ	meta_copyr��templater'r'r(�get_meta_doc�sT




rcCstjjtjjt��}t|�S)N)�osr,�dirname�abspath�__file__r)Zconfigs_dirr'r'r(�get_modules1sr)�requested_modulesr+cCs�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.
    r;�allz+Invalid --docs value {}. Must be one of: {}z, T)�sys_exitzcloudinit.configrr)rdr�valuesr�
differencerr/r5r�find_module�
import_modulerA)r�docsZall_modulesZinvalid_docs�mod_name�mod_locs�_�modr'r'r(�load_doc6s"

r$cCstjjtjjtjjt��d�S)NZschemas)rr,r5rrrr'r'r'r(�get_schema_dirQsr%cCsxtjjt�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�)rr,r5r%�USERDATA_SCHEMA_FILE�json�loadsr�	Exceptionr�r�)Zschema_file�full_schemarar'r'r(r�Us r�cCsZt�}xNt�j�D]@\}}tj|dgdg�\}}|rtj|d�}|j||jd<qW|S)z<Return metadata coalesced from all cc_* cloud-config module.zcloudinit.configrrr)r�rr�rrrr)Z	full_metar"r r!r#r'r'r(�get_metatsr+cCs\|stjddd�}|jdddd�|jdd	d
dd�|jd
dddd�|jdd	d
dd�|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--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)�parserr'r'r(�
get_parser�s0r7cCs�|j|j|jg}tdd�|D��dkr2tddd�|jrJ|jrJtddd�t�}|jrhtt|j��dS|jr|d	|jff}n�t	j
�d
kr�tddd�tgd�}|jd
d�|j
jd�}|s�tddd�dSd	|ff}d|j
jd�fd|j
jd�ff}x.|D]&\}}	|	r�t	jj|	�r�|||	ff7}q�Wt	jj|d
d��sXtd|d
d�d�ddd�d}
tt|�dk�}|�r�tddjdd�|D���d}
g}�x$t|d�D�]\}
\}}|�r�td|
�d |�d!|�d"��yt|||j�Wn�tk
�rB}z>|j�s2t|
�d#|���tt|�|
d$d%�|j|�WYdd}~Xnvtk
�r�}z6t|
�d#|���tt|�|
d$d%�|j|�WYdd}~Xn$X|j�r�|n|}t|
�d&|����q�W|�r�tdjd'd�|D��d(dd�dS))z@Handle provided schema args and perform the appropriate actions.cSsg|]}|r|�qSr'r')rt�argr'r'r(rw�sz&handle_schema_args.<locals>.<listcomp>r�z;Expected one of --config-file, --system or --docs argumentsT)rz;Invalid flag combination. Cannot use --annotate with --docsNz	user-datarzNUnable to read system userdata or vendordata as non-root user. Try using sudo.)Zds_depsZtrust)�existingZ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: {})�fmtrr;z!Found cloud-config data types: %sz, css|]\}}|VqdS)Nr')rt�cfg_typer"r'r'r(ry�sz%handle_schema_args.<locals>.<genexpr>z  r�z. z at �:zInvalid cloud-config z
Error: {}
)r:zValid cloud-config: css|]
}|VqdS)Nr')rtr^r'r'r(ry�sz'Error: Invalid cloud-config schema: {}
)Zconfig_filer�systemr�rrVr�r�r$r�getuidrZfetch�pathsZ	get_ipathr,�existsr?r5rcr�r8rrzr�)r�argsZexclusive_argsr*Zconfig_filesZinitZ
userdata_fileZvendor_config_filesr;Zvendor_fileZnested_output_prefixZmulti_config_outputZerror_types�idxZcfg_fileraZcfgr'r'r(�handle_schema_args�s�

rCcCst�}td|j��dS)zDTool to validate schema of a cloud-config file or print schema docs.zcloudconfig-schemar)r7rC�
parse_args)r6r'r'r(�main�srE�__main__)FN)T)NFFTF)F)r�)N)N)irAr3r'Zloggingrr��sysr�collectionsr�collections.abcr�copyr�	functoolsr�	itertoolsrr"rrr	r
rrr
r�Z	cloudinitrrZcloudinit.stagesrZcloudinit.utilrrrrFrZ_ValidationErrorrGr)Z	getLoggerrr�ZVERSIONED_USERDATA_SCHEMA_FILEr&r�r�rrr�r�rrr�ZDEPRECATED_PREFIXZtyping_extensionsrrrr�r)r*rBrr7r
r8rLr\r?r_r�r�rrr|r�r�r�r�rJr�r�r�r�r�r�r�r�r�r�r�rrrrrdr$r%r�r+r7rCrE�exitr'r'r'r(�<module>s�$

#'$*K%Kz
Z
,
*H	>
$X


Zerion Mini Shell 1.0