o
    i                     @   s   d dl Z d dlZd dlZd dlmZmZ ddlmZmZ er"d dl	Z	e 
eZG dd dZ	dded	ed
dfddZdededed
dfddZdS )    N)TYPE_CHECKINGAny   )CACHE_CAE_SUFFIXCACHE_NON_CAE_SUFFIXc                	   @   s2   e Zd ZdZddddedededd	fd
dZd	S )TokenCachePersistenceOptionsa  Options for persistent token caching.

    Most credentials accept an instance of this class to configure persistent token caching. The default values
    configure a credential to use a cache shared with Microsoft developer tools and
    :class:`~azure.identity.SharedTokenCacheCredential`. To isolate a credential's data from other applications,
    specify a `name` for the cache.

    By default, the cache is encrypted with the current platform's user data protection API, and will raise an error
    when this is not available. To configure the cache to fall back to an unencrypted file instead of raising an
    error, specify `allow_unencrypted_storage=True`.

    .. warning:: The cache contains authentication secrets. If the cache is not encrypted, protecting it is the
       application's responsibility. A breach of its contents will fully compromise accounts.

    .. admonition:: Example:

        .. literalinclude:: ../tests/test_persistent_cache.py
            :start-after: [START snippet]
            :end-before: [END snippet]
            :language: python
            :caption: Configuring a credential for persistent caching
            :dedent: 8

    :keyword str name: prefix name of the cache, used to isolate its data from other applications. Defaults to the
        name of the cache shared by Microsoft dev tools and :class:`~azure.identity.SharedTokenCacheCredential`.
        Additional strings may be appended to the name for further isolation.
    :keyword bool allow_unencrypted_storage: whether the cache should fall back to storing its data in plain text when
        encryption isn't possible. False by default. Setting this to True does not disable encryption. The cache will
        always try to encrypt its data.
    Fz
msal.cacheallow_unencrypted_storagenamer	   r
   kwargsreturnNc                K   s   || _ || _d S )Nr   )selfr	   r
   r    r   W/home/app/Keep/.python/lib/python3.10/site-packages/azure/identity/_persistent_cache.py__init__2   s   
z%TokenCachePersistenceOptions.__init__)__name__
__module____qualname____doc__boolstrr   r   r   r   r   r   r      s    &r   Foptionsis_caer   z#msal_extensions.PersistedTokenCachec                 C   s4   dd l }|rtnt}t| jd| j| d}||S )Nr   Z	MSALCache)allow_unencryptedaccount_name
cache_name)msal_extensionsr   r   _get_persistencer	   r
   ZPersistedTokenCache)r   r   r   Zcache_suffixZpersistencer   r   r   _load_persistent_cache8   s   
r   r   r   r   z+msal_extensions.persistence.BasePersistencec              
   C   s  ddl }tjdrdtjv rtjtjd d|}||S tjdr8tj	tjdd|}|
|d|S tjd	rtj	tjdd|}z|j||d
di|dW S  tyy } ztjd|dd | sotd}||W Y d}~nd}~ww ||S td)a  Get an msal_extensions persistence instance for the current platform.

    On Windows the cache is a file protected by the Data Protection API. On Linux and macOS the cache is stored by
    libsecret and Keychain, respectively. On those platforms the cache uses the modified timestamp of a file on disk to
    decide whether to reload the cache.

    :param bool allow_unencrypted: when True, the cache will be kept in plaintext should encryption be impossible in the
        current environment
    :param str account_name: the name of the account for which the cache is storing tokens
    :param str cache_name: the name of the cache
    :return: an msal_extensions persistence instance
    :rtype: ~msal_extensions.persistence.BasePersistence
    r   NwinLOCALAPPDATAz.IdentityServicedarwin~z#Microsoft.Developer.IdentityServicelinuxZMsalClientID)labelz=msal-extensions is unable to encrypt a persistent cache: "%s"T)exc_infoa;  Cache encryption is impossible because libsecret dependencies are not installed or are unusable, for example because no display is available (as in an SSH session). The chained exception has more information. Specify "allow_unencrypted_storage=True" to store the cache unencrypted instead of raising this exception.z8A persistent cache is not available in this environment.)r   sysplatform
startswithosenvironpathjoinZ!FilePersistenceWithDataProtection
expanduserZKeychainPersistenceZLibsecretPersistence	Exception_LOGGERdebug
ValueErrorZFilePersistenceNotImplementedError)r   r   r   r   Zcache_location	file_pathexerrorr   r   r   r   F   s2   


r   )F)loggingr)   r&   typingr   r   
_constantsr   r   r   	getLoggerr   r/   r   r   r   r   r   r   r   r   r   <module>   s4   
'
