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/utils/__pycache__/azurearm.cpython-310.pyc
o

�N�g-�@s�dZddlZddlZddlZddlmZddlZddlZddl	Zddl
ZddlZddlZddl
mZmZzddlmZmZddlmZmZdZWneySdZYnwe�e�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Z ddd�Z!dS)a�
Azure (ARM) Utilities

.. versionadded:: 2019.2.0

:maintainer: <devops@eitr.tech>
:maturity: new
:depends:
    * `azure <https://pypi.python.org/pypi/azure>`_ >= 2.0.0rc6
    * `azure-common <https://pypi.python.org/pypi/azure-common>`_ >= 1.1.4
    * `azure-mgmt <https://pypi.python.org/pypi/azure-mgmt>`_ >= 0.30.0rc6
    * `azure-mgmt-compute <https://pypi.python.org/pypi/azure-mgmt-compute>`_ >= 0.33.0
    * `azure-mgmt-network <https://pypi.python.org/pypi/azure-mgmt-network>`_ >= 0.30.0rc6
    * `azure-mgmt-resource <https://pypi.python.org/pypi/azure-mgmt-resource>`_ >= 0.30.0
    * `azure-mgmt-storage <https://pypi.python.org/pypi/azure-mgmt-storage>`_ >= 0.30.0rc6
    * `azure-mgmt-web <https://pypi.python.org/pypi/azure-mgmt-web>`_ >= 0.30.0rc6
    * `azure-storage <https://pypi.python.org/pypi/azure-storage>`_ >= 0.32.0
    * `msrestazure <https://pypi.python.org/pypi/msrestazure>`_ >= 0.4.21
:platform: linux

�N)�
itemgetter)�SaltInvocationError�SaltSystemExit)�ServicePrincipalCredentials�UserPassCredentials)�MetadataEndpointError� get_cloud_from_metadata_endpointTFcCstsdSdS)NFT)�	HAS_AZURE�r
r
�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/azurearm.py�__virtual__6src	
Ks�d|vrtd|d�}|�|�gd�}ddg}z$|�d�r.|�d��d�r.t|d�}nt�d�}t||�dd	��}Wntt	t
fyQt�d
�
|d���wt|��|�rx|dre|dre|d
sitd��t|d|d|d
|d�}nAt|��|�r�|dr�|ds�td��t|d|d|d�}n"d|vr�z
ddlm}||d�}Wnt	y�tdd��wtd��d|vr�td��tjj�|d�}|||fS)z'
    Acquire Azure ARM Credentials
    Zprofilez
config.option)�	client_id�secret�tenant�username�password�cloud_environment�httpzmsrestazure.azure_cloudZAZURE_PUBLIC_CLOUDz0The Azure cloud environment {} is not available.r
rrz_The client_id, secret, and tenant parameters must all be populated if using service principals.)rrzfThe username and password parameters must both be populated if using username/password authentication.)r�subscription_idr)�MSIAuthenticationzHMSI authentication support not availabe (requires msrestazure >= 0.4.14)��msgz�Unable to determine credentials. A subscription_id with username and password, or client_id, secret, and tenant or a profile with the required parameters populatedz#A subscription_id must be specified)Z__salt__�update�get�
startswithr�	importlib�
import_module�getattr�AttributeError�ImportErrorr�sys�exit�format�set�issubsetrrrZ"msrestazure.azure_active_directoryrr�salt�utilsZstringutilsZto_str)	�kwargsZazure_credentialsZservice_principal_creds_kwargsZuser_pass_creds_kwargs�	cloud_envZcloud_env_module�credentialsrrr
r
r�_determine_auth=sv
��
�����������	�
r*cKs�ddddddddd	d
dd�}||vrtd
�|�d��||}|dvr%d}n	|dvr,d}n|}zt�d|�}t||�d��}WntyOt�d|�d���wtdi|��\}}}	|dkrg|||	j	j
d�}
n	||||	j	j
d�}
|
j�dt
jj���|
S)zT
    Dynamically load the selected client and return a management client object
    ZComputeManagementZAuthorizationManagementZ
DnsManagementZStorageManagementZManagementLockZMonitorManagementZNetworkManagement�PolicyZResourceManagementZSubscriptionZWebSiteManagement)ZcomputeZ
authorizationZdnsZstorage�managementlockZmonitor�network�policy�resource�subscriptionZwebz8The Azure ARM client_type {} specified can not be found.r)r.r0r/)r,zresource.locks�azure.mgmt.�Clientz
The azure z client is not available.r0)r)�base_url)r)rr3zSalt/Nr
)rr"rrrrr r!r*Z	endpointsZresource_manager�configZadd_user_agentr%�version�__version__)Zclient_typer'Z
client_mapZ	map_value�module_nameZ
client_moduler2r)rr(�clientr
r
r�
get_client�sV������r9c	KsJz
tt|�d��}Wnttfyttd�}Ynw|d|��|�dS)z/
    Log an azurearm cloud error exception
    Zazurearm_log_level�errorz*An AzureARM %s CloudError has occurred: %sN)r�logrr�	TypeError�
capitalize)r8�messager'Zcloud_loggerr
r
r�log_cloud_error�s�
�r?cCs8g}	z
t|�}|�|���Wn
tyY|Swq)zK
    Extract all pages within a paged object as a list of dictionaries
    )�next�appendZas_dict�
StopIteration)Zpaged_objectZpaged_returnZpager
r
r�paged_object_to_list�s��rCcKs�i}zt�d|�d��}t||�}Wnty"t�d�||���wdt|�vr�|j�	�D]�\}}|�
|�}|dur�|dd��rVt|t
�rVt||dfi|��||<q.|dddkrht|t
�rh|||<q.|ddd	kr�t|t�r�g}	|D]V}
|dd
��r�t|
t
�r�|	�t||d|d�d	�d
|d�d��fi|
���qy|dd
dkr�t|
t
�r�|	�|
�qy|dd
��s�|dd
dkr�|	�|
�qy|	||<q.|||<q.|di|��S)
z6
    Assemble an object from incoming parameters.
    r1z.modelsz5The {} model in the {} Azure module is not available.�_attribute_mapN�typer�{�[��]r
)rrrrr r!r"�dirrD�itemsr�isupper�
isinstance�dict�create_object_model�listrA�index�rindex)r7Zobject_namer'Z
object_kwargsZmodel_moduleZModel�attrrK�paramZobj_listZ	list_itemr
r
rrO�sd���
��
������
 
�
�rOcCsBi}|sg}t|t�sd|d<|St|�t|�kr"||d�|d<|Sz
dd�||fD�\}}Wnty>d|d<|YStyLd|d<|YSwt|�D]M\}}|D]F}||}	||vrs||�|i��d	d
��d�d}
n||�|�}
t|	t�r�|	�	�}	t|
t�r�|
�	�}
|	|
kr�||d�|d<|SqWqQ|S)
a
    Compare lists of dictionaries representing Azure objects. Only keys found in the "new" dictionaries are compared to
    the "old" dictionaries, since getting Azure objects from the API returns some read-only data which should not be
    used in the comparison. A list of parameter names can be passed in order to compare a bare object name to a full
    Azure ID path for brevity. If string types are found in values, comparison is case insensitive. Return comment
    should be used to trigger exit from the calling function.
    z+must be provided as a list of dictionaries!Zcomment)�old�newZchangescss �|]}t|td�d�VqdS)�name)�keyN)�sortedr)�.0r4r
r
r�	<genexpr>3s�
�z(compare_list_of_dicts.<locals>.<genexpr>z:configurations must be provided as a list of dictionaries!z7configuration dictionaries must contain the "name" key!�id��/���)
rMrP�lenr<�KeyError�	enumerater�split�str�lower)rUrVZconvert_id_to_name�retZ
local_configsZremote_configs�idx�valrXZ	local_valZ
remote_valr
r
r�compare_list_of_dictssJ
�� �

��ri)N)"�__doc__r�loggingr �operatorrZsalt.configr%Zsalt.loaderZsalt.utils.argsZsalt.utils.stringutilsZsalt.utils.versionsZsalt.versionZsalt.exceptionsrrZazure.common.credentialsrrZmsrestazure.azure_cloudrrr	r�	getLogger�__name__r;rr*r9r?rCrOrir
r
r
r�<module>s6�
P<5