
    Zj                     b   U d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ 	 ddlZn# e$ rZ ed          edZ[ww xY w	 ddlZn# e$ rZ ed	          edZ[ww xY wg Zee         ed
<   defdZ ej        e          ZdedefdZdeddfdZdeeef         defdZdS )z'Configuration file loading and parsing.    N)Path)Any)ConfigurationError)substitute_env_vars)OpenTelemetryConfigurationzcFile configuration requires pyyaml. Install with: pip install opentelemetry-sdk[file-configuration]zgFile configuration requires jsonschema. Install with: pip install opentelemetry-sdk[file-configuration]_schema_cachereturnc                      t           sbt          j                            d          dz  } t                               t          j        |                     d                               t           d         S )Nz opentelemetry.sdk._configurationzschema.jsonutf-8encodingr   )r   	importlib	resourcesfilesappendjsonloads	read_text)schema_paths    j/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/opentelemetry/sdk/_configuration/file/_loader.py_get_schemar   %   sq     
%%&HII 	 	J{,,g,>>??	
 	
 	
     	file_pathc                 z   t          |           }|                                s-t                              d|            t	          d|            |                                s-t                              d|            t	          d|            	 t          |d          5 }|                                }ddd           n# 1 swxY w Y   n@# t          $ r3}t          	                    d|            t	          d	|            |d}~ww xY w	 t          |          }n%# t          $ r}t	          d
|           |d}~ww xY w|j                                        }	 |dv rt          j        |          }nI|dk    rt!          j        |          }n.t                              d|           t	          d| d          n# t          j        $ r3}t          	                    d|            t	          d|           |d}~wt           j        $ r3}t          	                    d|            t	          d|           |d}~ww xY w|*t                              d|            t	          d          t)          |t*                    sQt                              dt-          |          j                   t	          dt-          |          j                   t1          |           	 t3          |          }n@# t          $ r3}t          	                    d|            t	          d|           |d}~ww xY w|S )aG  Load and parse an OpenTelemetry configuration file.

    Supports YAML and JSON formats. Performs environment variable substitution
    before parsing.

    Args:
        file_path: Path to the configuration file (.yaml, .yml, or .json).

    Returns:
        Parsed OpenTelemetryConfiguration object.

    Raises:
        ConfigurationError: If file cannot be read, parsed, or validated.
        EnvSubstitutionError: If required environment variable is missing.

    Examples:
        >>> config = load_config_file("otel-config.yaml")
        >>> print(config.tracer_provider)
    z Configuration file not found: %szConfiguration file not found: z$Configuration path is not a file: %sz"Configuration path is not a file: r   r   Nz%Failed to read configuration file: %sz#Failed to read configuration file: z*Environment variable substitution failed: )z.yamlz.ymlz.jsonzUnsupported file format: %szUnsupported file format: z. Use .yaml, .yml, or .jsonzFailed to parse YAML from %szFailed to parse YAML: zFailed to parse JSON from %szFailed to parse JSON: zConfiguration file is empty: %szConfiguration file is emptyz.Configuration must be a mapping/object, got %sz,Configuration must be a mapping/object, got z(Failed to validate configuration from %sz"Failed to validate configuration: )r   exists_loggererrorr   is_fileopenreadOSError	exceptionr   	Exceptionsuffixloweryaml	safe_loadr   r   	YAMLErrorJSONDecodeError
isinstancedicttype__name___validate_schema_dict_to_model)r   pathconfig_filecontentexcr$   dataconfigs           r   load_config_filer6   4   s   ( 	??D;;== O8)DDD !M)!M!MNNN<<>> 
<iHHH <<<
 
 	
$))) 	)[!&&((G	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)   A9MMM =)==
 
	%g..    >>>
 
	 [  FJ&&&>'**DDw:g&&DDMM7@@@$OFOOO   > J J J8)DDD !?#!?!?@@cI J J J8)DDD !?#!?!?@@cIJ |7CCC !>???dD!! 
<JJ	
 	
 	
 !P4::;NPP
 
 	
 T%%   6		
 	
 	
 !666
 
		 Ms   C $C9C C		C C	C 
D.D		DD" "
E,D??E!A"G I.HI.II+K; ;
L8.L33L8r4   c           
         	 t          j        | t                      t           j                   dS # t           j        $ rT}t          |j        r0d|j         dd                    d |j        D                        dn	d|j                   |d}~wt           j	        $ r}t          d|j                   |d}~ww xY w)	zValidate configuration dict against the OTel configuration JSON schema.

    Raises:
        ConfigurationError: If the data does not conform to the schema.
    )instanceschemaclsz%Configuration does not match schema: z (at z -> c              3   4   K   | ]}t          |          V  d S )N)str).0ps     r   	<genexpr>z#_validate_schema.<locals>.<genexpr>   s(      AA!s1vvAAAAAAr   )NzInvalid configuration schema: )

jsonschemavalidater   Draft202012ValidatorValidationErrorr   absolute_pathmessagejoinSchemaError)r4   r3   s     r   r.   r.      s    ==/	
 	
 	
 	
 	
 	

 %      G ECK E E;;AAs/@AAAAAE E E E GFF	
 

 	 !    :S[::
 
	s"   -1 B> ABB>!B99B>c                 j    	 t          di | }|S # t          $ r}t          d|           |d}~ww xY w)a  Convert dictionary to OpenTelemetryConfiguration model.

    Uses the generated dataclass from models.py. This provides basic
    validation through dataclass field types.

    Args:
        data: Parsed configuration dictionary.

    Returns:
        OpenTelemetryConfiguration instance.

    Raises:
        TypeError: If data doesn't match expected structure.
        ValueError: If values are invalid.
    zdConfiguration structure is invalid. Check that all required fields are present and correctly typed: N )r   	TypeError)r4   r5   r3   s      r   r/   r/      sj    (+33d33   UORU U
 
 	s    
2-2)__doc__importlib.resourcesr   r   loggingpathlibr   typingr   ,opentelemetry.sdk._configuration._exceptionsr   7opentelemetry.sdk._configuration.file._env_substitutionr   'opentelemetry.sdk._configuration.modelsr   r&   ImportErrorr3   rA   r   listr+   __annotations__r   	getLoggerr-   r   r<   r6   r.   r/   rJ   r   r   <module>rX      s   . - -                   K K K K K K      O N N N N NKKKK   
+	J     
+	J   tDz   	T 	 	 	 	 '
H
%
%^ ^(B ^ ^ ^ ^B4 D    2c3h ,F      s,   4 A
AA
A A)A$$A)