o
    i}                     @   s   d dl Z d dlZd dlmZmZ d dlmZ ddlmZ ddl	m
Z
 G dd de
Zd	ee fd
dZdededed	efddZded	dfddZdS )    N)OptionalDict)HttpRequest   )EnvironmentVariables)MsalManagedIdentityClientc                   @   s    e Zd ZddedefddZdS )AzureMLCredential descreturnc                 C   s
   d| S )NzBAzure ML managed identity configuration not found in environment.  )selfr
   r   r   [/home/app/Keep/.python/lib/python3.10/site-packages/azure/identity/_credentials/azure_ml.pyget_unavailable_message   s   
z)AzureMLCredential.get_unavailable_messageN)r	   )__name__
__module____qualname__strr   r   r   r   r   r      s    r   r   c               	   K   sn   |  dd pi }tjtj}tjtj}|r|sd S | dr(|  d|d< t| t|d|it	
t|dS )Nidentity_configZ	client_idZclientidsecret)Z_content_callbackr   base_headersZrequest_factory)poposenvirongetr   ZMSI_ENDPOINTZ
MSI_SECRETdict_parse_expires_on	functoolspartial_get_request)kwargsr   urlr   r   r   r   _get_client_args   s   

r"   r!   scoper   c                 C   s    t d| td|dfi |dS )NGETz
2017-09-01)zapi-versionresource)params)r   r   )r!   r#   r   r   r   r   r   )   s    r   contentc              	   C   s   zt | d | d< W dS  ty   Y nw ddl}ddl}| d }|drN|dtd  }dD ]}z|||}||| d< W  dS  tyM   Y q1w td|)a  Parse an App Service MSI version 2017-09-01 expires_on value to epoch seconds.

    This version of the API returns expires_on as a UTC datetime string rather than epoch seconds. The string's
    format depends on the OS. Responses on Windows include AM/PM, for example "1/16/2020 5:24:12 AM +00:00".
    Responses on Linux do not, for example "06/20/2019 02:57:58 +00:00".

    :param dict content: a deserialized response from an App Service MSI.
    :raises ValueError: ``expires_on`` didn't match an expected format
    
expires_onNr   z +00:00)z%m/%d/%Y %H:%M:%Sz%m/%d/%Y %I:%M:%S %pz&'{}' doesn't match the expected format)	int
ValueErrorcalendartimeendswithlenstrptimetimegmformat)r'   r+   r,   r(   Zdate_stringformat_stringtr   r   r   r   -   s(   
r   )r   r   typingr   r   Zazure.core.restr   
_constantsr   Z&_internal.msal_managed_identity_clientr   r   r"   r   r   r   r   r   r   r   <module>   s   