ó
>ò†[c           @  s  d  Z  d d l m Z d d l 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	 d d l
 Z
 d d l m Z d d l m Z d d l m Z d d	 l m Z e j d
 ƒ Z d Z d „  Z e d „ Z d „  Z d „  Z d „  Z d S(   sy   
Manage Authentication tokens

See also:

  * [Using Anaconda Cloud Tokens](http://docs.anaconda.org/using.html#Tokens)

iÿÿÿÿ(   t   print_functionN(   t   FileType(   t   datetime(   t   parse(   t   input(   t   errors(   t   get_server_apis   binstar.authsâ   

Examples

To allow access to only conda downloads from your account you can run:

    anaconda auth --create --scopes 'repos conda:download'

To allow full access to your account:

    anaconda auth --create --scopes 'all'

c          C  s   t  j ƒ  }  |  j d t j ƒ S(   Nt   tzinfo(   R   t   utcnowt   replacet   pytzt   utc(   t   now(    (    se   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/authorizations.pyR   /   s    c         C  sÛ   |  s
 d St  ƒ  } |  | k  r> | r) d S|  } | }  | } n  |  | } | j r | j | j d } | d k r… t | ƒ } d | Sd | SnG | j d k r® d	 | j d S| j d k rÌ d
 | j d Sd | j Sd  S(   Nt   Nevert   expiredg      N@g      8@i   s   %i dayss	   %.1f daysi<   s
   %.1f hourss
   %i minutess
   %i secondsg      ¬@g     õ@i  g      ¬@(   R   t   dayst   secondst   int(   t   dateR   R   t   tmpt   deltaR   (    (    se   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/authorizations.pyt   format_timedelta4   s*    		
	c      	   C  s‹  i d d 6d d 6d d 6d d 6d	 d
 6d d 6} d } t  j d ƒ t  j | | ƒ t  j d d d d d d d d d d d f ƒ xý |  D]õ } | d
 r± t | d
 ƒ } n d  } t | ƒ | d
 <t } | d } | rhx£ | D]} } | r| | d <t  j | | ƒ t } qä d | d <d | d <d | d <d | d <d | d
 <| | d <t  j | | ƒ qä WqŽ d | d <t  j | | ƒ qŽ Wd  S(   Nt   IDt   idt   Applicationt   applications   Remote Addrt   remote_addrt   Hostt   hostnames
   Expires Int   expirest   Scopest   scopessf   %(id)-25s | %(application)-35s | %(remote_addr)-20s | %(hostname)-25s | %(expires)-15s | %(scopes)-25st    s   %s-+-%s-+-%s-+-%s-+-%s-+-%st   -i   i#   i   i   t   NO_SCOPEs   --------------------s   ---------------(   t   loggert   infot
   parse_datet   NoneR   t   Truet   False(   t   authenticationst   headert   templatet   authR   t
   first_timet   scope_itemst   scope(    (    se   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/authorizations.pyt
   show_authsS   s@    

3


	






c         C  sO  t  |  j |  j ƒ } |  j rW | j ƒ  } t j d | d ƒ t j d | d ƒ n  |  j rt t | j ƒ  ƒ d  S|  j	 r¹ x5 |  j	 D]* } | j
 | |  j ƒ t j d | ƒ q‡ Wd  S|  j r$| j ƒ  } xC t | ƒ D]5 } t j | ƒ t j d | | ƒ t j d ƒ qÛ Wt j t ƒ n'|  j rK| j ƒ  } y | j ƒ  } | d } WnS | d	 k rvt j d
 ƒ d  Sd  } t j j d ƒ t j j ƒ  t d ƒ } n Xg  |  j D] } | j ƒ  D] }	 |	 ^ qÃq³} | st j d ƒ t j d |  j p | ƒ t j d ƒ n  x3t d ƒ D]"}
 yõ | d	 k r‘| j d  |  j d |  j d | d |  j d |  j  d d j! t j" ƒ d |  j# d t$ ƒ} nz t j j d | ƒ t% j% ƒ  } | j& | | |  j d |  j d | d |  j d |  j  d d j! t j" ƒ d |  j# d t$ ƒ} |  j' j | ƒ PWq"t( j) k
 rCt j d ƒ q"q"Xq"Wn  d  S(   Ns   Name: %sR   s   Id: %sR   s   Removed token %ss     R    t   logint   kerberossK   Kerberos authentication needed, please use 'anaconda login' to authenticates
   Username: sL   You have not specified the scope of this token with the '--scopes' argument.s1   This token will grant full access to %s's accounts=   Use the --list-scopes option to see a listing of your optionsi   t   application_urlR   t   for_usert   max_aget   created_witht    t   strengtht   fail_if_already_existss   Please re-enter %s's s7   Invalid Username password combination, please try again(*   R   t   tokent   siteR$   t   authenticationR#   t   listR0   R)   t   removet   remove_authenticationt   organizationt   list_scopest   sortedt   SCOPE_EXAMPLESt   createt   authentication_typet   usert   errorR&   t   syst   stderrt   writet   flushR   R   t   splitt   warningt   ranget   _authenticatet   namet   urlR5   t   joint   argvR8   R'   t   getpasst   authenticatet   outR   t   Unauthorized(   t   argst   aserver_apit   datat	   auth_nameR   t   keyt	   auth_typet   current_usert   usernameR/   t   _R:   t   password(    (    se   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/authorizations.pyt   main|   sˆ    					/											c         C  s?  d } |  j  d d | d | d t d t j ƒ} | j d d d	 d
 t j ƒ  d d ƒ| j d d d d d d d ƒ| j d d ƒ } | j d d d d g d	 d d d ƒ| j d d d d d d d d d ƒ| j d d d d d d d d d d  ƒ| j d! d	 d" d d# ƒ| j d$ d% t d d& ƒ| j d' d( d d) d d* d	 g  ƒ| j d+ d	 t	 j
 d% t d, ƒ ƒ| j d- ƒ } | j d. t ƒ } | j d/ d0 d d1 d d2 ƒ| j d3 d4 d d1 d d5 ƒ| j d6 d7 d8 d9 d: d; d d< ƒ| j d= d> d d1 d d? ƒ| j d@ dA dB d dC d d1 d dD ƒ| j dE t ƒ d  S(F   Ns   Manage Authorization TokensR,   t   helpt   descriptiont   epilogt   formatter_classs   -ns   --namet   defaults   binstar_token:%ssd   A unique name so you can identify this token later. View your tokens at anaconda.org/settings/accesss   -os   --orgs   --organizations-   Set the token owner (must be an organization)t   destR@   s   token creation argumentss9   These arguments are only valid with the `--create` actions
   --strengtht   choicest   strongt   weakR8   s   --strongt   actiont   store_constt   consts   Create a longer token (default)s   -ws   --weaks   Create a shorter tokens   --urls   http://anaconda.orgs3   The url of the application that will use this tokens	   --max-aget   types<   The maximum age in seconds that this token will be valid fors   -ss   --scopest   appends‚   Scopes for token. For example if you want to limit this token to conda downloads only you would use --scopes "repo conda:download"s   --outt   wt   actionst   requireds   -xs   --list-scopest
   store_trues   list all authentication scopess   -ls   --lists#   list all user authentication tokenss   -rs   --removet   metavart   NAMEt   nargst   +s   remove authentication tokenss   -cs   --creates   Create an authentication tokens   -is   --infos   --current-infoR$   s7   Show information about the current authentication tokenRb   (   t
   add_parsert   __doc__t   argparset   RawDescriptionHelpFormattert   add_argumentt   sockett   gethostnamet   add_argument_groupR   RH   t   stdoutR   t   add_mutually_exclusive_groupR'   t   set_defaultsRb   (   t
   subparsersRd   t   parsert   gt   group(    (    se   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/authorizations.pyRy   Ë   s8    %%("(   Rz   t
   __future__R    R{   RT   t   loggingR~   RH   R   R   R
   t   dateutil.parserR   R%   t	   six.movesR   t   binstar_clientR   t   binstar_client.utilsR   t	   getLoggerR#   RC   R   R'   R   R0   Rb   Ry   (    (    (    se   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/authorizations.pyt   <module>   s(   		)	O