HEX
Server: Apache
System: Linux sh-pro142.hostgator.com.br 5.14.0-162.23.1.9991722448259.nf.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 31 18:11:45 UTC 2024 x86_64
User: okform09 (1324)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //usr/libexec/oracle-cloud-agent/plugins/osms/oci_agent_utils/config.pyc
a

���f��@sZdZddlZddlZddlZddlmZddlZedddg�Zddd�ZGd	d
�d
�Z	dS)zD
Get a config object by calling config.from_file("/path/to/config")
�N)�Enum�OS�Windows�LinuxcCs
t||�S�N)�Config)�filename�operating_system�r
�F/sparta/input/python_modules/oci_agent_utils/oci_agent_utils/config.py�	from_filesrc@sfeZdZdZiZdZddd�Zdd�Zddd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
ddd�ZdS)ra�
    This class loads the configuration from a yaml file and stores the
    dictionary representation in memory. The main purpose is to separate
    config from the implementation to allow alter settings after installation.

    If no config file is specified, the config is assumed to be the file 'config.yml' in a platform-specific directory.
    On Windows, the config file will be assumed located along with the agent
    executable; on Linux, the config will be assumed located in: /etc/oracle-cloud-agent

    The default config is packed accordingly in OS specific build. To update
    config file location, please also update the build script accordingly.

    NOTE: Use get_config function in the module, to avoid multiple copies of the same object.
    NcCs<|dur(t��dkrtj|_q.tj|_n||_|�|�dS)Nr)�platform�systemrr�	_platformr�load_config)�self�config_filer	r
r
r�__init__'s

zConfig.__init__c
Cs�|durXd}|��r.tj�tj�tj�|�}n*|��rJtj�ddd|�}ntd|j	��z@t
|d��"}|�t�
|��|_Wd�n1s�0YWn4ty�}ztd�|�|��WYd}~n
d}~00dS)Nz
config.yml�/�etc�oracle-cloud-agentzUnknown platform: �rz&Fail to load the configuration at {0}.)�
is_windows�os�path�join�dirname�sys�
executable�is_linux�RuntimeErrorr�open�_expand_log_filename�yaml�	safe_load�_config�	Exception�format)rr�default_config_file_name�
configFile�er
r
rr2s�(zConfig.load_configcCs|j�||�Sr)r%�get)r�key�defaultr
r
rr+Csz
Config.getcCs|j�|�Sr)r%�__getitem__)rr,r
r
rr.FszConfig.__getitem__cCs|jtjkSr)rrr�rr
r
rrIszConfig.is_windowscCs|jtjkSr)rrrr/r
r
rrLszConfig.is_linuxcCs|jj��Sr)r�name�lowerr/r
r
rr
OszConfig.platformc
Cs(d|v�r$d|dv�r$|��|ddv�r$tj�|dd|���}tj�|��szDt�|�|��r�ddl}|�d�j	}|�d�j
}t�|||�Wnft�y}zL|�
�r�td�|�|��n&|��r�ddl}|�|jd�||��WYd}~n
d}~00d	|v�r$|�||d	d	�|d	<|S)
a�
        This function takes two special config settings to make the logging
        filename config working across Windows and Linux. Specifically, if the
        agent config has '[os]_log_dir' setting and if the 'filename' for
        logging 'rotating_file' handler is not an absolute path, the 'filename'
        will be assumed to be under 'log_dir' for the respective OS.
        �agent�log_dirrNr�admz(Fail to create the log directory at {0}.zMFail to create the log directory or set ownership at {0!s}. Exception: {1!r}.�logging)r
rr�
expandvars�exists�makedirsr�pwd�getpwnam�pw_uid�pw_gid�chownr&rr r'�syslog�LOG_INFO�#_Config__visit_and_replace_filename)r�configr3r9�uid�gidr*r>r
r
rr"Rs<��
��

��zConfig._expand_log_filenamecsnt|t�r&��fdd�t|���D�St|t�rD��fdd�|D�S|dkrftj�|�sftj��|�S|SdS)zDRecursively visit each node in config; expand the 'filename' settingcs i|]\}}|���||��qSr
�r@)�.0�k�v�r3rr
r�
<dictcomp>z�z7Config.__visit_and_replace_filename.<locals>.<dictcomp>csg|]}���|��qSr
rD)rE�itemrHr
r�
<listcomp>|rJz7Config.__visit_and_replace_filename.<locals>.<listcomp>rN)�
isinstance�dict�list�itemsrr�isabsr)rr3�noder,r
rHr�__visit_and_replace_filenamews

z#Config.__visit_and_replace_filename)NN)N)N)�__name__�
__module__�__qualname__�__doc__r%rrrr+r.rrr
r"r@r
r
r
rrs

%r)NN)
rWrr
r�enumrr#rrrr
r
r
r�<module>s