403Webshell
Server IP : 3.96.16.70  /  Your IP : 216.73.216.15
Web Server : Apache
System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3.9/site-packages/cloudinit/config/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.9/site-packages/cloudinit/config/__pycache__/schema.cpython-39.pyc
a

�½bGo�@sFdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlZddlmZmZddlmZddlmZmZmZe
ed	d
�Ze�e�ZdZdZd
ddd�ZdZdZdZ dZ!dZ"dZ#dZ$ej%dkr�Gdd�dej&�Z'ne(Z'Gdd�de)�Z*dd�Z+dd �Z,dSe(d!�d"d#�Z-dTe(e(e.e.e.d%�d&d'�Z/d(d)�Z0dUd*d+�Z1d,d-�Z2e(e(e3d.�d/d0�Z4e3d1�d2d3�Z5e(e(d4�d5d6�Z6dVe(e(e3d8�d9d:�Z7e'e3d;�d<d=�Z8dWe'e(e3d>�d?d@�Z9e(d1�dAdB�Z:e;e3dC�dDdE�Z<e3d1�dFdG�Z=e(d1�dHdI�Z>e(d1�dJdK�Z?dXdLdM�Z@dNdO�ZAdPdQ�ZBedRk�rBe�CeB��dS)YzFschema.py: Set of module functions for processing cloud-config schema.�N)�defaultdict)�deepcopy)�partial)�importer�safeyaml)�read_cfg_paths)�error�find_modules�	load_fileT)Zsys_exitz!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}

{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} ---)��c@sReZdZUeed<eed<eed<eed<ejeed<ejeed<eed<dS)	�
MetaSchema�name�id�title�description�distros�examples�	frequencyN)�__name__�
__module__�__qualname__�str�__annotations__�typing�List�rr�;/usr/lib/python3.9/site-packages/cloudinit/config/schema.pyr>s
rcs"eZdZdZd�fdd�	Z�ZS)�SchemaValidationErrorz<Raised when validating a cloud-config file against a schema.rcs8||_dd�|D�}d�d�|��}tt|��|�dS)z�Init the exception an n-tuple of schema errors.

        @param schema_errors: An n-tuple of the format:
            ((flat.config.key, msg),)
        cSsg|]\}}d�||��qS�z{0}: {1}��format)�.0Z
config_key�messagerrr�
<listcomp>Vs�z2SchemaValidationError.__init__.<locals>.<listcomp>zCloud config schema errors: {0}�, N)�
schema_errorsr"�join�superr�__init__)�selfr'Zerror_messagesr$��	__class__rrr*Os��zSchemaValidationError.__init__)r)rrr�__doc__r*�
__classcell__rrr,rrLsrcCs@zddlm}Wnty$YdS0|j�|d�p>t|tf�S)zWTYPE_CHECKER override allowing bytes for string type

    For jsonschema v. 3.0.0+
    r)�Draft4ValidatorF�string)�
jsonschemar0�ImportError�TYPE_CHECKERZis_type�
isinstance�bytes)Zchecker�instancer0rrr�is_schema_byte_string`s�
�r8cCs�ddlm}m}ddlm}t|j�}d|d<ddi|dd	<t|d
�rj|j�	dt
�}|||jd|d�}n$|j}t
tf|d<|||jd|d
�}||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)r0�
FormatChecker)�createFZadditionalProperties�typer1�
properties�labelr4Zdraft4)�meta_schema�
validators�version�type_checker)r>r?r@Z
default_types)r2r0r9Zjsonschema.validatorsr:rZMETA_SCHEMA�hasattrr4Zredefiner8Z
VALIDATORSZ
DEFAULT_TYPESrr6)r0r9r:�strict_metaschemarA�cloudinitValidator�typesrrr�get_jsonschema_validatorns0

���rF��schemac
Cszddlm}z|�|�WnZ|yt}zB|rTtd�dd�|jD��|jffd�|�t�d|�WYd}~n
d}~00dS)	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#�prrrr%��z3validate_cloudconfig_metaschema.<locals>.<listcomp>)r'zGMeta-schema validation failed, attempting to validate config anyway: %sN)	Zjsonschema.exceptionsrIZcheck_schemarr(�pathr$�LOG�warning)�	validatorrH�throwrI�errrrr�validate_cloudconfig_metaschema�s
����rUF)�configrH�strictrC�log_detailsc
Cs�|durt�}z t�\}}|r,t||dd�WntyLt�d�YdS0|||�d�}d}t|�|�dd�d	�D]*}	d
�dd�|	j	D��}
||
|	j
ff7}qv|r�|r�t|��|r�d
d�|D�}dd�|�}nd}t�d|�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 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.

    @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)rSz5Ignoring schema validation. jsonschema is not present)Zformat_checkerrcSs|jS�N)rO)�errr�<lambda>�rNz-validate_cloudconfig_schema.<locals>.<lambda>��keyrJcSsg|]}t|��qSrrKrLrrrr%�rNz/validate_cloudconfig_schema.<locals>.<listcomp>cSsg|]\}}d�||��qSr r!)r#�k�msgrrrr%�rN�
zFPlease run 'sudo cloud-init schema --system' to see the schema errors.z!Invalid cloud-config provided: %s)
�
get_schemarFrUr3rP�debug�sortedZiter_errorsr(rOr$rrQ)
rVrHrWrCrXrDr9rR�errorsrrOZmessages�detailsrrr�validate_cloudconfig_schema�s2
�

�rfcCsX|s|Stt�}g}d}g}|���d�}t|t�sJd�||�d�g�S|D]f\}	}
t�	d|	�}|r�|�
�\}}
|t|��|
�nd}
|||	�|
�|
durNdj||
|
d�}
qNd}t
|d�D]r\}}||}|�r,g}|D].}|�d	�|��|�d
�||��|d7}q�|�|dd�|��q�|�|�q�|�|�d�|���d�|�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 schema_errors: List of tuples from a JSONSchemaValidationError. The
        tuples consist of (schemapath, error_message).
    z# Errors: -------------
{0}

r`z&# E1: Cloud-config is not a YAML dict.z&format-l(?P<line>\d+)\.c(?P<col>\d+).*NzLine {line} column {col}: {msg})�line�colr_�zE{0}z# E{0}: {1}z		# �,)r�list�decode�splitr5�dictr(r"�re�match�groups�int�append�	enumerate)�cloudconfigZoriginal_contentr'ZschemamarksZerrors_by_lineZerror_footerZerror_headerZannotated_content�linesrOr_rprgrhZerror_indexZline_numberrdZerror_labelrrrr�annotated_cloudconfig_file�sJ

���
rwc
Cs|dur:t��dkrtd��t�}|�d�}t|dd�}n&tj�|�sTtd�|���t|dd�}|�	t
�s�dd	�|t
���ff}t|�}|r�t
ti||ji��|�z&|r�t�|�\}}	nt�|�}i}	Wn�tj�y�}
z�d
}}d}
t|
d��rt|
d��rt|
d�}
n"t|
d��r0t|
d��r0t|
d�}
|
�rJ|
jd
}|
jd
}d
j||d�d�|t|
��ff}t|�}|�r�t
ti||ji��||
�WYd}
~
n
d}
~
00t|t��s�|�s�td��zt||dd�WnBt�y}
z(|�rt
t|||
j|	���WYd}
~
n
d}
~
00dS)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 sudoZuserdata_rawF)rlzConfigfile {0} does not existzformat-l1.c1z"File {0} needs to begin with "{1}"riZcontext_markZproblem_markzformat-l{line}.c{col})rgrhzFile {0} is not valid yaml. {1}z Cloud-config is not a YAML dict.T)rW)�os�getuid�RuntimeErrorrZ
get_ipath_curr
rO�existsr"�
startswith�CLOUD_CONFIG_HEADERrlr�printrwr'rZload_with_marks�load�yamlZ	YAMLErrorrB�getattrrg�columnrr5rnrf)Zconfig_pathrH�annotate�pathsZuser_data_fileZcontentrdrruZmarksrZrgr�Zmarkrrr�validate_cloudconfig_file1s��
�
���
��



��
��
��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��objectrirr)�valuerrr�_sort_property_order�s
r�)�
property_dict�defs�returncCs:t||�|�dg�}t|t�s&|g}|�d�rDdd�|dD�}n$|�d�rh|�dd�|�d�D��t|�dkr~|d}n|jtd	�d
�|�}|�di�}|�dg�}t|t�s�|g}|�di�D]}|�	t
||��q�|�r0t|�dk�r|�d|d��S|jtd	�d
d
�|��d�}|�d|��S|�p8dS)zNReturn a string representing a property type from a given
    jsonschema.
    r;�enumcSs g|]}dt�||��d��qS)z``)�	_YAML_MAP�get)r#r^rrrr%�sz&_get_property_type.<locals>.<listcomp>�oneOfcSsg|]}|�d�r|d�qS)r;�r�)r#Z	subschemarrrr%�s
�rirr\�/�itemsz of �(�)Z	UNDEFINED)�_flatten_schema_refsr�r5rk�extend�len�sortr�r(rs�_get_property_type)r�r�Zproperty_typesZ
property_typer�Zsub_property_typesZsub_itemZsub_property_docrrrr��s>


�
��


r�)r�cCsB|d}t�dd|�}t�dd�|�|�}t�dd�|�|�}|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
    rz
(\S)\n(\S)z\1 \2z\n\nz\n\n{}z\n( +)-z\n{}-)ro�subr")r�prefixZlist_paragraphrrr�_parse_description�s�r�)�src_cfgr�cCs�d|vr(|�d��dd�}|�||�d|vr�d|dvrd|d�d��dd�}|d�||�d|dvr�|ddD],}d|vr||�d��dd�}|�||�q||�dg�D],}d|vr�|�d��dd�}|�||�q�dS)zEFlatten schema: replace $refs in src_cfg with definitions from $defs.z$refz#/$defs/�r�r�N)�pop�replace�updater�)r�r�Z	reference�
alt_schemarrrr��s r��    )rHr�r�cs�|d}g}��d�durdS�fdd�dD�}�fdd�|D�}|D�]\}|��D�]L\}}	t|	|�|	�d�durxqT|	�d	d�}
|
r�d
|
}
|	�d|�}|�tj||t|
|�t|	|�d��|	�d
�}|�r|t||�|�d�s�|�d��r |�tj||d��|d7}|�t	|||d��|�dg�D]N}
|
�d��sH|
�d��r,|�tj||d��|d7}|�t	|
||d���q,d|	v�s�d|	vrT|�t	|	||d��qTqFd�
|�S)zDReturn restructured text describing the supported schema properties.r��hiddenTr�cs$g|]}d�vs|�dvr|�qS)r�r�r#r]rGrrr%�s�z%_get_property_doc.<locals>.<listcomp>)r<�patternPropertiescsg|]}��|i��qSrr�r�rGrrr%�rNr� r=)r��	prop_namerZ	prop_typer�r<r�)r�r�)r�r�r�z

)r�r�r�rs�SCHEMA_PROPERTY_TMPLr"r�r��SCHEMA_LIST_ITEM_TMPL�_get_property_docr()rHr�r��
new_prefixr<Z
property_keysZproperty_schemasZprop_schemaZprop_keyZprop_configrr=r�r�rrGrr��s~
�

��

������������r�)�metar�cCsp|�d�}|sdSt}t|�D]L\}}|�d�}dd�|D�}|tkr\|�dt�|d��|d�|�7}q|S)zAReturn restructured text describing the meta examples if present.rr�r`cSsg|]}d�|��qS)z    {0}r!)r#rgrrrr%@rNz!_get_examples.<locals>.<listcomp>rri)r��SCHEMA_EXAMPLES_HEADERrtrm�insert�SCHEMA_EXAMPLES_SPACER_TEMPLATEr"r()r�rZrst_content�countZexamplervZindented_linesrrr�
_get_examples7s

�r�)r�rHr�cCsB|durt�}|r|std��t|���}thd��}d}||rRd�||�}n||rhd�||�}|rtt|��tt|��}d|d<|�di�}|�|d	�r�|�|d	�}zt	||d
�|d<Wn$t
y�t�d�d|d<Yn0|dr�t
|d<t|�|d
<d�|d�|d<t�dd|d�|d<tjfi|��}|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>rrrrrrrr�z(Missing expected keys in module meta: {}z3Additional unexpected keys found in module meta: {}Zproperty_header�$defsr)r�Zproperty_docz3Unable to render property_doc due to invalid schemarr&rrJ�-rZtitle_underbar)ra�
ValueError�set�keysr"�KeyErrorrnrr�r��AttributeErrorrPrQ�SCHEMA_PROPERTY_HEADERr�r(ror��SCHEMA_DOC_TMPL)r�rHr�ZexpectedZ
error_messageZ	meta_copyr��templaterrr�get_meta_docIsJ����
r�cCstj�tj�t��}t|�SrY)rxrO�dirname�abspath�__file__r	)Zconfigs_dirrrr�get_modules�sr�)�requested_modulesr�cCs�d}tt����dg}t|��t|��}|rHtd�t|�d�|���|D]J}d|vs`||vrLt�	|dgdg�\}}|rLt�
|d�}||jp�d7}qL|S)zaLoad module docstrings

    Docstrings are generated on module load. Reduce, reuse, recycle.
    r��allz+Invalid --docs value {}. Must be one of: {}r&�cloudinit.configr�r)rkr��valuesr��
differencerr"r(r�find_module�
import_moduler.)r��docsZall_modulesZinvalid_docs�mod_name�mod_locs�_�modrrr�load_doc�s&��
�r�cCstj�tj�tj�t��d�S)NZschemas)rxrOr(r�r�r�rrrr�get_schema_dir�sr�c
Csztj�t�t�}d}zt�t|��}Wn2tyX}zt	�
d||�WYd}~n
d}~00|svt	�
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$schemaZallOf)rxrOr(r��USERDATA_SCHEMA_FILE�json�loadsr
�	ExceptionrPrQ)Zschema_file�full_schemarZrrrra�s $��racCsVt�}t���D]@\}}t�|dgdg�\}}|rt�|d�}|j||jd<q|S)z<Return metadata coalesced from all cc_* cloud-config module.r�r�rr)rnr�r�rr�r�r�)Z	full_metar�r�r�r�rrr�get_meta�s
�r�cCs\|stjddd�}|jdddd�|jdd	d
dd�|jd
dddd�|jdd	d
dd�|S)z0Return a parser for supported cmdline arguments.�cloudconfig-schemaz.Validate cloud-config files or document schema)�progrz-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��parserrrr�
get_parser�s:����	�r�c
Cs
|j|j|jg}tdd�|D��dkr.td�|jrB|jrBtd�t�}|jsT|jr�zt|j||j�Wndty�}z|js�tt	|��WYd}~nXd}~0t
y�}ztt	|��WYd}~n*d}~00|jdur�d}n|j}td|�n|j�rtt|j��dS)	z@Handle provided schema args and perform the appropriate actions.cSsg|]}|r|�qSrr)r#�argrrrr%�rNz&handle_schema_args.<locals>.<listcomp>riz;Expected one of --config-file, --system or --docs argumentsz;Invalid flag combination. Cannot use --annotate with --docsNzsystem userdatazValid cloud-config:)
Zconfig_filer��systemr�rr�rar�rrrzr~r�)r�argsZexclusive_argsr�rZZcfg_namerrr�handle_schema_args�s,
� "
r�cCst�}td|���dS)zDTool to validate schema of a cloud-config file or print schema docs.r�r)r�r��
parse_argsr�rrr�mainsr��__main__)T)NFFT)F)r�)N)N)Dr.r�r�Zloggingrxro�sysr�collectionsr�copyr�	functoolsrr�Z	cloudinitrrZcloudinit.cmd.develrZcloudinit.utilrr	r
Z	getLoggerrrPZVERSIONED_USERDATA_SCHEMA_FILEr�r�r}r�r�r�r�r�r��version_info�	TypedDictrrnr�rr8rFrU�boolrfrwr�r�rr�r�r�r�r�r�r�rkr�r�rar�r�r�r��exitrrrr�<module>s�
�

3#��:5
[
)I;
$


Youez - 2016 - github.com/yon3zu
LinuXploit