
    e                         d Z ddlmZmZ ddlZddlZddlZddlZddlmZ ddl	m	Z	m
Z
 ddlmZ dd	lmZ  ej        d
          Z G d de          ZdS )z+
Manage your Anaconda repository channels.
    )print_functionunicode_literalsN)FileType)datetime	timedelta   )errors   )SubCommandBaserepo_clic                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )

SubCommandauthc                    | j         j        r|                                  d S | j         j        r|                                  d S | j         j        r!|                     | j         j                   d S | j         j        r|                                  d S | j         j	        r7| 
                    | j         j        | j         j        | j         j                   d S d S )N)argsinfoshow_token_infolistshow_tokensremoveremove_tokenslist_scopesshow_scopescreatecreate_tokennamescopesmax_age)selfs    6lib/python3.11/site-packages/repo_cli/commands/auth.pymainzSubCommand.main   s    9> 	S  """""Y^ 		SFY 	Sty/000FY" 	SY 	Sdindi.>	@QRRRRR	S 	S    c                    | j         j        s| j        j                                         | j         j        s| j                            d           d S |sy| j                            d           | j                            d| j        j        j        z             | j                            d           | j         	                                }t          t          j                                                    t          |          z             }| j                             |||d           }| j                            d                    |d         |d	                              d S )
NFailed to authenticate...zLYou have not specified the scope of this token with the '--scopes' argument.z1This token will grant full access to %s's accountz=Use the --list-scopes option to see a listing of your options)seconds)r   	resourcesz*Token {0} succesfully created with id: {1}tokenid)api_jwtparentauth_managerinteractive_get_tokenlogr   warningusername
get_scopesstrr   nowdater   create_user_tokenformat)r   r   r   r   
expirationdatas         r    r   zSubCommand.create_token%   sk   x} 	=K$::<<<x} 	HMM5666F 	+H^   HC;+46   HO   X((**F,,..71K1K1KKLL
x))*Vt * 
 
 	8??WtDz 	
 	
 	
 	
 	
r"   c                 |   | j                                         }| j                            d           | j                            d           | j                            d           | j                            d                    t          |                               | j                            d           d S )N zAvailable scopes:,)r)   r1   r.   r   joinsorted)r   r   s     r    r   zSubCommand.show_scopesD   s    $$&&b)***bchhvf~~..///br"   c                 ~    |D ]9}| j                             |           | j                            d|z             :d S )NzToken %s successfully removed.)r)   remove_user_tokenr.   r   )r   tokensr'   s      r    r   zSubCommand.remove_tokensL   sR     	D 	DEH&&u---HMM:UBCCCC	D 	Dr"   c                 Z   | j         j        st          j                    | j                                         }| j                            d           | j                            d| j         j        z             | j                            d|                    dd          z             d S )Nr:   z	Token: %szExpiration: %s
expires_atzn/a)r)   _access_tokenr	   Unauthorizedget_token_infor.   r   get)r   r8   s     r    r   zSubCommand.show_token_infoQ   s    x% 	(%'''x&&((bkDH$::;;;&,)F)FFGGGGGr"   c                    | j         j        s| j        j                                        }| j         j        s| j                            d           d S | j                                         }|rT| j                            d           | j                            dt          |d                   z             |d         D ]}| j                            d           | j                            d|d         z             | j                            d|d	         z             | j                            d
|d         z             | j                            d|d         z             | j                            d|d         z             | j                            d           | j                            d           d S d S )Nr$   r:   zTokens count: %sitemsz-----------------zid: %sr(   zname: %sr   zcreated_at: %s
created_atzexpires_at: %srB   ztype: %stype)	r)   r*   r+   r,   loginr.   r   get_user_tokenslen)r   r'   r8   s      r    r   zSubCommand.show_tokensY   s   x} 	5K,2244Ex} 	HMM5666Fx'')) 	HMM"HMM,s4=/A/AABBBg 3 31222ht4555j5=8999.|1DDEEE.|1DDEEEj5=899912222HMM"	 	r"   c           
      b   d}|                     | j        ||t          t          j                  }|                    dddt          j                    z  d           |                    dd	          }d
}d|z  }|                    dt          |d|d|d           |                    ddddg            |                    dt          j        t          d                     |                    d          }|                    d          }|                    dddd            |                    d!d"dd#            |                    d$d%d&d'd()           |                    d*d+dd,            |                    d-d.d/d0dd12           |                    | j        3           d S )4NzManage Authorization Tokens)helpdescriptionepilogformatter_classz-nz--namezconda_repo:%sz3A unique name so you can identify this token later.)defaultrO   ztoken creation argumentsz9These arguments are only valid with the `--create` action   iQ z	--max-agezOThe maximum age in seconds that this token will be valid for (default value is z that equals to z days)rJ   rS   rO   z-sz--scopesappendzScopes for token. For example if you want to limit this token to conda downloads only you would use --scopes "repo artifact:download")actionrO   rS   z--outw)rS   rJ   actionsT)requiredz-xz--list-scopes
store_truezlist all authentication scopes)rV   rO   z-lz--listz#list all user authentication tokensz-rz--removeID+zremove authentication tokens)metavarnargsrO   z-cz--createzCreate an authentication tokenz-iz--infoz--current-infor   z7Show information about the current authentication token)destrV   rO   )r!   )
add_parserr   __doc__argparseRawDescriptionHelpFormatteradd_argumentsocketgethostnameadd_argument_groupintsysstdoutr   add_mutually_exclusive_groupset_defaultsr!   )r   
subparsersrP   parsergage_in_daysdefault_agegroups           r    r`   zSubCommand.add_parserr   sN   3&&I#$@ ' 
 
 	#v'9';';<F	 	 	
 	
 	
 %%&G
 
 k)	K,7KKF	 	 	
 	
 	
 	
Q  	 		
 		
 		
 	
w
#GGG)))4422D2AA1	 	 	
 	
 	
 	6	 	 	
 	
 	
 	/ 	 	
 	
 	
 	*\8X 	 	
 	
 	
 	J 	 	
 	
 	
 	+++++r"   N)__name__
__module____qualname__r   r!   r   r   r   r   r   r`    r"   r    r   r      s        DS S S
 
 
>  D D D
H H H  2X, X, X, X, X,r"   r   )ra   
__future__r   r   rb   loggingre   ri   r   r   r   r:   r	   baser   	getLoggerloggerr   rv   r"   r    <module>r|      s     8 7 7 7 7 7 7 7    



       ( ( ( ( ( ( ( (                  		:	&	&v, v, v, v, v, v, v, v, v, v,r"   