File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/azurearm.cpython-310.pyc
o
�N�g- � @ s� d Z ddlZddlZddlZddlmZ ddlZddlZddl Zddl
ZddlZddlZddl
mZmZ zddlmZmZ ddlmZmZ dZW n eyS dZY nw e�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_endpointTFc C s t sdS dS )NFT)� HAS_AZURE� r
r
�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/azurearm.py�__virtual__6 s r c
K s� d| v rt d | d �}| �|� g d�}ddg}z$| �d�r.| �d��d�r.t| d �}nt�d�}t|| �dd ��}W n tt t
fyQ t�d
�
| d ���w t|��| �rx| d re| d re| d
sitd��t| d | d | d
|d�}nAt|��| �r�| d r�| d s�td��t| d | d |d�}n"d| v r�z
ddlm} ||d�}W n t y� tdd��w td��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
r r z_The client_id, secret, and tenant parameters must all be populated if using service principals.)r r zfThe 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�issubsetr r r Z"msrestazure.azure_active_directoryr r �salt�utilsZstringutilsZto_str) �kwargsZazure_credentialsZservice_principal_creds_kwargsZuser_pass_creds_kwargs� cloud_envZcloud_env_module�credentialsr r r
r
r �_determine_auth= sv
��
����������� �
r* c K s� ddddddddd d
dd�}| |vrt d
�| �d��|| }| dv r%d}n | dv r,d}n| }zt�d| �}t||� d��}W n tyO t�d| � d���w tdi |��\}}} | 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�PolicyZResourceManagementZSubscriptionZWebSiteManagement)ZcomputeZ
authorizationZdnsZstorage�managementlockZmonitor�network�policy�resource�subscriptionZwebz8The Azure ARM client_type {} specified can not be found.r )r. r0 r/ )r, zresource.locks�azure.mgmt.�Clientz
The azure z client is not available.r0 )r) �base_url)r) r r3 zSalt/Nr
)r r"