HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/compose/config/__pycache__/validation.cpython-310.pyc
o

S�`�M�@sPddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
Z
ddlmZddlm
Zdd	lmZd
dlmZd
dlmZd
d
lmZe�e�Zdddddddddddddd�
ZdZdZdZdjed�Zdjed�ZdZd � d!jeed"��!��Z"e	j#ded#�d$d%��Z$e	j#d&ed#�d'd(��Z%e	j#d)ed*�d+d,��Z&d-d.�Z'd/d0�Z(d1d2�Z)d3d4�Z*d5d6�Z+d7d8�Z,d9d:�Z-d;d<�Z.d=d>�Z/d?d@�Z0dAdB�Z1dCdD�Z2dEdF�Z3dGdH�Z4dIdJ�Z5dKdL�Z6dMdN�Z7dOdP�Z8dQdR�Z9dSdT�Z:dUdV�Z;dWdX�Z<dYdZ�Z=d[d\�Z>d]d^�Z?d_d`�Z@dadb�ZAdcdd�ZBdedf�ZCdgdh�ZDdidj�ZEdkdl�ZFdS)m�N)�
split_port)�Draft4Validator)�
FormatChecker)�RefResolver)�ValidationError�)�COMPOSEFILE_V1)�NANOCPUS_SCALE���ConfigurationError)�VERSION_EXPLANATION)�"get_service_name_from_network_mode�
cpu_shares�extra_hosts�devices�links�
memswap_limit�ports�
privileged�volumes�working_dir)
�	cpu_share�add_host�hosts�
extra_host�device�link�memory_swap�port�	privilege�
priviliged�	privilige�volume�workdirz[a-zA-Z0-9\._\-]z^\d+(\-\d+)?(\/[a-zA-Z]+)?$z!(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])z({IPV4_SEG}\.){{3}}{IPV4_SEG})�IPV4_SEGz!^{IPV4_ADDR}/(\d|[1-2]\d|3[0-2])$)�	IPV4_ADDRz[0-9a-fA-F]{1,4}�a9
^
(
    (({IPV6_SEG}:){{7}}{IPV6_SEG})|
    (({IPV6_SEG}:){{1,7}}:)|
    (({IPV6_SEG}:){{1,6}}(:{IPV6_SEG}){{1,1}})|
    (({IPV6_SEG}:){{1,5}}(:{IPV6_SEG}){{1,2}})|
    (({IPV6_SEG}:){{1,4}}(:{IPV6_SEG}){{1,3}})|
    (({IPV6_SEG}:){{1,3}}(:{IPV6_SEG}){{1,4}})|
    (({IPV6_SEG}:){{1,2}}(:{IPV6_SEG}){{1,5}})|
    (({IPV6_SEG}:){{1,1}}(:{IPV6_SEG}){{1,6}})|
    (:((:{IPV6_SEG}){{1,7}}|:))|
    (fe80:(:{IPV6_SEG}){{0,4}}%[0-9a-zA-Z]{{1,}})|
    (::(ffff(:0{{1,4}}){{0,1}}:){{0,1}}{IPV4_ADDR})|
    (({IPV6_SEG}:){{1,4}}:{IPV4_ADDR})
)
/(\d|[1-9]\d|1[0-1]\d|12[0-8])
$
)�IPV6_SEGr&)�format�raisesc
Cs4zt|�WdSty}ztt|���d}~ww)NT)r�
ValueErrorr�str)�instance�e�r/�;/usr/lib/python3/dist-packages/compose/config/validation.py�format_portsEs
���r1�exposecCs"t|t�rt�t|�std��dS)Nz)should be of the format 'PORT[/PROTOCOL]'T)�
isinstancer,�re�match�VALID_EXPOSE_FORMATr�r-r/r/r0�
format_exposeNs
�r8�subnet_ip_address)r*cCs.t|t�rt�t|�st�t|�std��dS)Nzshould use the CIDR formatT)r3r,r4r5�VALID_REGEX_IPV4_CIDR�VALID_REGEX_IPV6_CIDRrr7r/r/r0�format_subnet_ip_addressXs

�r<cCsD|�dg�}|D]}|jr|j|vrtd�|��|�d����qdS)Nrz^Named volume "{}" is used in service "{}" but no declaration was found in the volumes section.�name)�get�is_named_volume�externalrr)�repr)�service_dict�project_volumes�service_volumes�volume_specr/r/r0�match_named_volumesbs����rFc	Cs(t|�j}ddddddddd��||�S)N�mapping�array�number�boolean�string)�dict�list�int�float�bool�unicoder,�bytes)�type�__name__r>)�type_�	type_namer/r/r0�python_type_to_yaml_typens
�	�rWc	Cs�t|t�stdj||tt|��d���|��D]+\}}t|t�s*tdj|||d���t|ttd�f�sBtdj|||tt|��d���qdS)z�Validate the structure of a configuration section. This must be done
    before interpolation so it's separate from schema validation.
    z>In file '{filename}', {section} must be a mapping, not {type}.)�filename�sectionrSzWIn file '{filename}', the {section} name {name} must be a quoted string, i.e. '{name}'.)rXrYr=NzFIn file '{filename}', {section} '{name}' must be a mapping not {type}.)rXrYr=rS)	r3rLrr)�anglicize_json_typerW�itemsr,rS)rX�configrY�key�valuer/r/r0�validate_config_section|s>

��
��
����r_cCs(t|jt�std�|jt|j����dS)Nz8Top level object in '{}' needs to be an object not '{}'.)r3r\rLrr)rXrS)�config_filer/r/r0�validate_top_level_object�s���racCsP|j�di�}|��D]\}}t|t�r%|d|dks%tdj||d���qdS)N�ulimits�soft�hardzdService '{s.name}' has invalid ulimit '{ulimit}'. 'soft' value can not be greater than 'hard' value )�s�ulimit)r\r>r[r3rLrr))�service_config�
ulimit_config�
limit_name�soft_hard_valuesr/r/r0�validate_ulimits�s
����rkcCs,d|}d|vr|durtd|��dSdS)zo
    The service to be extended must either be defined in the config key 'file',
    or within 'filename'.
    z'Invalid 'extends' configuration for %s:�fileNz;%s you need to specify a 'file', e.g. 'file: something.yml'r)�service_name�extends_optionsrX�error_prefixr/r/r0�validate_extends_file_path�s��rpcCsT|j�d�}|s
dSd|jvrtd��t|�}|sdS||vr(tdj||d���dS)N�network_mode�networksz0'network_mode' and 'networks' cannot be combinedzPService '{s.name}' uses the network stack of service '{dep}' which is undefined.�re�dep)r\r>rrr))rg�
service_namesrq�
dependencyr/r/r0�validate_network_mode�s
���rwcC�B|j�d�}|s
dSt|�}|sdS||vrtdj||d���dS)N�pidzPService '{s.name}' uses the PID namespace of service '{dep}' which is undefined.rs�r\r>rrr))rgru�pid_modervr/r/r0�validate_pid_mode�����r|cCrx)N�ipczPService '{s.name}' uses the IPC namespace of service '{dep}' which is undefined.rsrz)rgru�ipc_modervr/r/r0�validate_ipc_mode�r}r�cCs<|j�dg�D]}|�d�d|vrtdj||d���qdS)Nr�:rzEService '{s.name}' has a link to service '{link}' which is undefined.)rer)r\r>�splitrr))rgrurr/r/r0�validate_links�s����r�cCs:|j�di�}|��D]}||vrtdj||d���qdS)N�
depends_onzAService '{s.name}' depends on service '{dep}' which is undefined.rs)r\r>�keysrr))rgru�depsrvr/r/r0�validate_depends_on�s����r�cCs<|j�d�}|s
dSd|vrd|vrtdj|d���dSdS)N�credential_spec�registryrlzQService '{s.name}' is missing 'credential_spec.file' or credential_spec.registry')re)r\r>rr))rgr�r/r/r0�validate_credential_spec�s���r�cCs.d�t|�|�}|tvr|d�t|�7}|S)Nz&Unsupported config option for {}: '{}'z (did you mean '{}'?))r)�path_string�DOCKER_CONFIG_HINTS)�path�	error_key�msgr/r/r0�get_unsupported_config_msg
sr�cCs|�d�r	d|Sd|S)N)�ar.�i�o�uzan za )�
startswith)�	json_typer/r/r0rZs
rZcCs|dvS)N)zconfig_schema_v1.jsonz#/properties/servicesr/)�	schema_idr/r/r0�is_service_dict_schemasr�cCs�|jd}t|�r|jdkrd�dd�t|j�D�dt�S|jdkrS|dkr0t|�}t||�S|�	d�rIt|�}d	j|d
�
|jd���td�S|j
sUd
�|jt�SdSdS)N�id�additionalPropertiesz:Invalid service name '{}' - only {} characters are allowedcSs&g|]}|rttdd�|��r|�qS)cSst�t|�S�N)r4r5�VALID_NAME_CHARS)�cr/r/r0�<lambda>"sz<handle_error_for_schema_with_id.<locals>.<listcomp>.<lambda>)�any�filter)�.0r�r/r/r0�
<listcomp>!s�z3handle_error_for_schema_with_id.<locals>.<listcomp>rz#/definitions/service�config_schema_z�Invalid top-level property "{key}". Valid top-level sections for this Compose file are: {properties}, and extensions starting with "x-".

{explanation}�, �
properties)r]r��explanationz{}

{})�schemar��	validatorr)rMr-r��parse_key_from_error_msgr�r��joinr�r
r��message)�errorr�r��invalid_config_keyr/r/r0�handle_error_for_schema_with_ids0
��


��r�cCs�d}|j}|jdkrd}t|�\}}|r|�|�nO|jdkr'd}t|j�}nB|jdkr5d�|j�}d}n4|jdkrYt|j���d	}d
�|j|�}d}|�|�d�	||�}n|j
rdt|j
�}d}n|jrid
}|rt|j	t
|�|d�S|jS)N�oneOfz{path} {msg}rSz3{path} contains an invalid type, it should be {msg}�requiredr�z%{path} is invalid, {msg} is required.�dependenciesr�,z{path} is invalid: {msg}z,when defining '{}' you must set '{}' as wellz{path} value {msg})r�r�)r�r��_parse_oneof_validator�append�!_parse_valid_types_from_validator�validator_valuer�rMr�r)�causer,r�r�)r�r��
msg_format�	error_msg�
config_key�
required_keysr/r/r0�handle_generic_error:s>

�



�
r�cCsFz	|j�d�dWSty"|j�d�d�d�d�d�YSw)N�'r
�(� r)r�r��
IndexError�strip)r�r/r/r0r�cs
$�r�cCsd�dd�|D��S)N�.css�|]
}t|t�r|VqdSr�)r3r,)r�r�r/r/r0�	<genexpr>ks�zpath_string.<locals>.<genexpr>)r�)r�r/r/r0r�j�r�cCsZt|t�s	t|�St|�dkrt|d�Sd�d�t|d�g|dd��t|d��S)z�A validator value can be either an array of valid types or a string of
    a valid type. Parse the valid types and prefix with the correct article.
    r
rz	{}, or {}r����)r3rMrZ�lenr)r�)r�r/r/r0r�ns

�r�cCs�g}|jD]m}|jdkrt|�\}}t|j�|fS|jdkr'd|jfS|jdkr9t|�}dd�|�fS|jdkrP|jrFt|j�ndd�|j�fS|jrgt|j�d�t	�
|j�t|j��fS|jd	krr|�
|j�qt|�}dd
�|�fS)aoneOf has multiple schemas, so we need to reason about which schema, sub
    schema or constraint the validation is failing on.
    Inspecting the context value of a ValidationError gives us information about
    which sub schema failed and which kind of error it is.
    r�r�Nr�z!contains unsupported option: '{}'�uniqueItemsz;contains non-unique items, please remove duplicates from {}z6contains {}, which is an invalid type, it should be {}rSz)contains an invalid type, it should be {})�contextr�r�r�r�r�r�r)r-�json�dumpsr�r�r�)r��typesr��_r�r��valid_typesr/r/r0r�}s8




��
��
�r�cCsj|tkr"d|jvrd|jvrd�|�Sd|jvr"d|jvr"d�|�Sd|jvr1d|jvr3d�|�SdSdS)N�image�buildz�Service {} has both an image and build path specified. A service can either be built to image or use an existing image, not both.�
dockerfilez�Service {} has both an image and alternate Dockerfile. A service can either be built to image or use an existing image, not both.z]Service {} has neither an image nor a build context specified. At least one must be provided.)�V1r-r))r�rm�versionr/r/r0�!process_service_constraint_errors�s����r�cCs0t|j�}d|jvrt||�}|r|St||�S)Nr�)rMr�r�r�r�)r�r�r�r/r/r0�process_config_schema_errors�s



r�cCs@i}|��D]\}}||t|�<t|t�rt|�|t|�<q|S)zH
        Non-string keys may break validator with patterned fields.
    )r[r,r3rL�keys_to_str)r`�d�k�vr/r/r0r��s
�r�cCsLt|�}t|j�}tgd��}t|tt�|�|d�}t|�|�t	|j
�dS)N)rr2r9)�resolver�format_checker)�load_jsonschemar�r\rrr�get_resolver_path�
handle_errors�iter_errorsr�rX)r`r�r�r\r�r�r/r/r0�validate_against_config_schema�s

��r�csB��fdd�}t�j�}t|ddd�}t|�|�|d�dS)Ncst|��j�Sr�)r�r�)�errors�r`rmr/r0�handler�s�z-validate_service_constraints.<locals>.handler�definitions�constraints�service)r�r�rr�r�)r\rmr`r�r�r�r/r�r0�validate_service_constraints�s
r�cCs>|j�d�}|s
dS|t}t|t�r|��std��dSdS)N�cpusz6cpus must have nine or less digits after decimal point)r\r>r	r3rO�
is_integerr)rgr��	nano_cpusr/r/r0�validate_cpu�s��r�cCstj�tj�t��Sr�)�osr��dirname�abspath�__file__r/r/r/r0�get_schema_path�r�r�cCsxd}|tkrd}tj�t�d�|��}tj�|�s!td�|t���t	|��
}t
�|�Wd�S1s5wYdS)N�compose_spec�config_schema_v1z{}.jsonz"Version in "{}" is unsupported. {})r�r�r�r�r�r)�existsrr
�openr��load)r�r=rX�fhr/r/r0r��s��
$�r�cCs2t�}tjdkrd}|�dd�}nd}d�||�S)N�win32z///�\�/z//z
file:{}{}/)r��sys�platform�replacer))�schema_path�schemer/r/r0r�	s
r�csLt|td�}|s
dSd��fdd�|D��}tdj|r d�|�nd|d	���)
z�jsonschema returns an error tree full of information to explain what has
    gone wrong. Process each error and pull out relevant information and re-write
    helpful error messages that are relevant.
    )r]N�
c3s�|]}�|�VqdSr�r/)r�r���format_error_funcr/r0r�s�z handle_errors.<locals>.<genexpr>z:The Compose file{file_msg} is invalid because:
{error_msg}z '{}'r')�file_msgr�)�sortedr,r�rr))r�rrXr�r/r�r0r�s��r�cCs�|j�di�}d|vrHt|dt�rJt|d�dkr"td�|j���|dddkr8t|�dkr8td�|j���|dddvrLtd	�|j���dSdSdS)
N�healthcheck�testrzDService "{}" defines an invalid healthcheck: "test" is an empty list�NONEr
zbService "{}" defines an invalid healthcheck: "disable: true" cannot be combined with other options)r�CMDz	CMD-SHELLzwService "{}" defines an invalid healthcheck: when "test" is a list the first item must be either NONE, CMD or CMD-SHELL)r\r>r3rMr�rr)r=)rgrr/r/r0�validate_healthcheck$s&����r)Gr��loggingr�r4r��docker.utils.portsr�
jsonschemarrrr�constrr�r	r�rr
�
sort_servicesr�	getLoggerrT�logr�r�r6�VALID_IPV4_SEGr)�VALID_IPV4_ADDRr:�VALID_IPV6_SEGr�r�r;�
cls_checksr1r8r<rFrWr_rarkrprwr|r�r�r�r�r�rZr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr/r/r/r0�<module>s�
���

	
	

))