
    e                         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mZ ddlmZmZmZmZ  ej        d          Zd	 ZddZd Zd Zd ZdS )zAuthenticate a user.    )unicode_literalsN)input)urlparse)errors)
get_configget_server_apistore_token
bool_inputzbinstar.loginc                    	  | di |S # t           j        $ r}|                    dd          rt          |j                  dk    r|j        d         dk    rt
                              dt          j                               t
                              d           t
                              d           t          d	          rd|d<    | di |cY d
}~S  d
}~ww xY w)zYAuthenticates using the given *authenticate*, retrying if the token needs to be replaced.fail_if_already_existsF      i  z1It appears you are already logged in from host %szyLogging in again will remove the previous token. (This could cause troubles with virtual machines with the same hostname)zPOtherwise you can login again and specify a different hostname with "--hostname"zWould you like to continueN )
r   BinstarErrorgetlenargsloggerwarningsocketgethostnamer
   )authenticatekwargserrs      =lib/python3.11/site-packages/binstar_client/commands/login.pytry_replace_tokenr      s   |%%f%%%   ::.66 	.CMMQ<N<NUXU]^_U`dgUgUgNNNPVPbPdPdeeeNN*   NNmnnn677 .38/0#|--f--------s!   
 CB:CCCCTc           
         t          | j        | j                  }t          | j                  }d }t	          | dt          j                              }| j        p|                    d          }|                    dd          }d}|r|dvr|d|z  z  }|t          j	                    d	|z  }|
                                 |                                }	|	d
k    r1t          |j        ||||          }|t          j        d          n9t	          | dd           r| j        }
nt#          d          }
t	          | dd           }t%          d          D ]}	 t&          j                            d|
z             |t          j        t&          j                  }t          |j        |
|||||          } n1# t          j        $ r t0                              d           d }Y w xY w|[t5          |          }|j                            d          rd}n|j        }|j        |f}dd|z  z   dz   }t          j        |          |S )N)sitehostnamedefault_siteurlzhttps://api.anaconda.orgzbinstar_client:)binstaranacondaz%s:@kerberos)applicationapplication_urlr   r   zUUnable to authenticate via Kerberos. Try refreshing your authentication using `kinit`login_usernamez
Username: login_password   z%s's )stream)usernamepasswordr&   r'   r   r   z7Invalid Username password combination, please try againzapi.anaconda.orgzanaconda.orgzSorry. Please try again z'(go to %s://%s/account/forgot_password zto reset your password))r   tokenr   r   getattrplatformnoder   getpassgetusercheck_serverauthentication_typer   krb_authenticater   r   r(   r   rangesysstderrwriter   Unauthorizedr   errorr   netloc
startswithscheme)r   r   
api_clientconfigr.   r   r   r!   	auth_name	auth_typer,   r-   _
parsed_urlr=   	hostpartsmsgs                    r   interactive_get_tokenrH   ,   s   
DI66JTY'''FE tZ99H92

>22D
**U6
7
7C!I "333UT\!	GO----xx88I..00IJ!'!#9
 
 
 =%g   
 4)400 	+*HH\**H4!1488q 	 	A
  8!3444#&cjAAAH)+%% )$'+A%   &   VWWW
 =!#J ++,>?? +'#*#*F3I-<yHI,-C %c***Ls   AF;;+G)(G)c                 x    t          |           }t          ||            t                              d           d S )Nzlogin successful)rH   r	   r   info)r   r.   s     r   interactive_loginrK   |   s8    !$''Et
KK"#####    c                 $    t          |            d S )N)rK   )r   s    r   mainrN      s    drL   c                 (   |                      ddt                    }|                    dt          j                    d           |                    ddd	
           |                    ddd
           |                    t                     d S )NloginzAuthenticate a user)helpdescriptionz
--hostnamezQSpecify the host name of this login, this should be unique (default: %(default)s))defaultrQ   z
--usernamer(   zASpecify your username. If this is not given, you will be prompted)destrQ   z
--passwordr)   zASpecify your password. If this is not given, you will be prompted)rN   )
add_parser__doc__add_argumentr0   r1   set_defaultsrN   )
subparsers	subparsers     r   rU   rU      s    %%g4IW^%__I< s  u u u<.> c  e e e<.> c  e e e%%%%%rL   )T)rV   
__future__r   r2   loggingr0   r   r8   	six.movesr   six.moves.urllib.parser   binstar_clientr   binstar_client.utilsr   r   r	   r
   	getLoggerr   r   rH   rK   rN   rU   r   rL   r   <module>rb      s     ' ' ' ' ' '     



       + + + + + + ! ! ! ! ! ! T T T T T T T T T T T T		?	+	+  ,M M M M`$ $ $  & & & & &rL   