HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/roster/__pycache__/sshconfig.cpython-310.pyc
o

�N�g_�@s�dZddlZddlZddlZddlZddlZddlZddlZe�	e
�Ze�dddg�Z
e
ddd�e
d	d
d�e
ddd�fZd
d�Zdd�Zddd�ZGdd�d�ZdS)z�
Parses roster entries out of Host directives from SSH config

.. code-block:: bash

    salt-ssh --roster sshconfig '*' -r "echo hi"
�N�
_SSHConfRegex�target_field�pattern�userz\s+User (.*))rr�portz\s+Port (.*)Zprivz\s+IdentityFile (.*)cCs>|�d�}tj�|�std��t�|tj�std|����|S)zL
    :return: Path to the .ssh/config file - usually <home>/.ssh/config
    �ssh_config_filezCannot find SSH config filezCannot access SSH config file: )�get�os�path�isfile�OSError�access�R_OK)�optsr�r�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/roster/sshconfig.py�_get_ssh_config_files
rcCs^g}|D]"}tjj�|�}|r|�d�rq|�d�r|�g�|d�|�qt��}|D]:}t��}|d��dd�}|dd�D]}t	D]}t
�|j|�}|r\|�
d���||j<qGqC|D]}	|||	<q`q-g}
g}|��D]}d|vszd|vr�|
�|�qp|�|�qp|
D]}|D]}
t�|
|�r�||
�||�q�||=q�|D]}|||d	<q�|S)
z�
    Parses lines from the SSH config to create roster targets.

    :param lines: Individual lines from the ssh config file
    :return: Dictionary of targets in similar style to the flat roster
    �#zHost ���r�N�*�?�host)�salt�utilsZstringutilsZ
to_unicode�
startswith�append�collections�OrderedDict�split�_ROSTER_FIELDS�re�matchr�group�stripr�keys�fnmatch�update)�lines�hosts�line�targetsZ	host_data�targetZ	hostnames�fieldr"�hostnameZwildcard_targetsZnon_wildcard_targetsr�	candidaterrr�parse_ssh_config(sJ	

��
��r0�globcKsbtt�}tjj�|d��}tdd�|D��}Wd�n1s wYt|||�}|��}|S)zs
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    �rcSsg|]}|���qSr)�rstrip)�.0r*rrr�
<listcomp>csztargets.<locals>.<listcomp>N)	rZ__opts__rr�filesZfopenr0�
RosterMatcherr+)�tgt�tgt_type�kwargsr�fpZall_minionsZrmatcherZmatchedrrrr+\s�r+c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)r7z/
    Matcher for the roster data structure
    cCs||_||_||_dS)N)r8r9�raw)�selfr<r8r9rrr�__init__ns
zRosterMatcher.__init__cCs0zt|d|j�d���WStyiYSw)zA
        Execute the correct tgt_type routine and return
        Zret_Z_minions)�getattrr9�AttributeError)r=rrrr+ss
�zRosterMatcher.targetscCs8i}|jD]}t�||j�r|�|�}|r|||<q|S)z4
        Return minions that match via glob
        )r<r&r8�get_data)r=Zminions�minion�datarrr�ret_glob_minions|s

�zRosterMatcher.ret_glob_minionscCs<t|j|t�rd|j|iSt|j|t�r|j|SdS)z*
        Return the configured ip
        rF)�
isinstancer<�str�dict)r=rBrrrrA�s

zRosterMatcher.get_dataN)�__name__�
__module__�__qualname__�__doc__r>r+rDrArrrrr7is	r7)r1)rKrr&�loggingr	r!Zsalt.utils.filesrZsalt.utils.stringutils�	getLoggerrH�log�
namedtuplerr rr0r+r7rrrr�<module>s$



�
4