
    [1                        S 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SKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  \R,                  " \R.                  R0                  5      \R2                   " S S\R4                  5      5       5       r\R,                  " \R.                  R8                  5      \R2                   " S S\R4                  5      5       5       rg)z The `app instances ssh` command.    N)
exceptions)appengine_api_client)base_classes)base)flags)
iap_tunnel)
ssh_common)ssh)
properties)	resourcesc                   r    \ rS rSrSr\R                  " S5      \R                  -   SS.r	\
S 5       rS rSrg	)
ScpGa"   z9SCP from or to the VM of an App Engine Flexible instance.zd        *{command}* lets you remotely copy files to or from an App Engine
        Flexible instance.            To copy one file from a remote instance to the local machine, run:

              $ {command} --service=s1 --version=v1 i1:remote_file local_file

          To copy several local files to a remote instance, run:

              $ {command} --service=s1 --version=v1 local_1 local_1 i1:remote_dir

          To use recursive copy, run:

              $ {command} --service=s1 --version=v1 --recurse local_dir i1:remote_dir
          DESCRIPTIONEXAMPLESc                     [         R                  " U 5        [        R                  " U 5        U R	                  SSSS9  U R	                  SSSS9  U R	                  SSS	S
S9  U R	                  SSSS9  g Nz	--recurse
store_truezUpload directories recursively.)actionhelpz
--compresszEnable compression.sourceszSpecifies the files to copy.z[INSTANCE:]SRC+)r   metavarnargsdestinationz-Specifies a destination for the source files.z[INSTANCE:]DEST)r   r   r   AddServiceVersionSelectArgsr   AddSshTunnelArgsadd_argumentparsers     lib/surface/app/instances/scp.pyArgs
ScpGa.Args:       	%%f-'
.  0
 "  $
 + 	   <!  #    c                 
   [         R                  " U R                  5       5      n[        R                  R                  5       nUR                  5         [        R                  R                  5       nUR                  SS9  [        R                  R                  UR                  5      nUR                   Vs/ s H"  n[        R                  R                  U5      PM$     nn[        R                  R                  XuSS9  UR                   =(       d    US   R                   nUR"                  n	UR                   (       d  U H	  n
Xl        M      UR%                  UR&                  UR(                  5      n[4        R6                  R8                  R:                  R=                  5       n[>        R@                  RC                  U	UUR(                  U	UR&                  S.SS	9nURE                  5       n URG                  U5      n[J        RL                  " UUU R                  5       UUUS
9nSRO                  URP                  RS                  S5      SS 5      n[        RT                  " 5       n[V        RX                  " U R                  5       5      n[        RZ                  " SUUUR]                  5       R_                  5       SU R                  5       UR`                  URb                  URd                  U	URf                  (       a  URf                  OSUS.[h        Rj                  " U R                  5       5      Rl                  Rn                  S9nSnURp                  (       d  URr                  (       a7  [        Rt                  " UR`                  URb                  URd                  U	5      n[V        Rv                  " X!R&                  UR(                  UR"                  UR]                  5       URx                  URz                  5      nUR                   R"                  Ul        UR                   Rx                  Ul<        [        R                  " UUUR|                  UUR~                  UR                  UR                  US9R                  U5      $ s  snf ! [*        R,                   a;    [.        R0                  " SR3                  UR&                  UR(                  5      5      ef = f! [*        R,                   a    [.        RH                  " U5      ef = f)_  Securily copy files from/to a running flex instance.

Args:
  args: argparse.Namespace, the args the command was invoked with.

Raises:
  InvalidInstanceTypeError: The instance is not supported for SSH.
  MissingVersionError: The version specified does not exist.
  MissingInstanceError: The instance specified does not exist.
  UnattendedPromptError: Not running in a tty.
  OperationCancelledError: User cancelled the operation.
  ssh.CommandError: The SCP command exited with SCP exit code, which
    usually implies that a connection problem occurred.

Returns:
  int, The exit code of the SCP command.
F	overwriteTsingle_remoter   {}/{}appsId
versionsIdinstancesId
servicesId*appengine.apps.services.versions.instancesparams
collection)args
api_clienttrackprojectversioninstance-N r1   r4   r2   r3   serviceAccountregionapp_engine_paramsmessagesidentity_file	cert_filecompress	recursiveoptionsiap_tunnel_argsCr   GetApiClientForTrackReleaseTrackr
   EnvironmentCurrent
RequireSSHKeysFromFilenameEnsureKeysExistFileReferenceFromPathr   r   
SCPCommandVerifyremotehostGetVersionResourceservicer=   apitools_exceptionsHttpNotFoundErrorcommand_exceptionsMissingVersionErrorformatr   VALUEScorer<   	GetOrFailr   REGISTRYParseRelativeNameGetInstanceResourceMissingInstanceErrorr   CreateSshTunnelArgsjoin
vmZoneNamesplitGetDefaultSshUsernamer	   GetComputeProjectGetOsloginStateGetPublicKeyToEntrynamer4   r2   rC   compute_base_classesComputeApiHolderclientrG   third_party_userrequire_certificatesCertFileFromAppEngineInstancePopulatePublicKeyuseroslogin_enabledkey_filerK   recurserM   Run)selfr9   r:   envkeysdstsourcesrcsr\   r>   srcversion_resourcer<   resinstance_nameinstance_resourcerN   rD   r~   oslogin_staterJ   connection_detailss                         r$   r   	ScpGa.RunT   s   $ &::4;L;L;NOJ
//
!
!
#CNN88  "D5) 


$
$T%5%5
6C=A\\J\6C&&v.\DJNN$48ZZ)47>>F{{H::#
 '#66t||7;||E $$,,668G



"
",,#,,	
 @ # AC $$&MC$88= !44! "$O XX'2288=crBCF$$&D**4+<+<+>?G''##%ll....# $22 !//
 &66

&+M0 I%%)K)K33
,,i $55LL$,,]//1N1NP
 %++00FK$++00FK>>mm,,"**') *-S2c K 00 '227>>
,,4& ' ''" 00 C33MBBCs   7)R	&R 0S  AS +T N__name__
__module____qualname____firstlineno____doc__textwrapdedentr	   DETAILED_HELPdetailed_helpstaticmethodr%   r   __static_attributes__r   r(   r$   r   r   "   sO     B __ & !+!9!9:	-& # #2s2r(   r   c                   r    \ rS rSrSr\R                  " S5      \R                  -   SS.r	\
S 5       rS rSrg	)
ScpBeta   zESCP from or to the VM of an App Engine Flexible environment instance.zp        *{command}* lets you remotely copy files to or from an App Engine
        Flexible environment instance.r   r   c                     [         R                  " U 5        [        R                  " U 5        U R	                  SSSS9  U R	                  SSSS9  U R	                  SSS	S
S9  U R	                  SSSS9  g r   r   r"   s    r$   r%   ScpBeta.Args   r'   r(   c                  
   [         R                  " U R                  5       5      n[        R                  R                  5       nUR                  5         [        R                  R                  5       nUR                  SS9  [        R                  R                  UR                  5      nUR                   Vs/ s H"  n[        R                  R                  U5      PM$     nn[        R                  R                  XuSS9  UR                   =(       d    US   R                   nUR"                  n	UR                   (       d  U H	  n
Xl        M      UR%                  UR&                  UR(                  5      n[4        R6                  R8                  R:                  R=                  5       n[>        R@                  RC                  U	UUR(                  U	UR&                  S.SS	9nURE                  5       n URG                  U5      n[J        RL                  " XU R                  5       XU5      nS
RO                  URP                  RS                  S
5      SS 5      n[        RT                  " 5       n[V        RX                  " U R                  5       5      n[        RZ                  " SUUUR]                  5       R_                  5       SU R                  5       UR`                  URb                  URd                  U	URf                  (       a  URf                  OSUS.[h        Rj                  " U R                  5       5      Rl                  Rn                  S9nSnURp                  (       d  URr                  (       a7  [        Rt                  " UR`                  URb                  URd                  U	5      n[V        Rv                  " X!R&                  UR(                  UR"                  UR]                  5       URx                  URz                  5      nUR                   R"                  Ul        UR                   Rx                  Ul<        [        R                  " UUUR|                  UUR~                  UR                  UR                  US9nUR                  U5      $ s  snf ! [*        R,                   a;    [.        R0                  " SR3                  UR&                  UR(                  5      5      ef = f! [*        R,                   a    [.        RH                  " U5      ef = f)r*   Fr+   Tr-   r   r/   r0   r5   r6   r?   Nr@   rA   rB   rE   rH   rO   )r   r9   r:   r   r   r   r   r   r\   r>   r   r   r<   r   r   r   rN   rD   r~   r   rJ   r   cmds                          r$   r   ScpBeta.Run   s   $ &::4;L;L;NOJ
//
!
!
#CNN88  "D5) 


$
$T%5%5
6C=A\\J\6C&&v.\DJNN$48ZZ)47>>F{{H::#
 '#66t||7;||E $$,,668G



"
",,#,,	
 @ # AC $$&MC$88= !44T595F5F5H5<5FHO
 XX'2288=crBCF$$&D**4+<+<+>?G''##%ll....# $22 !//
 &66

&+M0 I%%)K)K33
,,i $55LL$,,]//1N1NP
 %++00FK$++00FK
..mm,,"**')C 773<m K 00 '227>>
,,4& ' ''" 00 C33MBBCs   7)R&R 0S" AS"+Tr   Nr   r   r(   r$   r   r      sP     N __ &* +-7-E-EF	-& # #2pr(   r   )r   r   apitools.base.pyr   r`   googlecloudsdk.api_lib.appr   googlecloudsdk.api_lib.computer   rw   googlecloudsdk.callioper   googlecloudsdk.command_lib.apprb   r   r   r	   #googlecloudsdk.command_lib.util.sshr
   googlecloudsdk.corer   r   ReleaseTracksrQ   GADefaultUniverseOnlyCommandr   BETAr   r   r(   r$   <module>r      s     '  > ; O ( K 0 5 5 3 * ) D%%(()c2DLL c2  *c2L D%%**+`dll `  ,`r(   