§
    ôc9  ã                   ó’   — d dl Z d dlZd dlZd dlZd dlmZmZmZm	Z	 d„ Z
d„ Zd„ Z G d„ de¦  «        Zd„ Zdd
„Zd„ Zd„ Zd„ Zd„ ZdS )é    N)ÚenvironmentÚloadÚ	normalizeÚoverridec                  ó,   — t          j        dd¦  «        S )zq
    Path to the installed YAML configuration schema file, used to validate and parse the
    configuration.
    Ú	borgmaticzconfig/schema.yaml)Úpkg_resourcesÚresource_filename© ó    ú;/usr/lib/python3/dist-packages/borgmatic/config/validate.pyÚschema_filenamer   
   s   € õ
 Ô*¨;Ð8LÑMÔMÐMr   c                 ó´   — t          | t          ¦  «        r"t          d                     | ¦  «        ¦  «        S t          d                     | ¦  «        ¦  «        S )z]
    Given a path element into a JSON data structure, format it for display as a string.
    z[{}]z.{})Ú
isinstanceÚintÚstrÚformat)Úpath_elements    r   Úformat_json_error_path_elementr      sJ   € õ �,¥Ñ$Ô$ð 0Ý�6—=’= Ñ.Ô.Ñ/Ô/Ð/åˆu�|Š|˜LÑ)Ô)Ñ*Ô*Ð*r   c                 óè   — | j         sd                     | j        ¦  «        S d                     d„ | j         D ¦   «         ¦  «        }d                     |                     d¦  «        | j        ¦  «        S )zh
    Given an instance of jsonschema.exceptions.ValidationError, format it for display as a string.
    zAt the top level: {}Ú c              3   ó4   K  — | ]}t          |¦  «        V — Œd S ©N)r   )Ú.0Úelements     r   ú	<genexpr>z$format_json_error.<locals>.<genexpr>#   s+   è è € Ð_Ð_ÈÕ;¸GÑDÔDÐ_Ð_Ð_Ð_Ð_Ð_r   zAt '{}': {}ú.)Úpathr   ÚmessageÚjoinÚlstrip)ÚerrorÚformatted_paths     r   Úformat_json_errorr$      sn   € ð Œ:ð <Ø%×,Ò,¨U¬]Ñ;Ô;Ð;à—W’WÐ_Ð_ÐTYÔT^Ð_Ñ_Ô_Ñ_Ô_€NØ×Ò × 5Ò 5°cÑ :Ô :¸E¼MÑJÔJÐJr   c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚValidation_errorzs
    A collection of error messages generated when attempting to validate a particular
    configuration file.
    c                 ó"   — || _         || _        dS )z�
        Given a configuration filename path and a sequence of string error messages, create a
        Validation_error.
        N)Úconfig_filenameÚerrors)Úselfr(   r)   s      r   Ú__init__zValidation_error.__init__-   s   € ð
  /ˆÔØˆŒˆˆr   c                 ó€   — d                      | j        ¦  «        d                     d„ | j        D ¦   «         ¦  «        z   S )zD
        Render a validation error as a user-facing string.
        z<An error occurred while parsing a configuration file at {}:
ú
c              3   ó   K  — | ]}|V — Œd S r   r   ©r   r"   s     r   r   z+Validation_error.__str__.<locals>.<genexpr>;   s"   è è € Ð5Ð5 �eÐ5Ð5Ð5Ð5Ð5Ð5r   )r   r(   r    r)   )r*   s    r   Ú__str__zValidation_error.__str__5   sH   € ð O×UÒUØÔ ñ
ô 
à�IŠIÐ5Ð5¨¬Ð5Ñ5Ô5Ñ5Ô5ñ6ð 	6r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r+   r0   r   r   r   r&   r&   '   s<   € € € € € ðð ð
ð ð ð6ð 6ð 6ð 6ð 6r   r&   c                 ó  — |                      di ¦  «                              d¦  «        }|                      di ¦  «                              dg ¦  «        }|D ]*}||vr$t          | d                     |¦  «        f¦  «        ‚Œ+dS )zò
    Given a parsed and schematically valid configuration as a data structure of nested dicts (see
    below), run through any additional logical validation checks. If there are any such validation
    problems, raise a Validation_error.
    ÚlocationÚrepositoriesÚconsistencyÚcheck_repositorieszJUnknown repository in the "consistency" section's "check_repositories": {}N)Úgetr&   r   )r(   Úparsed_configurationÚlocation_repositoriesr9   Ú
repositorys        r   Úapply_logical_validationr>   >   sª   € ð 1×4Ò4°ZÀÑDÔD×HÒHÈÑXÔXÐØ-×1Ò1°-ÀÑDÔD×HÒHÐI]Ð_aÑbÔbÐØ(ð 	ð 	ˆ
ØÐ2Ð2Ð2Ý"Øàa×hÒhØ"ñô ðñô ð ð 3ð	ð 	r   Tc                 ó”  — 	 t          j        | ¦  «        }t          j        |¦  «        }nF# t          j        j        j        t          f$ r#}t          | t          |¦  «        f¦  «        ‚d}~ww xY wt          j
        ||¦  «         t          j        | |¦  «        }|rt          j        |¦  «         	 t          j        |¦  «        }n$# t           $ r t          j        |¦  «        }Y nw xY wt%          |                     |¦  «        ¦  «        }	|	r't          | t%          d„ |	D ¦   «         ¦  «        ¦  «        ‚t)          | |¦  «         ||fS )a[  
    Given the path to a config filename in YAML format, the path to a schema filename in a YAML
    rendition of JSON Schema format, a sequence of configuration file override strings in the form
    of "section.option=value", return the parsed configuration as a data structure of nested dicts
    and lists corresponding to the schema. Example return value:

       {'location': {'source_directories': ['/home', '/etc'], 'repository': 'hostname.borg'},
       'retention': {'keep_daily': 7}, 'consistency': {'checks': ['repository', 'archives']}}

    Also return a sequence of logging.LogRecord instances containing any warnings about the
    configuration.

    Raise FileNotFoundError if the file does not exist, PermissionError if the user does not
    have permissions to read the file, or Validation_error if the config does not match the schema.
    Nc              3   ó4   K  — | ]}t          |¦  «        V — Œd S r   )r$   r/   s     r   r   z&parse_configuration.<locals>.<genexpr>u   s+   è è € Ð"[Ð"[ÀÕ#4°UÑ#;Ô#;Ð"[Ð"[Ð"[Ð"[Ð"[Ð"[r   )r   Úload_configurationÚruamelÚyamlr"   Ú	YAMLErrorÚRecursionErrorr&   r   r   Úapply_overridesr   r   Úresolve_env_variablesÚ
jsonschemaÚDraft7ValidatorÚAttributeErrorÚDraft4ValidatorÚtupleÚiter_errorsr>   )
r(   r   Ú	overridesÚresolve_envÚconfigÚschemar"   ÚlogsÚ	validatorÚvalidation_errorss
             r   Úparse_configurationrU   R   sb  € ð ?ÝÔ(¨Ñ9Ô9ˆÝÔ(¨Ñ9Ô9ˆˆøÝŒKÔÔ'­Ð8ð ?ð ?ð ?Ý˜µ°U±´°Ñ>Ô>Ð>øøøøð?øøøõ Ô˜V YÑ/Ô/Ð/ÝÔ˜°Ñ7Ô7€DØð 2ÝÔ)¨&Ñ1Ô1Ð1ð7ÝÔ.¨vÑ6Ô6ˆ	ˆ	øÝð 7ð 7ð 7ÝÔ.¨vÑ6Ô6ˆ	ˆ	ˆ	ð7øøøå˜i×3Ò3°FÑ;Ô;Ñ<Ô<Ðàð 
ÝØ�UÐ"[Ð"[ÐIZÐ"[Ñ"[Ô"[Ñ[Ô[ñ
ô 
ð 	
õ ˜_¨fÑ5Ô5Ð5à�4ˆ<Ðs'   ‚(+ « A.ÁA)Á)A.Â2C ÃC(Ã'C(c                 óL   — d| v r| S t           j                             | ¦  «        S )z[
    Given a repository path, return the absolute path of it (for local repositories).
    ú:)Úosr   Úabspath)r=   s    r   Únormalize_repository_pathrZ   }   s)   € ð
 ˆjÐÐØÐåŒ7�?Š?˜:Ñ&Ô&Ð&r   c                 óB   — t          | ¦  «        t          |¦  «        k    S )z[
    Given two repository paths (relative and/or absolute), return whether they match.
    )rZ   )ÚfirstÚseconds     r   Úrepositories_matchr^   ˆ   s    € õ % UÑ+Ô+Õ/HÈÑ/PÔ/PÒPÐPr   c                 ó$  ‡ — ‰ sdS t          t          ˆ fd„|                     ¦   «         D ¦   «         ¦  «        ¦  «        }|dk    r"t          d                     ‰ ¦  «        ¦  «        ‚|dk    r"t          d                     ‰ ¦  «        ¦  «        ‚dS )a`  
    Given a repository path and a dict mapping from config filename to corresponding parsed config
    dict, ensure that the repository is declared exactly once in all of the configurations. If no
    repository is given, skip this check.

    Raise ValueError if the repository is not found in a configuration, or is declared multiple
    times.
    Nc              3   ó^   •K  — | ]'}|d          d         D ]}t          ‰|¦  «        ¯|V — ŒŒ(dS ©r6   r7   N)r^   )r   rP   Úconfig_repositoryr=   s      €r   r   z:guard_configuration_contains_repository.<locals>.<genexpr>œ   si   øè è € ð 
ð 
àØ%+¨JÔ%7¸Ô%Gð
ð 
ð "Ý! *Ð.?Ñ@Ô@ð	
Øð
ð 
ð 
ð 
ð 
ð 
ð 
r   r   z.Repository {} not found in configuration filesé   z3Repository {} found in multiple configuration files)ÚlenrL   ÚvaluesÚ
ValueErrorr   ©r=   ÚconfigurationsÚcounts   `  r   Ú'guard_configuration_contains_repositoryrj   �   s·   ø€ ð ð ØˆåÝð 
ð 
ð 
ð 
à(×/Ò/Ñ1Ô1ð
ñ 
ô 
ñ 	
ô 	
ñô €Eð �‚z€zÝÐI×PÒPÐQ[Ñ\Ô\Ñ]Ô]Ð]Øˆq‚y€yÝÐN×UÒUÐV`ÑaÔaÑbÔbÐbð €yr   c                 ó¨   — | rdS t          t          d„ |                     ¦   «         D ¦   «         ¦  «        ¦  «        }|dk    rt          d¦  «        ‚dS )zÞ
    Given a repository path and a dict mapping from config filename to corresponding parsed config
    dict, ensure either a single repository exists across all configuration files or a repository
    path was given.
    Nc              3   ó<   K  — | ]}|d          d         D ]}|V — ŒŒdS ra   r   )r   rP   rb   s      r   r   z3guard_single_repository_selected.<locals>.<genexpr>´   sW   è è € ð 
ð 
àØ%+¨JÔ%7¸Ô%Gð
ð 
ð "ð ð
ð 
ð 
ð 
ð 
ð 
ð 
r   rc   zICan't determine which repository to use. Use --repository to disambiguate)rd   rL   re   rf   rg   s      r   Ú guard_single_repository_selectedrm   ª   s|   € ð ð ØˆåÝð 
ð 
à(×/Ò/Ñ1Ô1ð
ñ 
ô 
ñ 	
ô 	
ñô €Eð �‚z€zÝØXñ
ô 
ð 	
ð €zr   )NT)rX   rH   r	   Úruamel.yamlrB   Úborgmatic.configr   r   r   r   r   r   r$   rf   r&   r>   rU   rZ   r^   rj   rm   r   r   r   ú<module>rp      s#  ðØ 	€	€	€	à Ð Ð Ð Ø Ð Ð Ð Ø Ð Ð Ð à CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CðNð Nð Nð+ð +ð +ðKð Kð Kð6ð 6ð 6ð 6ð 6�zñ 6ô 6ð 6ð.ð ð ð((ð (ð (ð (ðV'ð 'ð 'ðQð Qð Qðcð cð cð6
ð 
ð 
ð 
ð 
r   