403Webshell
Server IP : 23.254.227.96  /  Your IP : 216.73.216.7
Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64
User : viralblo ( 1001)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3.6/site-packages/cloudinit/config/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.6/site-packages/cloudinit/config/__pycache__/schema.cpython-36.opt-1.pyc
3

��b�k�@s�dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
Z
ddlmZddlmZddlmZdd	lmZmZmZeed
d�Zeje�Zdd
dd�ZdZdZdZdZdZ dZ!Gdd�de"�Z#dd�Z$dd�Z%dIe&d�dd�Z'dJe&e&e(e(d �d!d"�Z)d#d$�Z*dKd%d&�Z+d'd(�Z,e&e-d)�d*d+�Z.e-d,�d-d.�Z/dLe&e&e-d0�d1d2�Z0ee-d3�d4d5�Z1dMee&e-d6�d7d8�Z2e&d,�d9d:�Z3e4e-d;�d<d=�Z5e&d,�d>d?�Z6e&d,�d@dA�Z7dNdBdC�Z8dDdE�Z9dFdG�Z:edHk�r�ej;e:��dS)OzFschema.py: Set of module functions for processing cloud-config schema.�N)�defaultdict)�deepcopy)�partial)�importer)�read_cfg_paths)�
MetaSchema)�error�find_modules�	load_fileT)Zsys_exit�trueZfalseZnull)TFNs
#cloud-configz�
{name}
{title_underbar}
**Summary:** {title}

{description}

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

**Module frequency:** {frequency}

**Supported distros:** {distros}

**Config schema**:
{property_doc}
{examples}
z4{prefix}**{prop_name}:** ({prop_type}) {description}zF{prefix}Each item in **{prop_name}** list supports the following keys:z
**Examples**::

z
    # --- Example{0} ---cs$eZdZdZff�fdd�	Z�ZS)�SchemaValidationErrorz<Raised when validating a cloud-config file against a schema.cs8||_dd�|D�}djdj|��}tt|�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),)
        cSsg|]\}}dj||��qS)z{0}: {1})�format)�.0Z
config_key�message�r�/usr/lib/python3.6/schema.py�
<listcomp>>sz2SchemaValidationError.__init__.<locals>.<listcomp>zCloud config schema errors: {0}z, N)�
schema_errorsr
�join�superr�__init__)�selfrZerror_messagesr)�	__class__rrr6szSchemaValidationError.__init__)�__name__�
__module__�__qualname__�__doc__r�
__classcell__rr)rrr3sr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)�
jsonschemar�ImportError�TYPE_CHECKERZis_type�
isinstance�bytes)Zchecker�instancerrrr�is_schema_byte_stringGsr&cCs�ddlm}m}ddlm}t|j�}d|d<ddi|dd	<t|d
�rj|jj	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)r�
FormatChecker)�createFZadditionalProperties�typer�
properties�labelr"Zdraft4)�meta_schema�
validators�version�type_checker)r,r-r.Z
default_types)r rr'Zjsonschema.validatorsr(rZMETA_SCHEMA�hasattrr"Zredefiner&Z
VALIDATORSZ
DEFAULT_TYPES�strr$)rr'r(�strict_metaschemar/�cloudinitValidator�typesrrr�get_jsonschema_validatorUs*


r5)�schemacCsxddlm}y|j|�WnX|k
rr}z<|rVtdjdd�|jD��|jffd�|�tjd|�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)r1)r�prrrr�sz3validate_cloudconfig_metaschema.<locals>.<listcomp>)rzGMeta-schema validation failed, attempting to validate config anyway: %sN)	Zjsonschema.exceptionsr7Zcheck_schemarr�pathr�LOG�warning)�	validatorr6�throwr7�errrrr�validate_cloudconfig_metaschema�s
 r@F)�configr6�strictr2cCs�|dkrt�}y t�\}}|r,t||dd�Wntk
rLtjd�dSX|||�d�}f}xDt|j|�dd�d�D]*}d	jd
d�|j	D��}	||	|j
ff7}qxW|r�|r�t|��n dd�|D�}
tjd
dj|
��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)

    @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:)�errr�<lambda>�sz-validate_cloudconfig_schema.<locals>.<lambda>)�keyr8cSsg|]}t|��qSr)r1)rr9rrrr�sz/validate_cloudconfig_schema.<locals>.<listcomp>cSsg|]\}}dj||��qS)z{0}: {1})r
)r�k�msgrrrr�sz!Invalid cloud-config provided:
%s�
)
�
get_schemar5r@r!r;�debug�sortedZiter_errorsrr:rrr<)rAr6rBr2r3r'r=�errorsrr:Zmessagesrrr�validate_cloudconfig_schema�s*


rMcCsx|s|Si}tt�}g}d}g}|j�jd�}t|t�sNdj||jd�g�S|r\t||�}xn|D]f\}	}
t	j
d|	�}|r�|j�\}}
|t|�j
|
�nd}
|||	j
|
�|
dk	rbdj||
|
d�}
qbWd}x�t|d�D]x\}}||}|�rJg}x8|D]0}|j
d	j|��|j
d
j||��|d7}�q�W|j
|ddj|��q�|j
|�q�W|j
|jdj|���dj|�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}

rHz&# E1: Cloud-config is not a YAML dict.z&format-l(?P<line>\d+)\.c(?P<col>\d+).*NzLine {line} column {col}: {msg})�line�colrG�zE{0}z# E{0}: {1}z		# �,)r�list�decode�splitr#�dictrr
�_schemapath_for_cloudconfig�re�match�groups�int�append�	enumerate)�cloudconfig�original_contentrZschemapathsZerrors_by_lineZerror_footerZerror_headerZannotated_content�linesr:rGrXrNrOZerror_index�line_numberrLZerror_labelrrrr�annotated_cloudconfig_file�sL	

rac
Cs�|dkr:tj�dkrtd��t�}|jd�}t|dd�}n&tjj|�sTtdj|���t|dd�}|j	t
�s�dd	j|t
j��ff}t|�}|r�t
ti||j��|�ytj|�}Wn�tjk
�r�}	z�d
}
}d}t|	d�r�t|	d�r�t|	d�}n"t|	d��rt|	d��rt|	d�}|�r.|jd
}
|jd
}d
j|
|d�dj|t|	��ff}t|�}|�rnt
ti||j��||	�WYdd}	~	XnXt|t��s�|�s�td��yt||dd�Wn>tk
�r�}	z |�r�t
t|||	j���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.
    Nrz?Unable to read system userdata as non-root user. Try using sudoZuserdata_rawF)rSzConfigfile {0} does not existzformat-l1.c1z"File {0} needs to begin with "{1}"rPZcontext_markZproblem_markzformat-l{line}.c{col})rNrOzFile {0} is not valid yaml. {1}z Cloud-config is not a YAML dict.T)rB)�os�getuid�RuntimeErrorrZ
get_ipath_curr
r:�existsr
�
startswith�CLOUD_CONFIG_HEADERrSr�printrar�yaml�	safe_loadZ	YAMLErrorr0�getattrrN�columnr1r#rUrM)
Zconfig_pathr6�annotate�pathsZuser_data_fileZcontentrLrr]rCrNrlZmarkrrr�validate_cloudconfig_files`




rocCs&|j�jd�}i}d}d}g}|s&iS�x�t|d�D�]�\}}ttj||�j�d�}	|j�}|s4|jd�rpq4|r�|d\}
}nd}
d}|jd��rd|d}|r�|j	|�r�|d	t|��}t
|�}
ttj||dd	��j�d�}|d7}|	}
|	|7}	||d	�}|d7}nd}|jd
d�\}
}|�rD|	|
k�rD|d|
}
xZ|	|
k�r�|�r�|j�\}
}|dk�r�|	|
k�r�dj|jd�d	d��}Pnd}
d}�qFW|j
|	|
f�|�r|j�}|jd��r|j
|	d
|
df�x6tdttj|���D]}|
dt
|�}|||<�q�W|||
<q4W|S)z�Return a dictionary mapping schemapath to original_content line number.

    @param config: The yaml.loaded config dictionary of a cloud-config file.
    @param original_content: The simple file content of the cloud-config file
    rHrz^(\s*)rP�#�z- z.%dN�:r8�[�z.0���rururu)rSrTr\�lenrWrXrY�striprf�endswithr1�poprr[�rangerirj)rAr^Z
content_linesZschema_line_numbersZ
list_indexZRE_YAML_INDENTZscopesr`rNZindent_depthZprevious_depthZpath_prefixZprevious_list_idxrEZitem_indent�valueZinner_list_indexZlist_keyrrrrVasb 

rV)�
property_dict�returncCs�|jd�}|dkrN|jd�r0dd�|dD�}n|jd�rNdd�|jd�D�}t|t�rbdj|�}|jd	i�}|jdd
�}x4|jdi�D]$}|r�|d7}|dt|�d7}q�W|r�d
j||�S|p�dS)zNReturn a string representing a property type from a given
    jsonschema.
    r)N�enumcSsg|]}ttj||���qSr)r1�	_YAML_MAP�get)rrFrrrr�sz&_get_property_type.<locals>.<listcomp>ZoneOfcSsg|]}|jd�r|d�qS)r))r�)rZ	subschemarrrr�s�/�itemsrq�(�)z
{0} of {1}Z	UNDEFINED)r�r#rRr�_get_property_typer
)r|Z
property_typer�Zsub_property_typeZsub_itemrrrr��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{}-)rW�subr
)�description�prefixZlist_paragraphrrr�_parse_description�sr��    )r6�defsr}c	Csr|d}g}|jdi�|jdi�g}�x@|D�]6}�x.|j�D�] \}}d|krn||djdd�}	|j|	�|jdd�}
|jd|�}|jtj||t|
|�t|�d	��|jd
�}|�r:t	|t
�r�xv|D]}
|jt|
||d��q�WnTt	|t��r:|jd��s
|jd��r:|jt
j||d��|d7}|jt|||d��d|k�sLd|kr>|jt|||d��q>Wq,Wd
j|�S)zDReturn restructured text describing the supported schema properties.z    r*ZpatternPropertiesz$refz#/$defs/rqr�r+)r��	prop_namer�Z	prop_typer�)r�r�)r�r�z

)r�r��replace�updater[�SCHEMA_PROPERTY_TMPLr
r�r�r#rR�_get_property_docrU�SCHEMA_LIST_ITEM_TMPLr)r6r�r�Z
new_prefixr*Z
property_keysZpropsZprop_keyZprop_config�refr�r+r��itemrrrr��sL





r�)�metar}cCst|jd�}|sdSt}xXt|�D]L\}}|jd�}dd�|D�}|tkr^|jdtj|d��|dj|�7}q W|S)zAReturn restructured text describing the meta examples if present.�examplesrqrHcSsg|]}dj|��qS)z    {0})r
)rrNrrrrsz!_get_examples.<locals>.<listcomp>rrP)r��SCHEMA_EXAMPLES_HEADERr\rT�insert�SCHEMA_EXAMPLES_SPACER_TEMPLATEr
r)r�r�Zrst_content�countZexampler_Zindented_linesrrr�
_get_exampless

r�)r�r6r}c
Cs6|dkrt�}|s|r"td��t|j��}tddddddd	h�}d
}||r`dj||�}n||rvdj||�}|r�t|��tt|��}|jd
i�}|j|d�r�|j|d�}yt	||d�|d<Wn&t
k
r�tjd�d
|d<YnXt
|�|d<dj|d�|d<tjdd|d	�|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 schema�id�titler�Z	frequencyZdistrosr��namerqz(Missing expected keys in module meta: {}z3Additional unexpected keys found in module meta: {}z$defs)r�Zproperty_docz3Unable to render property_doc due to invalid schemaz, r8�-Ztitle_underbar)rI�
ValueError�set�keysr
�KeyErrorrUrr�r��AttributeErrorr;r<r�rrWr��SCHEMA_DOC_TMPL)r�r6r�ZexpectedZ
error_messageZ	meta_copyr��templaterrr�get_meta_doc$sH

r�cCstjjtjjt��}t|�S)N)rbr:�dirname�abspath�__file__r	)Zconfigs_dirrrr�get_modules\sr�)�requested_modulesr}cCs�d}tt�j��dg}t|�jt|��}|rHtdjt|�dj|���xR|D]J}d|ksb||krNtj	|dgdg�\}}|rNtj
|d�}||jp�d7}qNW|S)zaLoad module docstrings

    Docstrings are generated on module load. Reduce, reuse, recycle.
    rq�allz+Invalid --docs value {}. Must be one of: {}z, zcloudinit.configr�r)rRr��valuesr��
differencerr
rr�find_module�
import_moduler)r��docsZall_modulesZinvalid_docs�mod_name�mod_locs�_�modrrr�load_docas 
r�cCs�tjjtjjtjjt��d�}d}ytjt|��}Wn0t	k
rd}zt
jd||�WYdd}~XnX|s�t
jd|�idgd�}xNt�j
�D]@\}}tj|dgdg�\}}|r�tj|d	�}|d
j|j�q�W|S)z?Return jsonschema coalesced from all cc_* cloud-config modules.zcloud-init-schema.jsonNz$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$schema�allOfzcloudinit.configr6rr�)rbr:rr�r�r��json�loadsr
�	Exceptionr;r<r�r�rr�r�r[r6)Zschema_file�full_schemarCr�r�r�r�rrrrI{s* rIcCsZt�}xNt�j�D]@\}}tj|dgdg�\}}|rtj|d�}|j||jd<qW|S)z<Return metadata coalesced from all cc_* cloud-config module.zcloudinit.configr�rr�)rUr�r�rr�r�r�)Z	full_metar�r�r�r�rrr�get_meta�sr�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)�parserrrr�
get_parser�s0r�cCs|j|j|jg}tdd�|D��dkr.td�|jrB|jrBtd�t�}|jsT|jr�yt|j||j�Wn`tk
r�}z|js�tt	|��WYdd}~XnNt
k
r�}ztt	|��WYdd}~Xn"X|jdkr�d}n|j}td|�n|j�rtt|j��dS)	z@Handle provided schema args and perform the appropriate actions.cSsg|]}|r|�qSrr)r�argrrrr�sz&handle_schema_args.<locals>.<listcomp>rPz;Expected one of --config-file, --system or --docs argumentsz;Invalid flag combination. Cannot use --annotate with --docsNzsystem userdatazValid cloud-config:)
Zconfig_filer��systemrvrrmrIrorr1rdrhr�)r��argsZexclusive_argsr�rCZcfg_namerrr�handle_schema_args�s*
r�cCst�}td|j��dS)zDTool to validate schema of a cloud-config file or print schema docs.zcloudconfig-schemar)r�r��
parse_args)r�rrr�main�sr��__main__)T)NFF)F)r�)N)N)<rr�r�ZloggingrbrW�sys�collectionsr�copyr�	functoolsrriZ	cloudinitrZcloudinit.cmd.develrZcloudinit.importerrZcloudinit.utilrr	r
Z	getLoggerrr;rrgr�r�r�r�r�r�rr&r5rUr@�boolrMrarorVr1r�r�r�r�r�r�rRr�rIr�r�r�r��exitrrrr�<module>s^
3#-8
O@=8&
$


Youez - 2016 - github.com/yon3zu
LinuXploit