
    it@                       S r 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	J
r
  SSK	Jr  SSK	Jr  SSKJr  SSKJr  SSKrSSKrSS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"  SSK#J$r$  SSK%J&r&  SSK'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  \$R^                  " \R`                  5      r1\Rd                  " SS5      r3Sr4SS/r5/ SQr6\
" \" S5      5      r7\7Rq                  SS5      r9\
" \" \Rt                  S 5      5      Rq                  SS5      r;S9S! jr< " S" S#\=5      r> " S$ S%\?5      r@   S:       S;S& jjrAS<S' jrBS=S( jrCS>S?S) jjrDS>S@S* jjrE   S:       SAS+ jjrF   S:       SAS, jjrG   S:       SAS- jjrH   S:       SAS. jjrI   S:       SAS/ jjrJ    SB           SCS0 jjrK    SD           SES1 jjrL   S:       S;S2 jjrM   S:       SAS3 jjrNS<S4 jrO     SF           SGS5 jjrPSHS6 jrQ S:       SIS7 jjrR       SJ                 SKS8 jjrSg)Lz5
Configure Conda to use Anaconda Commercial Edition.
    )annotationsN)abspath)
expanduser)join)Any)urljoin)context)main)CondaKeyErrorread_binstar_tokens)remove_binstar_token)set_binstar_token)CondaSession)Channel)version)Confirm)Commands)CondaRC)_build_channel_settings)consoleCONDA_TOKEN_REPO_URLz!https://repo.anaconda.cloud/repo/r
   rmsys2)freezmro-archiveproz
~/.condarc%z%%z.condarcc                     [         R                  " 5          [         R                  " S[        5        [	        U 0 UD6sS S S 5        $ ! , (       d  f       g = f)Nignore)warningscatch_warningssimplefilterPendingDeprecationWarning
conda_main)argskwargss     @lib/python3.13/site-packages/anaconda_auth/_conda/repo_config.pyrun_commandr(   1   s8    		 	 	"h(AB4*6* 
#	"	"s   &A
Ac                      \ rS rSrSrg)CondaTokenError8    N__name__
__module____qualname____firstlineno____static_attributes__r,       r'   r*   r*   8       r3   r*   c                      \ rS rSrSrg)CondaVersionWarning<   r,   Nr-   r,   r3   r'   r6   r6   <   r4   r3   r6   c                    / nU (       a  UR                  S5        U$ U(       a  UR                  S5        U$ U(       a  UR                  SU 35        U$ )z5Construct conda CLI args related to condarc location.z--systemz--envz--file=)append)condarc_systemcondarc_envcondarc_fileconfig_argss       r'   _get_condarc_argsr>   @   s]     K:&  
7#  
W\N34r3   c                     [         [        R                  " S5      :  =(       a    [         [        R                  " S5      :  $ )Nz4.7.0z25.9.0)CONDA_VERSIONr   parser,   r3   r'   can_restore_free_channelrB   R   s3    GMM'22 }w}}H 8 r3   c                 <    [        [        R                  SSS5        g)zRuns conda clean -i.

It is important to remove index cache when
changing the condarc to ensure that the downloaded
repodata is correct.
z-iz-yz-qN)r(   r   CLEANr,   r3   r'   clean_indexrE   Y   s     dD1r3   c                   U(       a  S[         R                  l        [        [        S5      (       a  [        R
                  " 5         O) [        R                  R                  R                  5         [	        5       n[        5         [        [        [        S5      5      nXl        [        UR!                  SS95      nUR#                  XBR$                  S9nUR&                  S:w  a  [)        S5      eg	! [         a     Nf = f)
z2Checks that token can be used with the repository.Fcache_clearzmain/noarch/repodata.jsonT)with_credentials)verify   zPThe token could not be validated. Please check that you have typed it correctly.N)context_moduler	   
ssl_verifyhasattrr   rG   _thread_localsessionsclearAttributeErrorrE   r   r   REPO_URLtokenstrurlheadrI   status_coder*   )rS   no_ssl_verifysessionchannel	token_urlr   s         r'   validate_tokenr\   c   s     ,1)
 |]++  "	&&//557
 nG Mgh(CDEGMGKKK67IY~~6A}}^
 	
   		s   	(C1 1
C>=C>c                    [        SS9nU(       d  g[        5       nUR                  5         U H  nUR                  US   US   SS9  M     UR	                  5         g)zConfigure the user's .condarc file with the anaconda-auth plugin.

We install the auth-handler plugin by writing the "channel_settings" key and associate
all premium repo channels with this auth handler.

F)include_defaultsNrZ   auth)username)r   r   backupupdate_channel_settingssave)should_set_default_channelssettingscondarcss       r'   configure_pluginrh      sU     '>HiGNN'')ai$'O LLNr3   c                r   [         [        R                  " S5      :  a  [        R                  " S[
        5        g[        U UUS9n/ SQnUR                  U5        [        [        R                  /UQ76   SS[        R                  S5      /nUR                  U5        [        [        R                  /UQ76   g)	zEnable package signature verification.

This will set extra_safety_checks: True and
signing_metadata_url_base in the CondaRC file.
4.10.1z[You need upgrade to at least Conda version 4.10.1 to enable package signature verification.Nr:   r;   r<   )--setextra_safety_checkstruerl   signing_metadata_url_base/)r@   r   rA   r    warnr6   r>   extendr(   r   CONFIGrR   rstripr:   r;   r<   condarc_file_argssafety_check_argsmetadata_url_argss         r'   enable_extra_safety_checksry      s     w}}X..i	
 	)%! A./4"34 "=xs?ST./4"34r3   c                X   [         [        R                  " S5      :  a  g[        U UUS9n/ SQnUR	                  U5         [        [        R                  /UQ76   SS/nUR	                  U5         [        [        R                  /UQ76   g! [         a     N=f = f! [         a     gf = f)zDisable package signature verification.

This will set extra_safety_checks: false and remove
signing_metadata_url_base in the CondaRC file.
rj   Nrk   )rl   rm   false--remove-keyro   )	r@   r   rA   r>   rr   r(   r   rs   r   ru   s         r'   disable_extra_safety_checksr}      s     w}}X..)%! B./HOO8&78 ()DE./HOO8&78    s$   B 1B 
BB
B)(B)c                x    / SQn[        U UUS9nUR                  U5        [        [        R                  /UQ76   g)zRun conda config --set add_anaconda_token true.

Setting this parameter to true ensures that the token
is used when making requests to the repository.
)rl   add_anaconda_tokenrn   rk   Nr>   rr   r(   r   rs   r:   r;   r<   r=   rv   s        r'   _set_add_anaconda_tokenr      s?     :K)%!
 ().+.r3   c                x    / SQn[        U UUS9nUR                  U5        [        [        R                  /UQ76   g)z}Run conda config --set ssl_verify false.

Setting this parameter to false disables all
SSL verification for conda activities
)rl   rL   r{   rk   Nr   r   s        r'   _set_ssl_verify_falser      s?     3K)%!
 ().+.r3   c                ~    / SQn[        U UUS9nUR                  U5        [        [        R                  /UQ7SS06  g)zRuns conda config --set restore_free_channel false.

The free channel is provided by Commercial Edition as
and should be added directly.)rl   restore_free_channelr{   rk   use_exception_handlerTNr   r   s        r'   _unset_restore_free_channelr     sD     =K)%!
 ()J+JTJr3   c                    [        [        U 5      nU(       a  SOSSU/n[        UUUS9nUR                  U5        [	        [
        R                  /UQ76   g)z<Adds a named Commercial Edition channel to default_channels.z	--prependz--appenddefault_channelsrk   N)r   rR   r>   rr   r(   r   rs   )rZ   prependr:   r;   r<   channel_urlr=   rv   s           r'   _set_channelr     s^     (G,K JK *%!
 ().+.r3   c                   SU S/n[        UUUS9nUR                  U5        [        R                  " 5       n[        R
                  " U5         [        [        R                  /UQ76   SSS5         [        R                  " UR                  5       5      nUR                  S0 5      R                  X5      $ ! , (       d  f       NT= f! [        R                   a    0 n NJf = f)Retrieve the existing default_channels from the user's `.condarc` file.

If the user does not have a "default_channels" section, an empty list is returned.

z--getz--jsonrk   Nget)r>   rr   ioStringIO
contextlibredirect_stdoutr(   r   rs   jsonloadsgetvalueJSONDecodeErrorr   )	keydefaultr:   r;   r<   r=   rv   	string_ioresults	            r'   _get_from_condarcr   7  s     C*K)%!
 () I		#	#I	.HOO2k2 
/I..01 ::eR $$S22 
/	.
  s   B61$C 6
CC C c                    [        S/ U UUS9$ )r   r   )r   r:   r;   r<   )r   rk   s      r'   _get_default_channelsr   Y  s      %! r3   c                   SS/n[        U UUS9nUR                  U5        [        R                  " 5       n[        R
                  " U5          [        [        R                  /UQ76   SSS5        UR                  5       nSUR                  5       ;  a  [        U[        R                  S9  gg! [         a     NRf = f! , (       d  f       N\= f)zRuns conda config --remove-key default_channels

It is best to remove the default_channels in case they
are not set at the default values before configuring
Commercial Edition.
r|   r   rk   Nr   )file)r>   rr   r   r   r   redirect_stderrr(   r   rs   r   r   stripprintsysstderr)r:   r;   r<   r=   rv   err_io
err_strings          r'   _remove_default_channelsr   l  s     "#56K)%!
 () [[]F		#	#F	+	6+6 
, "Jj..00jszz* 1	  		 
,	+s*   B>B..
B;8B>:B;;B>>
Cc                    [        5       n U (       aO  [        R                  " S5        U  H  n[        R                  " SU 35        M     [        R                  " S5        O[        R                  " S5        [        R                  " SSS9$ )zJPrompt the user for whether they would like to set their default channels.z Existing default channels found:z- z@This action will override the existing default_channels setting.z-Prepared to set default channels in .condarc.zProceed?F)r   )r   r   r   r   ask)existing_default_channelscs     r'   _prompt_to_set_default_channelsr     sf     5 7 89*AMMBqc(# +N	
 	EF;;z511r3   c           	        [         R                  " S5        [        5       nU Vs/ s H  ofR                  [        5      PM     nn[        U5      [        [        /[        -   5      :X  a  [         R                  " S5        gU(       d  [        5       (       d  g[        XU5        [        5       (       a  [        SU UUS9(       a  [        XU5        [        [        SU UUS9  [         H  n[        USU UUS9  M     Uc  gU H>  nU[        ;   a  [        USU UUS9  M  [        S	U S
SR!                  [        5       35      e   gs  snf )ak  Configure the default_channels to utilize only Commercial Edition.


This function performs the following actions
1. unset default_channels if it exists in the condarc
2. unset restore_free_channel if it exists in the condarc
3. Add the main, r, and msys2 channels to default_channels
4. Optionally add any of the archive channels:
   free, pro, mro, mro-archive
z+Configuring your [cyan].condarc[/cyan] filez3Default channels already configured, nothing to do.Nr   rk   T)r   r:   r;   r<   FzThe archive channel z is not one of z, )r   r   r   removeprefixrR   setMAIN_CHANNELACTIVE_CHANNELSr   r   rB   r   r   r   ARCHIVE_CHANNELS
ValueErrorr   )r:   r;   r<   include_archive_channelsforcer   r   %existing_default_channels_short_namess           r'   configure_default_channelsr     sU   " MM?@ 5 7 +D-*CQx *C * - 01S	(6  	KL466^,G!!&7%!	' 	$NN%! )#%	
   '%  -') &qcCS9T8UV  &U-s   Ec                     [        5       $ )zReturn a dictionary of tokens for all configured repository urls.

Note that this function will return tokens configured for non-Commercial Edition
urls.r   r,   r3   r'   
token_listr     s    
   r3   c                f    [        [        5        [        XU5        [        XU5        [	        5         g)zCompletely remove the Commercial Edition token and default_channels.

This function performs three actions.
1. Remove the token
2. Remove the custom default_channels in the condarc
3. Disable package signature verification
4. Run conda clean -i
N)r   rR   r   r}   rE   )systemenvr   s      r'   token_remover     s%     "V$/T2Mr3   c                    [        [        5        [        [        U 5        [        XU5        U(       a  [	        XU5        U(       a  [        XU5        [        XX4US9  [        5         g)a.  Set the Commercial Edition token and configure default_channels.


This function performs 4 actions.
1. Remove previous Commercial Edition token if present.
2. Add token.
3. Configure default_channels in the condarc file.
4. Optionally enable Conda package signature verification
5. Run conda clean -i
)r   N)r   rR   r   r   r   ry   r   rE   )rS   r   r   r   r   rX   enable_signature_verificationr   s           r'   	token_setr     sL    ( "h&F.f40$"65vDRWXMr3   )r%   r   r&   r   returnint)FFN)r:   boolr;   r   r<   
str | Noner   z	list[str])r   r   )r   None)F)rS   rT   rX   r   r   r   )rd   r   r   r   )r:   r   r;   r   r<   r   r   r   )TFFN)rZ   rT   r   r   r:   r   r;   r   r<   r   r   r   )NFFN)r   rT   r   r   r:   r   r;   r   r<   r   r   r   )FFNNF)r:   r   r;   r   r<   r   r   list[str] | Noner   r   r   r   )r   zdict[str, str])r   r   r   r   r   r   r   r   )FFNNFFF)rS   rT   r   r   r   r   r   r   r   r   rX   r   r   r   r   r   r   r   )T__doc__
__future__r   r   r   r   osr   r    os.pathr   r   r   typingr   urllib.parser   condaconda.gateways.logging
conda.baser	   rK   	conda.clir
   r$   conda.exceptionsr   conda.gateways.anaconda_clientr   r   r   !conda.gateways.connection.sessionr   conda.models.channelr   	packagingr   rich.promptr   anaconda_auth._conda.conda_apir   anaconda_auth._conda.condarcr   anaconda_auth._conda.configr   anaconda_cli_baser   rA   __version__r@   getenvrR   r   r   r   user_rc_pathreplaceescaped_user_rc_pathprefixescaped_sys_rc_pathr(   RuntimeErrorr*   UserWarningr6   r>   rB   rE   r\   rh   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r,   r3   r'   <module>r      sN   #  	  	 
          0 ( * > ? < : (   3 0 ? %e//099+-PQ.1 z,/0#++C6 d3::z:;CCCN +	l 		+ 	
 !#  	$2"
J$ !#555 5 
	5B !#      
	 H !#/// / 
	/. !#/// / 
	/. !#KKK K 
	K.  #/// / 	/
 / 
/8  #3	33 3 	3
 3 	3F !#  	( !#+++ + 
	+D2" !#15KKK K /	K
 K 
K\! AE#3=	& 15*/    
  	 
 /    $(    
 r3   