
    hK                    <   % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
J
r
  S SKJr  S SKJrJrJrJrJrJr  S SKrS SKJrJr  S SKJr  \(       a#  S SKJr  \R8                  S	:  a  S S
KJr  OS S
KJr  S SKJ r   \!\"\#\#4   \\$   4   r%S\&S'   \\/ \%4   S4   r'S\&S'    " S S\5      r( " S S\RR                  5      r* " S S\*\RR                  5      r+ " S S\+5      r, " S S\+5      r- " S S\+5      r. " S S\+5      r/ " S S\*5      r0    S S jr1g)!    )annotationsN)datetime)partial)TYPE_CHECKINGAnyCallableOptional	TypedDictUnion)eprintverbose)NoPickleOption)boto3)   
   )	TypeAlias)issue_unstable_warningr    CredentialProviderFunctionReturnCredentialProviderCredentialProviderFunctionc                      \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   Srg)AWSAssumeRoleKWArgs,   zParameters for [STS.Client.assume_role()](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sts/client/assume_role.html#STS.Client.assume_role).strRoleArnRoleSessionNamezlist[dict[str, str]]
PolicyArnsPolicyintDurationSecondsTagsz	list[str]TransitiveTagKeys
ExternalIdSerialNumber	TokenCodeSourceIdentityProvidedContexts N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r(       h/home/james-whalen/.local/lib/python3.13/site-packages/polars/io/cloud/credential_provider/_providers.pyr   r   ,   sL     tL$$K
  ON**r0   r   c                  @    \ rS rSrSr\R                  SS j5       rSrg)r   =   z
Base class for credential providers.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.
c                    g)zFetches the credentials.Nr(   selfs    r1   __call__CredentialProvider.__call__F   s    r0   r(   Nreturnr   )	r)   r*   r+   r,   r-   abcabstractmethodr7   r/   r(   r0   r1   r   r   =   s!     	' 'r0   c                  h    \ rS rSrSrS
S jrSS jr\R                  SS j5       r	S
S jr
SS jrSrg	)CachingCredentialProviderK   z
Base class for credential providers that has built-in caching.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.
c                0    [        5       U l        SU l        g )NF)r   _cached_credentials_has_logged_use_cacher5   s    r1   __init__"CachingCredentialProvider.__init__T   s     	  &+"r0   c                T   [         R                  " S5      S:X  a+  U R                  R                  S 5        U R	                  5       $ U R                  R                  5       nUb8  US   =nbc  U[        [        R                  " 5       R                  5       5      ::  a3  U R	                  5       nU R                  R                  U5        SU l
        OR[        5       (       aC  U R                  (       d2  US   n[        S[        R                  U 5       SU< S35        SU l
        Uu  p20 UEU4$ )	N(POLARS_DISABLE_PYTHON_CREDENTIAL_CACHING1   F[z&]: Using cached credentials (expiry = )T)osgetenvrA   setretrieve_credentials_implgetr   r   now	timestamprB   r   r   r>   __repr__)r6   credentialsexpirycredss       r1   r7   "CachingCredentialProvider.__call__Z   s   99?@CG$$((.1133..224"1~%V2#hlln6689988:K$$((5).D&YYt99 ^F-66t<= >7-3Kq: *.D&#%y&  r0   c                    g Nr(   r5   s    r1   rN   3CachingCredentialProvider.retrieve_credentials_implv   s    MPr0   c                :    U R                   R                  S 5        g rX   )rA   rM   r5   s    r1   clear_cached_credentials2CachingCredentialProvider.clear_cached_credentialsy   s      $$T*r0   c                ^    S[        U 5      R                   S[        [        U 5      5       S3$ )NzCachingCredentialProvider[z @ ])typer)   hexidr5   s    r1   rR   "CachingCredentialProvider.__repr__|   s+    +DJ,?,?+@C4M?RSTTr0   )rA   rB   Nr:   Noner9   r:   r   )r)   r*   r+   r,   r-   rC   r7   r;   r<   rN   r[   rR   r/   r(   r0   r1   r>   r>   K   s2    +!8 	P P+Ur0   r>   c                  L   ^  \ rS rSrSr    SU 4S jjrSS jrS	S jrSrU =r	$ )
CachedCredentialProvider   z
Wrapper that adds caching on top of a credential provider.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.
c                .   > Xl         [        TU ]	  5         g rX   )	_providersuperrC   )r6   provider	__class__s     r1   rC   !CachedCredentialProvider.__init__   s     "r0   c                "    U R                  5       $ rX   rj   r5   s    r1   rN   2CachedCredentialProvider.retrieve_credentials_impl   s    ~~r0   c                $    SU R                   < S3$ )NzCachedCredentialProvider[r^   rp   r5   s    r1   rR   !CachedCredentialProvider.__repr__   s    *4>>*<A>>r0   rp   )rl   z/CredentialProvider | CredentialProviderFunctionr:   rd   r9   re   )
r)   r*   r+   r,   r-   rC   rN   rR   r/   __classcell__rm   s   @r1   rg   rg      s,    G	 ? ?r0   rg   c                     ^  \ rS rSrSrSSSSSS.           SU 4S jjjrSS jrSS jrSS	 jrSS
 jr	SS jr
\SS j5       r " S S\5      rSrU =r$ )CredentialProviderAWS   z
AWS Credential Provider.

Using this requires the `boto3` Python package to be installed.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.
NF)profile_nameregion_nameassume_role_auto_init_unhandled_key!_storage_options_has_endpoint_urlc                  > Sn[        U5        U R                  5         Xl        X l        X0l        X@l        XPl        [        TU ]!  5         g)a  
Initialize a credential provider for AWS.

Parameters
----------
profile_name : str
    Profile name to use from credentials file.
assume_role : AWSAssumeRoleKWArgs | None
    Configure a role to assume. These are passed as kwarg parameters to
    [STS.client.assume_role()](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sts/client/assume_role.html#STS.Client.assume_role)
z<`CredentialProviderAWS` functionality is considered unstableN)	r   _ensure_module_availabilityry   rz   r{   r|   r}   rk   rC   )r6   ry   rz   r{   r|   r}   msgrm   s          r1   rC   CredentialProviderAWS.__init__   sH    ( Ms#((*(&&(@%1R.r0   c                   U R                   (       a   eU R                  5       nU R                  b  U R                  U5      $ UR	                  5       nUc  SnU R                  U5      e[        [        USS5      =n[        5      (       a  [        UR                  5       5      OSnUR                  UR                  S.UR                  b  SUR                  0EU4$ 0 EU4$ )z6Fetch the credentials for the configured profile name.NzDdid not receive any credentials from boto3.Session.get_credentials()_expiry_time)aws_access_key_idaws_secret_access_keyaws_session_token)r|   _sessionr{   _finish_assume_roleget_credentialsEmptyCredentialError
isinstancegetattrr   r   rQ   
access_key
secret_keytoken)r6   sessionrU   r   rT   s        r1   rN   /CredentialProviderAWS.retrieve_credentials_impl   s    0000--/'++G44'')=XC++C00 GE>4$HH&(SS   "# 	 "'!1!1%*%5%5
 6;[[5L#U[[1
 	 	 SU
 	 	r0   c                    UR                  S5      nUR                  " S	0 U R                  D6nUS   nUS   nUR                  c  Sn[        U5      eUS   US   US   S.[	        UR                  5       5      4$ )
NstsCredentials
ExpirationzDexpiration time in STS response did not contain timezone informationAccessKeyIdSecretAccessKeySessionToken)r   r   r   r(   )clientr{   tzinfo
ValueErrorr   rQ   )r6   r   r   sts_responserU   rT   r   s          r1   r   )CredentialProviderAWS._finish_assume_role   s    &))=D,<,<=]+|$== XCS/! "'}!5%*+<%=!&~!6
 v!"	# 	#r0   c                   U R                   (       a  0 $  U R                  5       R                  R                  5       nUR	                  S5      =n(       a!  [        5       (       a  [        SU 35        SU0$ 0 $ ! [         a    0 s $ f = f)Nendpoint_urlz.[CredentialProviderAWS]: Loaded endpoint_url: )r}   r   get_scoped_configImportErrorrO   r   r   )r6   configr   s      r1   _storage_update_options-CredentialProviderAWS._storage_update_options   s    11I	]]_--??AF "::n55<5yyG~VW"L11	  	I	s   (A8 8BBc                   U R                   (       a)  [        5       (       a  [        SU R                    S35        g U " 5         g! [         ac  nU R                  (       aH  SU R                   S[        U5      R                   SU 3n[        R                  R                  U5      Ue S nAgS nAfU R                   a    [        5       (       a  [        S5         gf = f)	Nz\[CredentialProviderAWS]: Will not be used as a provider: unhandled key in storage_options: ''Fz#cannot load requested aws_profile 'z': z: z5[CredentialProviderAWS]: Did not find any credentialsT)r|   r   r   r   ry   r_   r)   polars
exceptionsComputeErrorr   )r6   er   s      r1   _can_use_as_provider*CredentialProviderAWS._can_use_as_provider  s    ((yy::>:W:W9XXY[
 	F$ !  	  ))*#d1g.>.>-?r!F  ''44S9q@(( 	yyNO		s   A 
CAB,,-CCc                T    SS K nUR                  " U R                  U R                  S9$ )Nr   )ry   rz   )r   Sessionry   rz   )r6   r   s     r1   r   CredentialProviderAWS._session"  s(    }}**((
 	
r0   c                ^    [         R                  R                  S5      c  Sn[        U5      eg )Nr   z6boto3 must be installed to use `CredentialProviderAWS`	importlibutil	find_specr   clsr   s     r1   r   1CredentialProviderAWS._ensure_module_availability+  s,    >>##G,4JCc"" 5r0   c                      \ rS rSrSrSrg)*CredentialProviderAWS.EmptyCredentialErrori1  z
Raised when boto3 returns empty credentials.

This generally indicates that no credentials could be found in the
environment.
r(   N)r)   r*   r+   r,   r-   r/   r(   r0   r1   r   r   1  s    	r0   r   )r|   r}   r{   ry   rz   )ry   
str | Nonerz   r   r{   zAWSAssumeRoleKWArgs | Noner|   r   r}   boolr:   rd   r9   )r   r   r:   r   )r:   zdict[str, str])r:   r   )r:   zboto3.Sessionrc   )r)   r*   r+   r,   r-   rC   rN   r   r   r   r   classmethodr   	Exceptionr   r/   rt   ru   s   @r1   rw   rw      s     $("&26/327 !  	
 0 #- ,0 
 B6#&$>
 # #
y  r0   rw   c                     ^  \ rS rSrSrSSSSS.         SU 4S jjjrSS jr  SS jr\SS j5       r	\
SS	 j5       r\SS
 j5       r\SS j5       r\
SS j5       rSrU =r$ )CredentialProviderAzurei:  z
Azure Credential Provider.

Using this requires the `azure-identity` Python package to be installed.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.
N)scopes	tenant_id
credential_storage_accountc          	       > Sn[        U5        X@l        Ub  UOS/U l        X l        X0l        Ub$  [        US5      (       d  SU< S3n[        U5      eO!U R                  5       c  U R                  5         [        5       (       a6  [        SU R                  < SU R                  < S	U R                  < S
35        [        TU ]1  5         g)a  
Initialize a credential provider for Microsoft Azure.

By default, this uses `azure.identity.DefaultAzureCredential()`.

Parameters
----------
scopes
    Scopes to pass to `get_token`
tenant_id
    Azure tenant ID.
credential
    Optionally pass an instantiated Azure credential class to use (e.g.
    `azure.identity.DefaultAzureCredential`). The credential class must
    have a `get_token()` method.
z>`CredentialProviderAzure` functionality is considered unstableNz"https://storage.azure.com/.default	get_tokenz!the provided `credential` object z& does not have a `get_token()` method./[CredentialProviderAzure]: self.account_name = z self.tenant_id = z self.scopes =  )r   account_namer   r   r   hasattrr   6_try_get_azure_storage_account_credential_if_permittedr   r   r   rk   rC   )r6   r   r   r   r   r   rm   s         r1   rC    CredentialProviderAzure.__init__E  s    0 Os#,(F/S.T 	 #$! :{337
~ F7 7  !o% 4 HHJR,,.99($$( )%>>% &";;"!% 	r0   c                   U R                  5       =n b  U$ SSKnU R                  =(       d    UR                  R	                  5       nUR
                  " U R                  SU R                  06nSUR                  0UR                  4$ )Fetch the credentials.Nr   r   bearer_token)
r   azure.identityr   identityDefaultAzureCredentialr   r   r   r   
expires_on)r6   vazurer   r   s        r1   rN   1CredentialProviderAzure.retrieve_credentials_impl  s     LLNNA H__O(M(M(O
$$dkkLT^^L EKK
 	r0   c                   [         R                  " S5      n[        R                  R                  R                  5       nU(       a  [        SU R                  < SU< 35        U R                  b:  US:X  a4   SU R                  U R                  5      0nU(       a  [        S5        US 4$ g ! [         a  nU(       a  [        SU 35         S nAg S nAff = f)N)POLARS_AUTO_USE_AZURE_STORAGE_ACCOUNT_KEYr   z- POLARS_AUTO_USE_AZURE_STORAGE_ACCOUNT_KEY = rG   account_keyz?[CredentialProviderAzure]: Retrieved account key from Azure CLIzJ[CredentialProviderAzure]: Could not retrieve account key from Azure CLI: )
rK   rL   r   _utilsloggingr   r   r   %_get_azure_storage_account_key_az_clir   )r6   r   r   rU   r   s        r1   r   NCredentialProviderAzure._try_get_azure_storage_account_credential_if_permitted  s     57II75
1 --''//1($$( )@<@B )9S@#!4#M#M))$ Y d{"  defdgh s   7/B+ +
C5CCc                ^    [         R                  R                  S5      c  Sn[        U5      eg )Nzazure.identityzAazure-identity must be installed to use `CredentialProviderAzure`r   r   s     r1   r   3CredentialProviderAzure._ensure_module_availability  s-    >>##$45=UCc"" >r0   c                     U R                  SS5      S   R                  SS5      S   R                  SS5      S   R                  SS5      S   $ ! [         a     g f = f)Nz://rH   /r   @z.dfs.core.windows.net)split
IndexError)uris    r1   !_extract_adls_uri_storage_account9CredentialProviderAzure._extract_adls_uri_storage_account  sm    				%#A&sAq"sAq" .216  		s   AA 
AAc                f    [         R                  " U R                  SSSSSSSU5      5      S   S	   $ )
Nstorageaccountkeyslistz--outputjsonz--account-namer   value)r   loads_azcli)r   r   s     r1   r   =CredentialProviderAzure._get_azure_storage_account_key_az_cli  sM    " zzJJ 	
   	r0   c                t     [         R                  " U R                  S5      5      S   $ ! [         a     g f = f)Nversionz	azure-cli)r   r   r   r   )r   s    r1   _azcli_version&CredentialProviderAzure._azcli_version  s6    	::cjj34[AA 		s   '* 
77c                 r    [         R                  " [        R                  S:w  a	  S/U Q5      $ SSS/U Q5      $ )Nwin32azcmdz/C)
subprocesscheck_outputsysplatform)argss    r1   r   CredentialProviderAzure._azcli  sB    && \\W4TMDM
 	
;@$:Tt:T
 	
r0   )r   r   r   r   )
r   zlist[str] | Noner   r   r   
Any | Noner   r   r:   rd   r9   )r:   z'CredentialProviderFunctionReturn | Nonerc   )r   r   r:   r   )r   r   r:   r   )r:   r   )r   r   r:   bytes)r)   r*   r+   r,   r-   rC   rN   r   r   r   staticmethodr   r   r   r   r/   rt   ru   s   @r1   r   r   :  s     $( $!%'+9 !9 	9
 9 %9 
9 9v '	0'R # #
    :   
 
r0   r   c                  n   ^  \ rS rSrSrSSSSS.         S	U 4S jjjrS
S jr\SS j5       rSr	U =r
$ )CredentialProviderGCPi  z
GCP Credential Provider.

Using this requires the `google-auth` Python package to be installed.

.. warning::
    This functionality is considered **unstable**. It may be changed
    at any point without it being considered a breaking change.
Nr   requestquota_project_iddefault_scopesc                  > Sn[        U5        U R                  5         SSKn[        UR                  R
                  Ub  UOS/UUUS9U l        [        TU ]!  5         g)z
Initialize a credential provider for Google Cloud (GCP).

Parameters
----------
Parameters are passed to `google.auth.default()`
z<`CredentialProviderGCP` functionality is considered unstabler   Nz.https://www.googleapis.com/auth/cloud-platformr  )	r   r   google.authr   authdefault_init_credsrk   rC   )r6   r   r  r  r  r   googlerm   s          r1   rC   CredentialProviderGCP.__init__  se     Ms#((*"KK % FG-)

 	r0   c                z   SSK nU R                  5       u  p#UR                  UR                  R                  R
                  R                  5       5        SUR                  0UR                  =nbJ  [        UR                  c#  UR                  [        R                  " S5      S9OUR                  5       5      4$ S4$ )r   r   Nr   UTC)r   )google.auth.transport.requestsr  refreshr
  	transportrequestsRequestr   rT   r   r   replacezoneinfoZoneInforQ   )r6   r  rU   _project_idrT   s        r1   rN   /CredentialProviderGCP.retrieve_credentials_impl)  s    -!--/fkk++44<<>?,  ,,&3  }}, NN(*;*;E*BNC)+

 
	
 

 
	
r0   c                ^    [         R                  R                  S5      c  Sn[        U5      eg )Nzgoogle.authz<google-auth must be installed to use `CredentialProviderGCP`r   r   s     r1   r   1CredentialProviderGCP._ensure_module_availability<  s,    >>##M2:PCc"" ;r0   )r  )
r   r   r  r   r  r   r  r   r:   rd   r9   rc   )r)   r*   r+   r,   r-   rC   rN   r   r   r/   rt   ru   s   @r1   r  r    sl     ""'+%)" " 	"
 %" #" 
" "H
& # #r0   r  c                  ,    \ rS rSrSrSS jrSS jrSrg)	UserProvidedGCPTokeniC  z+User-provided GCP token in storage_options.c                    Xl         g rX   r   )r6   r   s     r1   rC   UserProvidedGCPToken.__init__F  s    
r0   c                "    SU R                   0S 4$ )Nr   r   r5   s    r1   r7   UserProvidedGCPToken.__call__I  s    

+T11r0   r   N)r   r   r:   rd   r9   )r)   r*   r+   r,   r-   rC   r7   r/   r(   r0   r1   r  r  C  s    52r0   r  c                   [        U [        5      (       a  U R                  5       (       d  g U " 5       u  pUbm  U[        [        R
                  " 5       R                  5       5      -
  =nS:  a8  SSKJn  [        5       (       a  [        SU S35        U" SU-   5        U " 5       u  p[        U [        5      (       a  U R                  5       =n(       a  0 UEUEnU$ )N   r   )sleepzwaiting for z" seconds for refreshed credentialsrH   )r   rw   r   r   r   rP   rQ   timer&  r   r   r   )credential_providerrU   
opt_expiry
expires_inr&  _r   s          r1   +_get_credentials_from_provider_expiry_awarer,  M  s     	&(=>>#88::+-E 	%HLLN,D,D,F(GGGZ1L99\*-OPQa*n&( %'<== 88:::5ALr0   )r(  r   r:   zdict[str, str] | None)2
__future__r   r;   importlib.utilr   r   rK   r   r   r  r   	functoolsr   typingr   r   r   r	   r
   r   polars._utils.loggingr   r   r   polars.io.cloud._utilsr   polars._dependenciesr   version_infor   typing_extensionspolars._utils.unstabler   tupledictr   r   r   r.   r   r   ABCr   r>   rg   rw   r   r  r  r,  r(   r0   r1   <module>r:     s/   " 
   	  
      1 1*
7"$/ 9 /4DcNHSM4Q.R  ) R(-R1124HH) I 
+) +"' '2U 2CGG 2Uj?8 ?.`5 `F}
7 }
@F#5 F#R2- 23r0   