
    i_'                       S SK Jr  S SKJr  S SKJ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  \R*                  " SS9r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r      SAS jrSBS jr\R=                  SSS9SCS j5       r\RA                  SS9SCS j5       r!\RA                  S S9\RD                  " S!S"S#9\RF                  " S!S$S%S&S#9\RF                  " SS'S#9\RF                  " S(S)S*S+S#94         SDS, jj5       r$\RA                  S-S9\RF                  " S(S.S#94   SES/ jj5       r%\RA                  S0S9\RF                  " S!S$S%5      \RF                  " S(S1S25      4     SFS3 jj5       r&\RA                  S4S9\RD                  " S5S"S#9\RF                  " S!S$S%S&S#9\RF                  " SS'S#9\RF                  " S!S6S7S8S#9\RF                  " S(S9S:S;S#9\RF                  " SS<S=S&S#94             SGS> jj5       r'\RA                  S?S9\RF                  " S!S6S7S8S#9\RF                  " S(S9S:S;S#9\RF                  " SS<S=S&S#94       SHS@ jj5       r(g)I    )annotations)datetime)UUIDN)	BaseModel)Confirm)Table)
BaseClient)	RepoToken)	TokenInfo)console)select_from_listtoken)namec                  *    \ rS rSr% S\S'   S\S'   Srg)TokenInfoResponse   r   idr   
expires_at N__name__
__module____qualname____firstlineno____annotations____static_attributes__r       2lib/python3.13/site-packages/anaconda_auth/repo.pyr   r      s    Hr   r   c                  *    \ rS rSr% S\S'   S\S'   Srg)TokenCreateResponse   strr   r   r   r   Nr   r   r   r   r    r       s    Jr   r    c                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)	OrganizationData   r   r   r"   r   titler   Nr   r   r   r   r$   r$      s    H
IJr   r$   c                  *    \ rS rSr% S\S'   S\S'   Srg)SubscriptionData$   r   org_idr"   product_coder   Nr   r   r   r   r(   r(   $   s    Lr   r(   c                  J    \ rS rSrS	S jrS
S jrSSS jjrSS jrSS jrSr	g)RepoAPIClient)   c                    U R                  SU S35      nUR                  S:X  a  gUR                  5         [        S0 UR	                  5       D6$ )zReturn the token information, if it exists.

Args:
    org_name: The name of the organization.

Returns:
    The token information, including its id and expiration date, or
    None if a token doesn't exist.
/api/organizations//ce/current-tokeni  Nr   )getstatus_coderaise_for_statusr   jsonselforg_nameresponses      r   _get_repo_token_info"RepoAPIClient._get_repo_token_info*   sR     88!(+<=
 3&!!# 38==?33r   c                `    U R                  SU S3SS0S9n[        S0 UR                  5       D6$ )zCreate a new repo token.

Args:
    org_name: The name of the organization.

Returns:
    The token information, including its value and expiration date.
r0   r1   confirmyes)r5   r   )putr    r5   r6   s      r   _create_repo_token RepoAPIClient._create_repo_token<   sB     88!(+<=U#  
 #5X]]_55r   c                t   U R                  US9nUbh  U(       da  [        R                  " SU S35        [        R                  " S5        [        R                  " SSS9nU(       d  [
        R                  " 5       eU R                  US9n[        R                  " SUR                   S	35        UR                  $ )
z/Issue a new repository token from anaconda.com.r8   z<An existing token already exists for the organization [cyan]z[/cyan].zhReissuing a new token will revoke and deactivate any existing token access. This action can't be undone.zProceed?F)defaultz6Your conda token has been installed and expires [cyan]zL[/cyan]. To view your token(s), you can use [cyan]anaconda token list[/cyan])
r:   r   printr   asktyperAbortr@   r   r   )r7   r8   r>   existing_token_infoshould_continuer9   s         r   issue_new_tokenRepoAPIClient.issue_new_tokenK   s    "777J*3MMNxjX`a MMz &kk*eDO"kkm#**H*=DXEXEXDY  Zf  g	
 ~~r   c                    U R                  S5      nUR                  5         UR                  5       nU Vs/ s H  n[        S0 UD6PM     sn$ s  snf )z4Get a list of all organizations the user belongs to.z/api/organizations/myr   )r2   r4   r5   r$   )r7   r9   dataitems       r   get_organizations_for_user(RepoAPIClient.get_organizations_for_usera   sI    8834!!#}}59:TT (4(T:::s   Ac                N   U R                  5       nU R                  R                  S/ 5       Vs/ s H  n[        S0 UD6PM     nnU Vs/ s H!  nSUR                  ;  d  M  UR
                  PM#     nnU Vs/ s H  oUR                  U;   d  M  UPM     sn$ s  snf s  snf s  snf )zVGet a list of all organizations the user belongs to that have a Business subscription.subscriptionsstarterr   )rP   accountr2   r(   r+   r*   r   )r7   organizationssubrS   business_subscription_org_idsorgs         r   #get_business_organizations_for_user1RepoAPIClient.get_business_organizations_for_userh   s    779/3||/?/?QS/T
/T#s#/T 	 
 #0)
"/39CDTDT3TJCJJ- 	& )
  -X}:W0W}XX
)
 Ys   B
B"B8B"B"r   N)r8   r"   returnzTokenInfoResponse | None)r8   r"   r\   r    )F)r8   r"   r>   boolr\   r"   )r\   zlist[OrganizationData])
r   r   r   r   r:   r@   rK   rP   rZ   r   r   r   r   r-   r-   )   s    4$6,;	Yr   r-   c                   [        SSS9nUR                  S5        UR                  S5        UR                  S5        SSKJn  U  H:  nU UR                   S	3nUR                  UR                  XTR                  5        M<     UR                  5        H  u  pgUR                  S Xg5        M     [        R                  " U5        g )
NzAnaconda Repository Tokensgreen)r&   title_styleOrganizationzChannel URLTokenr   )REPO_URLz/*)
r   
add_column anaconda_auth._conda.repo_configrc   r8   add_rowr   itemsr   rE   )tokenslegacy_tokenstablerc   
repo_tokenchannel_urlurlr   s           r   _print_repo_token_tablern   t   s     4'JE	^$	]#	W9
!
:#6#6"7r:j));8H8HI  $))+
dC' , MM%r   c                   U R                  5       nU(       d+  [        R                  " S5        [        R                  " 5       e[        U5      S:X  a*  US   R                  n[        R                  " SU 35        U$ 0 n/ nU H>  nUR                   SUR                   S3nUR                  X6'   UR                  U5        M@     [        SUS9nX7   $ )	NzNo organizations found.   r   z6Only one organization found, automatically selecting: z ([cyan]z[/cyan])zPlease select an organization:)choices)
rZ   r   rE   rG   rH   lenr   r&   appendr   )clientrV   r8   name_maprq   rY   key	org_titles           r   _select_org_namerx      s    >>@M/0kkm
=Q #((DXJO	
 HG8CHH:X6s 
 !(I r   T)invoke_without_commandno_args_is_helpc                     g)z!Manage your Anaconda repo tokens.Nr   r   r   r   mainr|      s    r   listc                     SSK Jn   U " 5       n[        R                  " SS9nUR                  nU(       d2  U(       d+  [
        R                  " S5        [        R                  " 5       e[        X1S9  g)z%List all installed repository tokens.r   )
token_listTcreatezFNo repo tokens are installed. Run [cyan]anaconda token install[/cyan].)rh   ri   N)
re   r   r   loadrepo_tokensr   rE   rG   rH   rn   )r   rh   
token_infor   s       r   list_tokensr      sQ     <\Ft,J((KkT	
 kkm;Er   install zBOptionally, provide the token received via email or web interface.)helpz-oz--orgzOrganization name (slug).z)Automatically configure default channels.Fz-yz--yeszAccept all promptsc                   [        5       nU(       d  [        U5      nU (       d  UR                  XS9n SSKJn   UR                  U SS9  [        R                  " SS9nUR                  X5        UR                  5         S	nU(       a  UR                  US
9  US-  n[        R                  " SU S35        g! UR                   a  n[        R                  " U5      eSnAff = f)z*Create and install a new repository token.)r8   r>   r   repo_configF)no_ssl_verifyNTr   z+Your token has been installed and validatedforcez, and conda has been configuredz	Success! .)r-   rx   rK   anaconda_auth._condar   validate_tokenCondaTokenErrorrG   rH   r   r   set_repo_tokensaveconfigure_default_channelsr   rE   )	r   r8   set_default_channelsr>   rt   r   er   msgs	            r   install_tokenr      s     _F#F+&&&B0""5"> t,Jh.OO
7C..S.900MMIcU!$% && kk!ns   B7 7C"CC"configz7Force configuration of default channels without prompt.c                .    SSK Jn  UR                  U S9  g)zKConfigure conda's default channels to access Anaconda's premium repository.r   r   r   N)r   r   r   )r   r   s     r   configure_condar      s     1***7r   	uninstallz-az--allc                   [         R                  " 5       nU(       a7  UR                  5         UR                  5         [        R
                  " S5        gU (       d+  [        R
                  " S5        [        R                  " 5       eUR                  U S9  UR                  5         [        R
                  " SU  S35        g)z9Uninstall a repository token for a specific organization.z2Successfully deleted [cyan]all[/cyan] repo tokens.Nz4Must explicitly provide an [cyan]--org[/cyan] optionrC   z3Successfully deleted token for organization: [cyan]z[/cyan])	r   r   delete_all_repo_tokenr   r   rE   rG   rH   delete_repo_token)r8   allr   s      r   uninstall_tokenr      s     !J
((*JKLMkkm  ( 3OOMM
=hZwOr   set.z-fz--filez2Write to the system .condarc file at '~/.condarc'.z-ez--envz}Write to the active conda environment .condarc file. If no environment is active, write to the user config file (~/.condarc).z-sz--systemc                R    U(       a
  [        XUS9  SSKJn  UR                  XXES9  g)zInstall a new repository token.)r   r8   r   r   r   )r   fileenvsystemN)r   r   r   	token_set)r   r8   r   r   r   r   r   s          r   	set_tokenr     s-    . AU	
 1cIr   removec                0    SSK Jn  UR                  XUS9  g)z+Remove binstar token and data from Keyring.r   r   )r   r   r   N)r   r   token_remove)r   r   r   r   s       r   remove_tokenr   ,  s      1$?r   )rh   zlist[RepoToken]ri   zdict[str, str]r\   None)rt   r-   r\   r"   )r\   r   )
r   r"   r8   r"   r   r]   r>   r]   r\   r   )r   r]   r\   r   )r8   r"   r   r]   r\   r   )r   r"   r8   r"   r   r]   r   r"   r   r]   r   r]   r\   r   )r   r"   r   r]   r   r]   r\   r   ))
__future__r   r   uuidr   rG   pydanticr   rich.promptr   
rich.tabler   anaconda_auth.clientr	   anaconda_auth.tokenr
   r   anaconda_cli_baser   anaconda_cli_base.consoler   Typerappr   r    r$   r(   r-   rn   rx   callbackr|   commandr   ArgumentOptionr   r   r   r   r   r   r   r   <module>r      s   "       + ) ) % 6kkw	 
) 
y y 
HYJ HYV,:	*8 T4@, A, &F F$ )
U LLT79TU!&>" UD'8LM$&$& 	$&
 $& 
$& 
$& $&N (,,M88 
	8 8 +LLT73UD'2	 
 4 %V LLT79TU!&>" 
D(!U  M	 <<dJ%@#JJ 	J
 J J 
J" #J( 
)J J> (
D(!U  M	 <<dJ%@@
@ 
	@ @ 
@ @r   