404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.147.7.64: ~ $
3

\�mee��@s�dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZdd	lmZmZmZmZmZmZmZmZddlZdd
lmZm Z ddl!m"Z"ddl#m$Z$m%Z%dd
l&m'Z'ddl(m)Z)m*Z*m+Z+yddl,m-Z.e.Z-Wne/k
�r.e0Z-YnXej1e2�Z3dZ4dZ5dZ6de5ide6id�Z7dddd�Z8dZ9dZ:dZ;dZ<dZ=dZ>dZ?dZ@eAd d!�e$jB�D��ZCe�r�ddlZdd"lDmEZEmFZFGd#d$�d$eF�ZGneHZGGd%d&�d&e-�ZIGd'd(�d(e�ZJeeJZKGd)d*�d*e�ZLdd+d,�eKeeMeMeMd-�d.d/�ZNGd0d1�d1eO�ZPd2d3�ZQd�eHeMd5�d6d7�ZRee-d8�d9d:�ZSeIfeTeHeMee0d;�d<d=�ZUeeUdd>�ZVeeUd?d>�ZWeIfee0d@�dAdB�ZXeIfee0d@�dCdD�ZYdEdF�ZZd�eHdH�dIdJ�Z[d�eHeeHeMeTeTeTeTdL�dMdN�Z\GdOdP�dP�Z]dddQ�eHeMeHeeKeeKeeMe^fdR�dSdT�Z_eMeeJdU�dVdW�Z`d�eMeMeMeLdX�dYdZ�Zad�eMeHeMeTeMeTd[�d\d]�Zbd^d_�Zcd`da�ZdeHeMeeMdb�dcdd�ZeeHeHeMde�dfdg�ZfeMd8�dhdi�ZgeHeHdj�dkdl�ZheHdm�dndo�ZieHeMdp�dqdr�Zjd�eHeHeMdt�dudv�ZkeGeMdw�dxdy�ZleGeMdw�dzd{�Zmd�eGeeHeMd|�d}d~�ZneHd8�dd��ZoepeMd��d�d��ZqeMd8�d�d��Zrd�eMeHd��d�d��Zsd�d�d��Ztd�d��Zud�d��Zve2d�k�r�ejwev��dS)�zFschema.py: Set of module functions for processing cloud-config schema.�N)�defaultdict)�Iterable)�deepcopy)�EACCES)�partial)�chain)�
TYPE_CHECKING�DefaultDict�List�
NamedTuple�Optional�Type�Union�cast)�importer�safeyaml)�read_cfg_paths)�INCLUSION_TYPES_MAP�type_from_starts_with)�DataSourceNotFoundException)�error�get_modules_from_dir�	load_file)�ValidationErrorz!versions.schema.cloud-config.jsonzschema-cloud-config-v1.jsonzschema-network-config-v1.json�latest)zcloud-configznetwork-config�trueZfalseZnull)TFNap
{name}
{title_underbar}

{title}

.. tab-set::

{prefix3}.. tab-item:: Summary

{description}

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

{prefix6}**Module frequency:** {frequency}

{prefix6}**Supported distros:** {distros}

{prefix6}{activate_by_schema_keys}

{prefix3}.. tab-item:: Config schema

{property_doc}

{prefix3}.. tab-item:: Examples

{prefix6}::

{examples}
�z5{prefix}* **{prop_name}:** ({prop_type}){description}zJ{prefix}* Each object in **{prop_name}** list supports the following keys:z&
   # --- Example{example_count} ---

�
deprecatedzDEPRECATED: cCsg|]}|ddkr|�qS)r�#�)�.0�trr�/usr/lib/python3.6/schema.py�
<listcomp>psr#)�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_keysrrrr"r&zs


r&c@seZdZdS)�SchemaDeprecationErrorN)r'r(r)rrrr"r4�sr4c@s$eZdZUeeed�dd�ZdS)�
SchemaProblem)�returncCs|j�d|j��S)Nz: )�path�message)�selfrrr"�format�szSchemaProblem.formatN)r'r(r)r*r7r8r:rrrr"r5�s
r5c@seZdZUeedS)�UserDataTypeAndDecodedContentN)r'r(r)r*�
userdata_type�contentrrrr"r;�s
r;z, )�prefix�	separator)�schema_problemsr>r?r6cCs(|jtdd�|��}|r$|�|��}|S)NcSs|j�S)N)r:)�prrr"�<lambda>�sz)_format_schema_problems.<locals>.<lambda>)�join�map)r@r>r?Z	formattedrrr"�_format_schema_problems�srEcs@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),)
        rcs8|s|S�r�d7�ttt|���}�t||d�7�|S)Nz

)r>)�sorted�list�setrE)�problemsr>)r8rr"�handle_problems�sz7SchemaValidationError.__init__.<locals>.handle_problemszCloud config schema errors: )r>z"Cloud config schema deprecations: N)rGrH�super�__init__)r9rGrHrM)�	__class__)r8r"rO�s


zSchemaValidationError.__init__)r6cCs
t|j�S)N)�boolrG)r9rrr"�
has_errors�sz SchemaValidationError.has_errors)NN)
r'r(r)�__doc__r�SchemaProblemsrOrQrR�
__classcell__rr)rPr"rF�srFcCs@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)�
jsonschemarV�ImportError�TYPE_CHECKER�is_type�
isinstance�bytes)Zchecker�instancerVrrr"�is_schema_byte_string�sr_F)�configr6csRtd���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)NrZ_descriptionZ_versionz	<missing z'_version key, please file a bug report>z in version z. � z

*�*)�get�
capitalize�strip)raZkey_description�v�msg)�annotater`rr"�format_message�s
z:_add_deprecated_changed_or_new_msg.<locals>.format_messager�changed�newrr.)r*rCrDrd�rstrip)r`ri�
filter_keyrjZfilter_keysZchanged_new_deprecatedr.r)rir`r"�"_add_deprecated_changed_or_new_msg�s
	ro)r6cCs�g}d}t|t�od|k}x�|D]�}|r�|d|jjdi�jdi�jdg�krT|gSt|d�r||jdd�dkr�|j|�q�|jr�|jddkr�|j|�q t|j�|kr�|j|�q t|j�|kr t|j�}|g}q W|S)	z�Return the best_match errors based on the deepest match in the json_path

    This is useful for anyOf and oneOf subschemas where the most-specific error
    tends to be the most appropriate.
    r�type�
properties�enum�	json_path�N���)	r\�dict�schemard�hasattrrs�appendr7�len)�errorsr^Zbest_matchesZ
path_depthr[�errrrr"�cloud_init_deepest_matchess(




r})rrwrn�
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)rirnN)ro)�
_validatorrZ	_instancerwrnr~rhrrr"r#s
r)rnrk)r~c#s�ddlm}g}g}d}x�t|�D]�\}	}
t|j||
|	d��}tt�fdd�|��}tt�fdd�|��}
|sz|j|
�Pt|t�r�d|kr�d	|
j	d
d�kr�d|d��|
d
kr�d
}|EdH|j|�q"W|s�||�Vt
d|f|d�V|EdHdS)a�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`.

    Cloud-init's network schema under the `config` key has a complexity of
    allowing each list dict item to declare it's type with a `type` key which
    can contain the values: bond, bridge, nameserver, physical, route, vlan.

    This schema 'flexibility' makes it hard for the default
    jsonschema.exceptions.best_match function to find the correct schema
    failure because it typically returns the failing schema error based on
    the schema of greatest match depth. Since each anyOf dict matches the
    same depth into the network schema path, `best_match` just returns the
    first set of schema errors, which is almost always incorrect.

    To find a better schema match when encountering schema validation errors,
    cloud-init network schema introduced schema $defs with the prefix
    `anyOf_type_`. If the object we are validating contains a 'type' key, and
    one of the failing schema objects in an anyOf clause has a name of the
    format anyOf_type_XXX, raise those schema errors instead of calling
    best_match.
    r)�
best_matchF)�schema_pathcst|��S)N)r\)�e)r~rr"rBbsz_anyOf.<locals>.<lambda>cs
t|��S)N)r\)r�)r~rr"rBdsrpZ
anyOf_typez$refrZanyOf_type_TNz.%r is not valid under any of the given schemas)�context)�jsonschema.exceptionsr��	enumeraterJ�descend�filter�extendr\rvrdr)�	validator�anyOfr^�_schemar~r��
all_errors�all_deprecationsZskip_best_match�index�	subschema�all_errs�errs�deprecationsr)r~r"�_anyOf;s4




r�c#s�t|�}g}g}x~|D]f\}}	t�j�|	|d��}
tt�fdd�|
��}tt�fdd�|
��}|sr|	}
|j|�P|j|�qWt|��EdH��fdd�|D�}|r�|j|
�djd	d
�|D��}td�|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�cst|��S)N)r\)r�)r~rr"rB�sz_oneOf.<locals>.<lambda>cs
t|��S)N)r\)r�)r~rr"rB�sNcs g|]\}}�j�|�r|�qSr)�is_valid)r �i�s)r^r�rr"r#�sz_oneOf.<locals>.<listcomp>z, css|]}t|�VqdS)N)�repr)r rwrrr"�	<genexpr>�sz_oneOf.<locals>.<genexpr>z%r is valid under each of %s)	r�rJr�r�r�r}ryrCr)r��oneOfr^r�r~Z
subschemasr�r�r�r�r�r�r�Zfirst_validZ
more_validZreprsr)r~r^r�r"�_oneOf~s,

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)rV�
FormatChecker)�createrprWrq�labelrZF�additionalProperties�type_checkerZ
default_typesrkr�r�Zdraft4)�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)r\r4)r�rrr"rB�sz<get_jsonschema_validator.<locals>.is_valid.<locals>.<lambda>N)r��iter_errors�next)r9r^r��__r{rrr"r��sz*get_jsonschema_validator.<locals>.is_valid)N)rXrVr�Zjsonschema.validatorsr�rZMETA_SCHEMArxrZZredefiner_Z
DEFAULT_TYPESr*r]rvZ
VALIDATORS�_validator_deprecated�DEPRECATED_KEY�_validator_changedr�r�r�)
rVr�r�r�Zvalidator_kwargsr��typesr��cloudinitValidatorr�rrr"�get_jsonschema_validator�s4





r�T)rwcCszddlm}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*)r rArrr"r#sz3validate_cloudconfig_metaschema.<locals>.<listcomp>)rGzGMeta-schema validation failed, attempting to validate config anyway: %sN)
r�r�Zcheck_schemarFr5rCr7r8�LOG�warning)r�rw�throwr�r|rrr"�validate_cloudconfig_metaschema�s
 r��cloud-config)r`rw�schema_type�strict�strict_metaschema�log_details�log_deprecationsc
Csx|dkrt|�}y t�\}}|r.t||dd�Wntk
rNtjd�dSX|||�d�}	g}
g}x�t|	j|�dd�d�D]x}d	jd
d�|j	D��}
|
r�|j
dkr�|j|kr�tj
d
|j�}|r�|d}
t|
|j�f}t|t�r�||7}q~|
|7}
q~W|�r|�rt|ddd�}tj|�|�r:|
�s0|�r:t|
|��|
�rt|�r^t|
d|�d�dd�}nd|�d�}tj|�dS)a�Validate 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 schema_type: Optional string. One of: cloud-config, network-config
       Default: cloud-config.
    @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.
    @raises: ValueError on invalid schema_type not in cloud-config or
        network_config
    NF)r�z5Ignoring schema validation. jsonschema is not present)Zformat_checkercSs|jS)N)r7)r�rrr"rBIsz-validate_cloudconfig_schema.<locals>.<lambda>)rar�cSsg|]}t|��qSr)r*)r rArrr"r#Ksz/validate_cloudconfig_schema.<locals>.<listcomp>r�z#.*\('(?P<name>.*)' was unexpected\)r+z"Deprecated cloud-config provided:
�
)r>r?zInvalid z provided:
zQ provided: Please run 'sudo cloud-init schema --system' to see the schema errors.T)�
get_schemar�r�rYr��debugrIr�rCr7r�rw�re�matchr8r5r\r4rErrFr�)r`rwr�r�r�r�r�r�r�r�r{r��schema_errorr7Z
prop_match�problemr8Zdetailsrrr"�validate_cloudconfig_schemasZ!










r�c	@s�eZdZeeed�dd�Zeeeeed�dd��Ze	d�dd	�Z
edeeeeeeeeed�dd
��Zeeeeeed�dd�Z
e	e	ed�dd�ZdS)�
_Annotator)�cloudconfig�original_content�schemamarkscCs||_||_||_dS)N)�_cloudconfig�_original_content�_schemamarks)r9r�r�r�rrr"rO|sz_Annotator.__init__)r-r=r6cCsdj|�}d|�d|�d�S)Nr�z# z: -------------
z

)rC)r-r=Zbodyrrr"�
_build_footer�s
z_Annotator._build_footer)r@cCs~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�colrh)	rrJr�r��groups�intryr�r:)r9r@�errors_by_liner7rhr�r�r�rrr"�_build_errors_by_line�sz _Annotator._build_errors_by_liner)rL�labels�footerr��label_prefixr6cCsFx@|D]8}|�|��}|j|�|jd|�d|���|d7}qW|S)Nz# z: �)ry)rLr�r�r�r�r�r�rrr"�
_add_problems�s

z_Annotator._add_problems)�linesr��deprecations_by_liner6cs�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)r9rr"rB�sz._Annotator._annotate_content.<locals>.<lambda>cSst|d�S)Nr�)rQ)r�rrr"rB�s�ErrorsZDeprecations)r�r�ryrCr�rDr�)r9r�r�r��annotated_contentZerror_footerZdeprecation_footerZerror_indexZdeprecation_indexZline_numberr�r{r�r�r)r9r"�_annotate_content�s8
z_Annotator._annotate_content)rGrHr6cCsp|r|r|jS|jjd�}t|jt�sDdj||jddg�g�S|j|�}|j|�}|j|||�}dj|�S)Nr�r�z&# E1: Cloud-config is not a YAML dict.)	r��splitr\r�rvrCr�r�r�)r9rGrHr�r�r�r�rrr"ri�s


z_Annotator.annotateN)r)r'r(r)rvr*rO�staticmethodr
r�rTr�r�r�r�rirrrr"r�{s 
)r�)rGrH)r�r�r�rGrHr6cCst|||�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�ri)r�r�r�rGrHrrr"�annotated_cloudconfig_file�sr�)r=r6cCsfddlm}||krgSg}xDt|j�d�D]2\}}|j|�r,|jtd|�d�|j|d���q,W|S)a�Annotate and return schema validation errors in merged cloud-config.txt

    When merging multiple cloud-config parts cloud-init logs an error and
    ignores any user-data parts which are declared as #cloud-config but
    cannot be processed. the hanlder.cloud_config module also leaves comments
    in the final merged config for every invalid part file which begin with
    MERGED_CONFIG_SCHEMA_ERROR_PREFIX to aid in triage.
    r)�MERGED_PART_SCHEMA_ERROR_PREFIXr�zformat-lz.c1zIgnored invalid user-data: )Zcloudinit.handlers.cloud_configr�r��
splitlines�
startswithryr5�replace)r=r�r{Zline_numr�rrr"�)process_merged_cloud_config_part_problemss

r�)�config_pathr=�instance_data_pathr6cCsddlm}m}m}t|�}d}|dkr�y||||�}Wnd|k
rl}ztt|d�g�|�WYdd}~Xn2|k
r�}ztt|�dd�WYdd}~XnXd	}t|�}|s�|j	d
�\}	}
}
tt|d|�d|	�d
dj
t����g��n|dk�rtd|�d��t
||�S)a
    Return tuple of user-data-type and rendered content.

    When encountering jinja user-data, render said content.

    :return: UserDataTypeAndDecodedContent
    :raises: SchemaValidationError when non-jinja content found but
        header declared ## template: jinja.
    r)�JinjaLoadError�
NotJinjaError�render_jinja_payload_from_filezformat-l1.c1ztext/jinja2zRDetected type '{user_data_type}' from header. But, content is not a jinja templateNT)�sys_exitzformat-l2.c1r�z!Unrecognized user-data header in z: "z%".
Expected first line to be one of: z, ztext/cloud-configzUser-data type 'z.' not currently evaluated by cloud-init schema)Z!cloudinit.handlers.jinja_templater�r�r�rrFr5rr*�	partitionrC�USERDATA_VALID_HEADERS�printr;)r�r=r�r�r�r�Zuser_data_typeZschema_positionr�Zheader_line�_rrr"�&_get_config_type_and_rendered_userdata&s6"$
r�)r�rwr�rir�r6c"Cs�t|dd�}|s$td||f�dS|dkr8t||�}nt|||�}|jdkrRdS|j}t|�}y&|rvtj|�\}	}
ntj	|�}	i}
Wn�t
jk
�r`}z�d}}
d}t|d	�r�t
|d	�r�t
|d	�}nt|d
�r�t
|d
�r�t
|d
�}|�r|jd}|jd}
|jtdj||
d�d
j|t|����t|�}|�rJtti|i|jd��||�WYdd}~XnXt|	t��s�|�s�t|�d|�d���|dk�r�|	jd|	�}|�s�td�dS|jd�dk�r�td|jd����dSy*t|	|ddd��std|�d��dSWn�tk
�r�}zl|j��r*||j7}|�rJtt|	||
||jd��n |j�rjt|jddd�}t|�|�r|t|d�|�WYdd}~XnXdS)a�Validate 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 schema_type: One of network-config or cloud-config.
    @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.

    :return: True when validation was performed successfully
    :raises SchemaValidationError containing any of schema_errors encountered.
    :raises RuntimeError when config_path does not exist.
    T)�decodez,Empty '%s' found at %s. Nothing to validate.F�network-config�text/cloud-configr�NZcontext_markZproblem_markzformat-l{line}.c{col})r�r�zFile {0} is not valid YAML. {1})rGrbz is not a YAML dict.Znetworkz:Skipping network-config schema validation on empty config.r�zJSkipping network-config schema validation. No network schema for version: )r�r�z	Skipping z2 schema validation. Jsonschema dependency missing.)rGrHz"Cloud config schema deprecations: z, )r>r?)r�)r�r�)rr�r;r�r<r=r�rZload_with_marks�load�yamlZ	YAMLErrorrx�getattrr��columnryr5r:r*rFr�rGr\rv�RuntimeErrorrdr�rRrHrE)r�rwr�rir�Zdecoded_contentZdecoded_configr=r{r�Zmarksr�r�r�Zmarkr�Znetcfgr8rrr"�validate_cloudconfig_filecs�








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_order�s
r�ccsBx<|D]4}t|t�r4t|ttf�r4t|�EdHq|VqWdS)N)r\rr*r]�_flatten)Zxs�xrrr"r��s
r�)�
property_dict�	multi_keyr6cCsrg}x`|j|i�D]P}|jt�r"q|jd�rJ|jdd�|jdg�D��q|jd�r|j|d�qWtt|��S)NrrcSs g|]}dtj||��d��qS)z``)�	_YAML_MAPrd)r Z
enum_valuerrr"r#sz,_collect_subschema_types.<locals>.<listcomp>rp)rdr�r�ryrJr�)r�r��property_typesr�rrr"�_collect_subschema_types�s


r)r��defsr6c
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.
    rprrcSs g|]}dtj||��d��qS)z``)rrd)r �krrr"r#sz&_get_property_type.<locals>.<listcomp>r�r�r�r)ra�/�itemsZ	UNDEFINEDz of �(�))�_flatten_schema_refsrdr\rJr�rrz�sortr�rCrQr�_get_property_typery)
r�rrZ
property_typerZsub_property_typesZprune_undefined�sub_itemZsub_typeZsub_property_docrrr"r	s>







 
rcCs>|}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.r>Zlist_paragraphrrr"�_parse_description5sr)�src_cfgrcCsd|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/rrr�r��allOfN)�popr��updaterrd)rrZ	reference�
sub_schemarrr"r	Ks&

r	)rcCs0|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.
    rN)rr)rZsub_schemasrrrr"�_flatten_schema_all_ofes

r)�prop_configr6cCs�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 ":".
    )r`�descriptions�deprecated_descriptionscSs<tt|jd��r |jt|��n|jd�r8|jt|��dS)N�deprecated_version�changed_version�new_versionr.)rrr)�anyrDrdryro)r`rrrrr"�assign_descriptions}s
z6_get_property_description.<locals>.assign_descriptionsr�r�z. rb)rvrJrdrrC)rrr�r�rrrr.rrr"�_get_property_descriptionrs
r�   )rwrr6c
s�|d}g}�jd�dkrdS�fdd�dD�}�fd	d�|D�}�x\|D�]R}�xJ|j�D�]<\}}	t|	|�t|	�|	jd�dkr�q\t|	�}
|	jd
|�}|jtj||t|
|d�t	|	|�d��|	jd�}|�rtt||�|jd�s�|jd��r|jt
j||d
��|jt|||d��xV|jdg�D]F}
|
jd��sF|
jd��r*|jt
j||d
��|jt|
||d���q*Wd|	k�s�d|	kr\|jt|	||d��q\WqJWdj|�S)zDReturn restructured text describing the supported schema properties.z  �hiddenTrcs$g|]}d�ks|�dkr|�qS)rr)r ra)rwrr"r#�sz%_get_property_doc.<locals>.<listcomp>rq�patternPropertiescsg|]}�j|i��qSr)rd)r ra)rwrr"r#�sr�)r>�	prop_namer.Z	prop_typer)r>r!)rr>r�z

)rqr )
rdrr	rrry�SCHEMA_PROPERTY_TMPLr:rr�SCHEMA_LIST_ITEM_TMPL�_get_property_docrC)rwrr>Z
new_prefixrqZ
property_keysZproperty_schemasZprop_schemaZprop_keyrr.r�rZ
alt_schemar)rwr"r$�sZ




r$)�metar6cCsb|jd�}|sdSt}xFt|d�D]8\}}|tj|d�7}tj|d�jd�}|dj|�7}q"W|S)zAReturn restructured text describing the meta examples if present.r1rr�)Z
example_countz   r�)	rd�SCHEMA_EXAMPLES_HEADERr��SCHEMA_EXAMPLES_SPACER_TEMPLATEr:�textwrap�indentr�rC)r%r1Zrst_content�countZexampleZindented_linesrrr"�
_get_examples�s

r+cCs2|jd�sdSdjdd�|dD��}d|�d�S)Nr3rz, css|]}d|�d�VqdS)z``Nr)r rrrr"r��sz3_get_activate_by_schema_keys_doc.<locals>.<genexpr>z**Activate only on keys:** z

)rdrC)r%Zschema_keysrrr"� _get_activate_by_schema_keys_doc�s

r,)r%rwr6c	
Cs�|dkrtdd�}|s|r&td��t|j��}ddddd	d
dh}dh}d
}||rfdj||�}n|||r�dj||�}|r�t|��tt|��}d
|d<d|d<d|d<tj	t
t|d
�d�|d
<|jdi�}|j|d�r�|j|di�}t
t|�}t
|dj���rPyt||dd�|d<Wn(tk
�rNtjd�d
|d<YnX|jdd
��sfd|d<tj	t|�d�|d<|d�s�d|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cloud-config)r�z"Expected non-empty meta and schemar,r-r1r2r0r.r+r3rz(Missing required keys in module meta: {}z3Additional unexpected keys found in module meta: {}Zproperty_headerz      Zprefix6z   Zprefix3z$defsrq)rr>Zproperty_docz3Unable to render property_doc due to invalid schemaz+      No schema definitions for this modulez$         No examples for this modulez, r��-Ztitle_underbar)r��
ValueErrorrK�keysr:�KeyErrorrvrr(r)rr*rdr�valuesr$�AttributeErrorr�r�r+rCr�r
r,�SCHEMA_DOC_TMPL)	r%rwr/Z
required_keysZ
optional_keysZ
error_messageZ	meta_copyr�templaterrr"�get_meta_doc�sd





r5cCstjjtjjt��}t|�S)N)�osr7�dirname�abspath�__file__r)Zconfigs_dirrrr"�get_modulesDsr:)�requested_modulesr6cCs�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)r�zcloudinit.configr%r)rJr:r1rK�
differencerr:rCr�find_module�
import_modulerS)r;�docsZall_modulesZinvalid_docsZmod_nameZmod_locsr��modrrr"�load_docIs"

rBcCstjjtjjtjjt��d�S)NZschemas)r6r7rCr7r8r9rrrr"�get_schema_dirdsrC)r�r6cCsZtjjt�t|d�}d}ytjt|��}Wn&tt	fk
rTt
jd||�iSX|S)ziReturn jsonschema for a specific type.

    Return empty schema when no specific schema file exists.
    rNz;Skipping %s schema valiation. No JSON schema file found %s.)r6r7rCrC�SCHEMA_FILES_BY_TYPE�json�loadsr�IOError�OSErrorr�r�)r�Zschema_file�full_schemarrr"r�hsr�cCs�|stjddd�}|jdddd�|jdd	td
dgdd
�|jddtdt�jd���d�|jddddd�|jddddd�|jddddd�|S)z0Return a parser for supported cmdline arguments.zcloudconfig-schemaz�Schema validation and documentation of instance-data configuration provided to cloud-init. This includes: user-data, vendor-data and network-config)�progr.z-cz
--config-filez@Path of the cloud-config or network-config YAML file to validate)�helpz-tz
--schema-typezcloud-configznetwork-configz_When providing --config-file, the schema type to validate config against. Default: cloud-config)rp�choicesrKz-iz--instance-datazbPath to instance-data.json file for variable expansion of '##template: jinja' user-data. Default: �
instance_data)rprKz--system�
store_trueFzVValidate the system instance-data provided as vendor-data user-data and network-config)�action�defaultrKz-dz--docs�+zCPrint schema module docs. Choices: all or space-delimited cc_names.)�nargsrKz
--annotatez;Annotate existing instance-data files any discovered errors)�argparse�ArgumentParser�add_argumentr*r�get_runpath)�parserrrr"�
get_parser}sFrXc)CsJ|j|j|jg}tdd�|D��dkr2tddd�t|j|jg�rP|jrPtd�|jrh|jrhtddd�t	d	d
�}|jr�tt
|j��dSytdd
�}Wnftt
fk
r�}z$|jtkr�tjd�t�}n�WYdd}~Xn$tk
r�t�}tjd�YnX|j�r|j}n$tj�dk�r*|jd�}n
|jd�}|j�rL|j|jff}n�tj�dk�rftddd�|jd�}|�s�tddd�dSy2tj|�jdk�r�|jd�}	tj|	�j�r�|	}Wntk
�r�YnXd|ff}d|jd�fd|jd�fd|jd�ff}
x4|
D],\}}|�rtjj|��r|||ff7}�qWtjj|dd��sltd|dd�d�d dd!�d"}
tt|�dk�}|�r�td#d$jd%d&�|D���d'}
g}�xtt |d�D�]d\}\}}d(}|�r�td)|�d*|�d+|�d,��|dk�rt	|�}|}n|}|d	k�rdn|}d	}yt!||||j|�}Wn�t"k
�r�}zN|�sRd-}|j�s�t|
�d.|�d/|���tt#|�|
d0d1�|j$|�WYdd}~Xn|t%k
�r�}z6t|
�d.|���tt#|�|
d0d1�|j$|�WYdd}~Xn*X|�r�|j�r|n|}t|
�d2|����q�W|�rFtd$jd3d&�|D��d4dd!�dS)5z@Handle provided schema args and perform the appropriate actions.cSsg|]}|r|�qSrr)r �argrrr"r#�sz&handle_schema_args.<locals>.<listcomp>r�z;Expected one of --config-file, --system or --docs argumentsT)r�z[WARNING: The --schema-type parameter is inapplicable when either --system or --docs presentz;Invalid flag combination. Cannot use --annotate with --docszcloud-config)r�NZtrust)Zfetch_existing_datasourcez=Using default instance-data/user-data paths for non-root userzEdatasource not detected, using default instance-data/user-data paths.rrMZinstance_data_sensitivezNUnable 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 availableZuserdata_rawz	user-datazvendor-dataZvendor_cloud_configzvendor2-dataZvendor2_cloud_configznetwork-configZnetwork_configzConfig file z does not existz	Error: {})�fmtr�rz!Found cloud-config data types: %sz, css|]\}}|VqdS)Nr)r �cfg_typer�rrr"r�sz%handle_schema_args.<locals>.<genexpr>z  Fr�z. z at �:ZUNKNOWN_CONFIG_HEADERzInvalid rbz
Error: {}
)rZz
Valid schema css|]
}|VqdS)Nr)r r~rrr"r�HszError: Invalid schema: {}
)&Zconfig_filer@�systemrzrrr�r�rir�rBrrGrH�errnorr�r�rr�rMr6�getuidrVZ	get_ipath�stat�st_size�FileNotFoundErrorr7�existsrQrCr�r�rFr*ryr�)r+�argsZexclusive_argsrI�pathsr�r�Zconfig_filesZ
userdata_fileZraw_userdata_fileZsupplemental_config_filesr[Zcfg_fileZnested_output_prefixZmulti_config_outputZerror_types�idxZperformed_schema_validationZ
cfg_schemar�Zcfgrrr"�handle_schema_args�s�







rgcCst�}td|j��dS)zDTool to validate schema of a cloud-config file or print schema docs.zcloudconfig-schemar)rXrg�
parse_args)rWrrr"�mainNsri�__main__)FN)T)Nr�FFTF)N)r�FN)r)N)r�)N)xrSrSrEZloggingr6r��sysr(�collectionsr�collections.abcr�copyrr^r�	functoolsr�	itertoolsrr/rr	r
rrr
rrr�Z	cloudinitrrZcloudinit.cmd.develrZcloudinit.handlersrrZcloudinit.sourcesrZcloudinit.utilrrrrXrZ_ValidationErrorrY�	ExceptionZ	getLoggerr'r�ZVERSIONED_USERDATA_SCHEMA_FILEZUSERDATA_SCHEMA_FILEZNETWORK_CONFIG_V1_SCHEMA_FILErDrr3ZSCHEMA_PROPERTY_HEADERr"r#r&r'r�ZDEPRECATED_PREFIXrIr/r�Ztyping_extensionsr$r%r&rvr4r5rTr;r*rEr.rFr_ror}rQrr�r�r�r�r�r�r�r�r]r�r�r�r�r�r�rrrr	rrr$r+r,r5r:rJrBrCr�rXrgri�exitrrrr"�<module>s�(

)!'C%L% ]z<z
,
*F	J
A


Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 128 B 0644
__init__.cpython-36.pyc File 128 B 0644
cc_ansible.cpython-36.opt-1.pyc File 8.63 KB 0644
cc_ansible.cpython-36.pyc File 8.63 KB 0644
cc_apk_configure.cpython-36.opt-1.pyc File 4.51 KB 0644
cc_apk_configure.cpython-36.pyc File 4.51 KB 0644
cc_apt_configure.cpython-36.opt-1.pyc File 30.42 KB 0644
cc_apt_configure.cpython-36.pyc File 30.42 KB 0644
cc_apt_pipelining.cpython-36.opt-1.pyc File 2.44 KB 0644
cc_apt_pipelining.cpython-36.pyc File 2.44 KB 0644
cc_bootcmd.cpython-36.opt-1.pyc File 2.51 KB 0644
cc_bootcmd.cpython-36.pyc File 2.51 KB 0644
cc_byobu.cpython-36.opt-1.pyc File 3.04 KB 0644
cc_byobu.cpython-36.pyc File 3.04 KB 0644
cc_ca_certs.cpython-36.opt-1.pyc File 7.05 KB 0644
cc_ca_certs.cpython-36.pyc File 7.05 KB 0644
cc_chef.cpython-36.opt-1.pyc File 9.13 KB 0644
cc_chef.cpython-36.pyc File 9.13 KB 0644
cc_disable_ec2_metadata.cpython-36.opt-1.pyc File 1.72 KB 0644
cc_disable_ec2_metadata.cpython-36.pyc File 1.72 KB 0644
cc_disk_setup.cpython-36.opt-1.pyc File 23.1 KB 0644
cc_disk_setup.cpython-36.pyc File 23.1 KB 0644
cc_fan.cpython-36.opt-1.pyc File 2.74 KB 0644
cc_fan.cpython-36.pyc File 2.74 KB 0644
cc_final_message.cpython-36.opt-1.pyc File 3.07 KB 0644
cc_final_message.cpython-36.pyc File 3.07 KB 0644
cc_growpart.cpython-36.opt-1.pyc File 15.91 KB 0644
cc_growpart.cpython-36.pyc File 15.91 KB 0644
cc_grub_dpkg.cpython-36.opt-1.pyc File 4.92 KB 0644
cc_grub_dpkg.cpython-36.pyc File 4.92 KB 0644
cc_install_hotplug.cpython-36.opt-1.pyc File 3.25 KB 0644
cc_install_hotplug.cpython-36.pyc File 3.25 KB 0644
cc_keyboard.cpython-36.opt-1.pyc File 1.98 KB 0644
cc_keyboard.cpython-36.pyc File 1.98 KB 0644
cc_keys_to_console.cpython-36.opt-1.pyc File 3.11 KB 0644
cc_keys_to_console.cpython-36.pyc File 3.11 KB 0644
cc_landscape.cpython-36.opt-1.pyc File 4.71 KB 0644
cc_landscape.cpython-36.pyc File 4.71 KB 0644
cc_locale.cpython-36.opt-1.pyc File 1.58 KB 0644
cc_locale.cpython-36.pyc File 1.58 KB 0644
cc_lxd.cpython-36.opt-1.pyc File 13.04 KB 0644
cc_lxd.cpython-36.pyc File 13.04 KB 0644
cc_mcollective.cpython-36.opt-1.pyc File 4.24 KB 0644
cc_mcollective.cpython-36.pyc File 4.24 KB 0644
cc_migrator.cpython-36.opt-1.pyc File 2.92 KB 0644
cc_migrator.cpython-36.pyc File 2.92 KB 0644
cc_mounts.cpython-36.opt-1.pyc File 14.08 KB 0644
cc_mounts.cpython-36.pyc File 14.08 KB 0644
cc_ntp.cpython-36.opt-1.pyc File 13.15 KB 0644
cc_ntp.cpython-36.pyc File 13.15 KB 0644
cc_package_update_upgrade_install.cpython-36.opt-1.pyc File 3.78 KB 0644
cc_package_update_upgrade_install.cpython-36.pyc File 3.78 KB 0644
cc_phone_home.cpython-36.opt-1.pyc File 4.1 KB 0644
cc_phone_home.cpython-36.pyc File 4.1 KB 0644
cc_power_state_change.cpython-36.opt-1.pyc File 6.24 KB 0644
cc_power_state_change.cpython-36.pyc File 6.24 KB 0644
cc_puppet.cpython-36.opt-1.pyc File 9.46 KB 0644
cc_puppet.cpython-36.pyc File 9.46 KB 0644
cc_reset_rmc.cpython-36.opt-1.pyc File 3.59 KB 0644
cc_reset_rmc.cpython-36.pyc File 3.59 KB 0644
cc_resizefs.cpython-36.opt-1.pyc File 7.02 KB 0644
cc_resizefs.cpython-36.pyc File 7.02 KB 0644
cc_resolv_conf.cpython-36.opt-1.pyc File 4.27 KB 0644
cc_resolv_conf.cpython-36.pyc File 4.27 KB 0644
cc_rh_subscription.cpython-36.opt-1.pyc File 12.06 KB 0644
cc_rh_subscription.cpython-36.pyc File 12.06 KB 0644
cc_rightscale_userdata.cpython-36.opt-1.pyc File 2.77 KB 0644
cc_rightscale_userdata.cpython-36.pyc File 2.77 KB 0644
cc_rsyslog.cpython-36.opt-1.pyc File 10.34 KB 0644
cc_rsyslog.cpython-36.pyc File 10.34 KB 0644
cc_runcmd.cpython-36.opt-1.pyc File 2.43 KB 0644
cc_runcmd.cpython-36.pyc File 2.43 KB 0644
cc_salt_minion.cpython-36.opt-1.pyc File 4.36 KB 0644
cc_salt_minion.cpython-36.pyc File 4.36 KB 0644
cc_scripts_per_boot.cpython-36.opt-1.pyc File 1.4 KB 0644
cc_scripts_per_boot.cpython-36.pyc File 1.4 KB 0644
cc_scripts_per_instance.cpython-36.opt-1.pyc File 1.57 KB 0644
cc_scripts_per_instance.cpython-36.pyc File 1.57 KB 0644
cc_scripts_per_once.cpython-36.opt-1.pyc File 1.51 KB 0644
cc_scripts_per_once.cpython-36.pyc File 1.51 KB 0644
cc_scripts_user.cpython-36.opt-1.pyc File 1.58 KB 0644
cc_scripts_user.cpython-36.pyc File 1.58 KB 0644
cc_scripts_vendor.cpython-36.opt-1.pyc File 2.04 KB 0644
cc_scripts_vendor.cpython-36.pyc File 2.04 KB 0644
cc_seed_random.cpython-36.opt-1.pyc File 4.07 KB 0644
cc_seed_random.cpython-36.pyc File 4.07 KB 0644
cc_set_hostname.cpython-36.opt-1.pyc File 4 KB 0644
cc_set_hostname.cpython-36.pyc File 4 KB 0644
cc_set_passwords.cpython-36.opt-1.pyc File 8.4 KB 0644
cc_set_passwords.cpython-36.pyc File 8.4 KB 0644
cc_snap.cpython-36.opt-1.pyc File 5.94 KB 0644
cc_snap.cpython-36.pyc File 5.94 KB 0644
cc_spacewalk.cpython-36.opt-1.pyc File 2.87 KB 0644
cc_spacewalk.cpython-36.pyc File 2.87 KB 0644
cc_ssh.cpython-36.opt-1.pyc File 11.02 KB 0644
cc_ssh.cpython-36.pyc File 11.02 KB 0644
cc_ssh_authkey_fingerprints.cpython-36.opt-1.pyc File 3.54 KB 0644
cc_ssh_authkey_fingerprints.cpython-36.pyc File 3.54 KB 0644
cc_ssh_import_id.cpython-36.opt-1.pyc File 3.85 KB 0644
cc_ssh_import_id.cpython-36.pyc File 3.85 KB 0644
cc_timezone.cpython-36.opt-1.pyc File 1.24 KB 0644
cc_timezone.cpython-36.pyc File 1.24 KB 0644
cc_ubuntu_advantage.cpython-36.opt-1.pyc File 12.42 KB 0644
cc_ubuntu_advantage.cpython-36.pyc File 12.42 KB 0644
cc_ubuntu_autoinstall.cpython-36.opt-1.pyc File 3.89 KB 0644
cc_ubuntu_autoinstall.cpython-36.pyc File 3.89 KB 0644
cc_ubuntu_drivers.cpython-36.opt-1.pyc File 3.63 KB 0644
cc_ubuntu_drivers.cpython-36.pyc File 3.63 KB 0644
cc_update_etc_hosts.cpython-36.opt-1.pyc File 4.3 KB 0644
cc_update_etc_hosts.cpython-36.pyc File 4.3 KB 0644
cc_update_hostname.cpython-36.opt-1.pyc File 3.01 KB 0644
cc_update_hostname.cpython-36.pyc File 3.01 KB 0644
cc_users_groups.cpython-36.opt-1.pyc File 7.58 KB 0644
cc_users_groups.cpython-36.pyc File 7.58 KB 0644
cc_wireguard.cpython-36.opt-1.pyc File 8.39 KB 0644
cc_wireguard.cpython-36.pyc File 8.39 KB 0644
cc_write_files.cpython-36.opt-1.pyc File 5.61 KB 0644
cc_write_files.cpython-36.pyc File 5.61 KB 0644
cc_write_files_deferred.cpython-36.opt-1.pyc File 1.73 KB 0644
cc_write_files_deferred.cpython-36.pyc File 1.73 KB 0644
cc_yum_add_repo.cpython-36.opt-1.pyc File 6.03 KB 0644
cc_yum_add_repo.cpython-36.pyc File 6.03 KB 0644
cc_zypper_add_repo.cpython-36.opt-1.pyc File 5.66 KB 0644
cc_zypper_add_repo.cpython-36.pyc File 5.66 KB 0644
modules.cpython-36.opt-1.pyc File 7.31 KB 0644
modules.cpython-36.pyc File 7.31 KB 0644
schema.cpython-36.opt-1.pyc File 39.45 KB 0644
schema.cpython-36.pyc File 39.45 KB 0644