
                            S 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r\R"                  " \R$                  R&                  \R$                  R(                  5       " S S\R*                  5      5       r\R"                  " \R$                  R.                  5       " S S\R*                  5      5       rg)zcloud-shell ssh command.    )absolute_import)division)unicode_literalsN)base)util)ssh)log)
propertiesc                   >    \ rS rSrSrSSS.r\S 5       rS rS r	S	r
g
)Ssh   DAllows you to establish an interactive SSH session with Cloud Shell.        *{command}* lets you remotely log in to Cloud Shell. If your Cloud Shell
        is not currently running, this will cause it to be started before
        establishing the SSH session.
                To SSH into your Cloud Shell, run:

            $ {command}

        To run a remote command in your Cloud Shell, run:

            $ {command} --command=ls
        DESCRIPTIONEXAMPLESc                     [         R                  " U 5        U R                  SSS9  U R                  SSSS9  U R                  SS	S
S9  U R                  SSSS9  g Nz	--commandzj        A command to run in Cloud Shell.

        Runs the command in Cloud Shell and then exits.
        )helpz	--dry-runzs        If provided, prints the command that would be run to standard out
        instead of executing it.
        
store_true)r   actionz
--ssh-flagz*Additional flags to be passed to *ssh(1)*.appendz--authorize-sessiona          If provided, sends OAuth credentials to the current Cloud Shell session
        on behalf of the user. When this completes, the session will be
        authorized to run various Google Cloud command-line tools without
        requiring the user to manually authenticate.
        )r   ParseCommonArgsadd_argumentparsers    lib/surface/cloud_shell/ssh.pyArgsSsh.Args6   s     
       9          c           
      "   UR                   (       d  [        R                  " S5        UR                  (       a  UR                  R	                  S5      OS/n[
        R                  R                  R                  R                  5       n[        R                  " U5      nUR                   (       a  [        R                  " 5         [        R                  " [        R                  " UR                   UR"                  S9[$        R&                  " UR(                  5      UR*                  U(       a  SU-   /O/ U-   UR,                  UR                  (       + SS0S9nUR.                  (       ao  UR1                  UR2                  5      n[        R                  " SR5                  U Vs/ s H"  n[$        R6                  R9                  U5      PM$     sn5      5        g UR                   (       a  [:        R<                  " 5       U l        [:        R@                  " U RB                  S	S
9nSUl"        URG                  5         URI                  UR2                  5        U R>                  RK                  5         g URI                  UR2                  5        g s  snf )NAutomatic authentication with GCP CLI tools in Cloud Shell is disabled. To enable, please rerun command with `--authorize-session` flag. bash -lhostuserDEVSHELL_PROJECT_ID=StrictHostKeyCheckingno)remoteportidentity_fileremote_commandextra_flagsttyoptions targetargsT)&authorize_sessionr	   Printcommandsplitr
   VALUEScoreprojectGetr   PrepareEnvironmentAuthorizeEnvironmentr   
SSHCommandRemoter'   r(   six	text_typer-   keyssh_flagdry_runBuildssh_envjoinmovesshlex_quote	threadingEventdoneThreadReauthorizedaemonstartRunset	selfr6   command_listr=   connection_infor9   elemselemthreads	            r   rT   Ssh.RunU   s   !!	ii . / /3ll4<<%%c*L$$,,002G--d3O
!nnzz33/:N:NO]]?//0%))>E/'9:2MM($/	G ||mmO334e	ii%H%$#))//5%HIJ			//#dit'7'7bAffmllnkk/))*
iimmokk/))* Is   $)Jc                 ~   U R                   R                  5       (       d  U R                   R                  [        R                  [
        R                  " SS9-
  R                  5        U R                   R                  5       (       d  [        R                  " 5         U R                   R                  5       (       d  M  g g N   )minutes	rO   is_setwaitr   MIN_CREDS_EXPIRYdatetime	timedeltasecondsr@   rW   s    r   rQ   Ssh.Reauthorizew   y    ii  
iinn  8#5#5a#@@
I
IKYY!!#	 ii  r!   rO   N__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   rT   rQ   __static_attributes__r3   r!   r   r   r      s5    L-&  < +D$r!   r   c                   >    \ rS rSrSrSSS.r\S 5       rS rS r	S	r
g
)SshAlpha   r   r   r   r   c                     [         R                  " U 5        [         R                  " U 5        U R                  SSS9  U R                  SSSS9  U R                  SS	S
S9  U R                  SSSS9  g r   )r   r   AddSshArgFlagr   r   s    r   r   SshAlpha.Args   s     v
       9      r!   c                 ^   UR                   (       d  [        R                  " S5        UR                  (       a  UR                  R	                  S5      OS/n[
        R                  R                  R                  R                  5       n[        R                  " U5      nUR                   (       a  [        R                  " 5         [        R                  " [        R                  " UR                   UR"                  S9[$        R&                  " UR(                  5      UR*                  U(       a  SU-   /O/ U-   UR,                  UR                  (       + SS0UR.                  (       a  UR.                  OS S9nUR0                  (       ao  UR3                  UR4                  5      n[        R                  " SR7                  U Vs/ s H"  n[$        R8                  R;                  U5      PM$     sn5      5        g UR                   (       a  [<        R>                  " 5       U l         [<        RB                  " U RD                  S	S
9nSUl#        URI                  5         URK                  UR4                  5        U R@                  RM                  5         g URK                  UR4                  5        g s  snf )Nr#   r$   r%   r&   r)   r*   r+   )r,   r-   r.   r/   r0   r1   r2   	remainderr3   r4   T)'r7   r	   r8   r9   r:   r
   r;   r<   r=   r>   r   r?   r@   r   rA   rB   r'   r(   rC   rD   r-   rE   rF   ssh_argsrG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   s	            r   rT   SshAlpha.Run   s   !!	ii() /3ll4<<%%c*L$$,,002G--d3O
!nnzz33/:N:NO]]?//0%))" 0'9:(*l;MM($/#'==$--d
G ||mmO334e	ii%H%$#))//5%HIJ			//#dit'7'7bAffmllnkk/))*
iimmokk/))* Is   )J*c                 ~   U R                   R                  5       (       d  U R                   R                  [        R                  [
        R                  " SS9-
  R                  5        U R                   R                  5       (       d  [        R                  " 5         U R                   R                  5       (       d  M  g g r_   rb   ri   s    r   rQ   SshAlpha.Reauthorize   rk   r!   rl   Nrm   r3   r!   r   rw   rw      s5    L-&  >"+H$r!   rw   )rr   
__future__r   r   r   rf   rM   googlecloudsdk.callioper   &googlecloudsdk.command_lib.cloud_shellr   #googlecloudsdk.command_lib.util.sshr   googlecloudsdk.corer	   r
   rC   ReleaseTracksReleaseTrackGABETACommandr   ALPHArw   r3   r!   r   <module>r      s     &  '   ( 7 3 # * 
 D%%(($*;*;*@*@A\$$,, \$ B\$~ D%%++,_$t|| _$ -_$r!   