
    "                     h   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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r\R(                  " SS9rSR-                  \R.                  5      r " S S\R2                  5      rS rS rS rS r " S S\5      r  " S S\
RB                  5      r"g)z)Utilities shared by cloud-shell commands.    )absolute_import)division)unicode_literalsN)apis)waiter)ssh)
exceptions)log)storezusers/me/environments/default   )minutesz{}sc                       \ rS rSrSrSrg)UnsupportedPlatform'   zCRaised when attempting to run a command on an unsupported platform. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       2lib/googlecloudsdk/command_lib/cloud_shell/util.pyr   r   '   s    Kr   r   c                 H    U R                  SSSS9  U R                  SSSS9  g)z4Parses arguments common to all cloud-shell commands.z--force-key-file-overwriteav        If enabled gcloud will regenerate and overwrite the files associated
      with a broken SSH key without asking for confirmation in both
      interactive and non-interactive environment.

      If disabled gcloud will not attempt to regenerate the files associated
      with a broken SSH key and fail in both interactive and non-interactive
      environment.
      
store_true)helpactionz--ssh-key-filezf      The path to the SSH key file. By default, this is
        *~/.ssh/google_compute_engine*.
      N)add_argumentparsers    r   ParseCommonArgsr!   +   sF     	"
    	
   r   c                 D    U R                  S[        R                  SSS9  g )Nssh_argszW          Flags and positionals passed to the underlying ssh implementation.
          z"        $ {command} -- -vvv
      )nargsr   example)r   argparse	REMAINDERr   s    r   AddSshArgFlagr(   C   s+    
  r   c           	          [         R                  " SS5      n[         R                  " SS5      n[         R                  " SS5      n[        R                  R                  5       nUR                  5         [        R                  R                  U R                  S9nUR                  U R                  S9  UR                  R                  UR                  [        S95      nUR!                  5       R#                  5       nSnUR$                   H  n	Xy:X  d  M
  Sn  O   U(       d  UR                  R'                  UR)                  [        UR+                  US9S	95      n
[,        R.                  " [1        UR                  UR2                  5      U
S
SSS9n[4        R6                  " S5        [8        R:                  " S5        UR<                  UR                  R>                  R@                  :w  a  [4        R6                  " S5        SnU RC                  S5      (       a)  U RD                  (       a  [F        RH                  " [J        S9nUR                  RM                  URO                  [        URQ                  US9S95      n[,        R.                  " [1        UR                  UR2                  5      USSSS9nURR                  (       d  [T        RV                  " S5      e[Y        UURZ                  URR                  UR\                  UR^                  S9$ )zGEnsures that the user's environment is ready to accept SSH connections.
cloudshellv1)filename)	overwritenameFT)key)environmentaddPublicKeyRequestz&Pushing your public key to Cloud Shelli  N)sleep_msmax_wait_msz+Waiting for your public key to propagate...   z$Starting your Cloud Shell machine...authorize_sessionmin_expiry_durationaccessToken)r/   startEnvironmentRequestz-Waiting for your Cloud Shell machine to startz&The Cloud Shell machine did not start.ssh_envuserhostportr0   )0r   GetClientInstanceGetMessagesModuler   EnvironmentCurrent
RequireSSHKeysFromFilenamessh_key_fileEnsureKeysExistforce_key_file_overwriteusers_environmentsGet%CloudshellUsersEnvironmentsGetRequestDEFAULT_ENVIRONMENT_NAMEGetPublicKeyToEntry
publicKeysAddPublicKey.CloudshellUsersEnvironmentsAddPublicKeyRequestAddPublicKeyRequestr   WaitForEnvironmentPoller
operationsr
   PrinttimesleepstateStateValueValuesEnumRUNNINGIsKnownAndSpecifiedr6   r   GetFreshAccessTokenIfEnabledMIN_CREDS_EXPIRY_SECONDSStart'CloudshellUsersEnvironmentsStartRequestStartEnvironmentRequestsshHostcore_exceptionsErrorConnectionInfosshUsernamesshPortkey_file)argsclientmessagesoperations_clientr=   keysr1   r0   has_key	candidateadd_public_key_operationaccess_tokenstart_operations                r   PrepareEnvironmentru   O   s    !!,5&##L$7(,,\4@ OO##%'				(9(9		:$!>!>? ))--44' 5 )*+
 	##%#'))i
g * 
%88EE??0 ( < < < E 	@ 	
  ..&33+66	8 0K II;<JJqM (..CCKKKII45L 3449O9O7768l //5588)$,$D$D( %E %* 	9 	+,O ..&33+66	87K 
		


 H
II	""
--
 r   c            	         [         R                  " SS5      n [         R                  " SS5      n[        R                  " [
        S9nU(       a;  U R                  R                  UR                  [        UR                  US9S95        gg)zFPushes gcloud command-line tool credentials to the user's environment.r*   r+   r7   r9   )r/   authorizeEnvironmentRequestN)r   rA   rB   r   r_   r`   rK   	Authorize+CloudshellUsersEnvironmentsAuthorizeRequestrN   AuthorizeEnvironmentRequest)rl   rm   rs   s      r   AuthorizeEnvironmentr{      s     !!,5&##L$7( 3324,
''<<)(0(L(L( )M )* 	= 	+, r   c                       \ rS rSrS rSrg)rg      c                 @    Xl         X l        X0l        X@l        XPl        g Nr<   )selfr=   r>   r?   r@   r0   s         r   __init__ConnectionInfo.__init__   s    LIIIHr   )r?   r0   r@   r=   r>   N)r   r   r   r   r   r   r   r   r   rg   rg      s    r   rg   c                   0    \ rS rSrSrS rS rS rS rSr	g)	rV      z"Poller for environment operations.c                     Xl         X l        g r   environments_serviceoperations_service)r   r   r   s      r   r   EnvironmentPoller.__init__   s     40r   c                     UR                   $ r   )done)r   	operations     r   IsDoneEnvironmentPoller.IsDone   s    >>r   c                     U R                   R                  S5      nU R                   R                  U" UR                  S95      $ NrL   r.   )r   GetRequestTyperL   r/   r   r   request_types      r   PollEnvironmentPoller.Poll   s8    **99%@L""&&|'HIIr   c                 ~    U R                   R                  S5      nU R                   R                  U" [        S95      $ r   )r   r   rL   rN   r   s      r   	GetResultEnvironmentPoller.GetResult   s:    ,,;;EBL$$((235 5r   r   N)
r   r   r   r   r   r   r   r   r   r   r   r   r   rV   rV      s    *1J5r   rV   )#r   
__future__r   r   r   r&   datetimerY   googlecloudsdk.api_lib.utilr   r   #googlecloudsdk.command_lib.util.sshr   googlecloudsdk.corer	   re   r
   googlecloudsdk.core.credentialsr   rN   	timedeltaMIN_CREDS_EXPIRYformatsecondsr`   rf   r   r!   r(   ru   r{   objectrg   OperationPollerrV   r   r   r   <module>r      s    0 &  '    , . 3 = # 1 ; %%b1  <<(8(@(@A L/// L0	M`,"V 5.. 5r   