
                         J   S 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  SSKJr  SSKJr  \
R.                  " \
R0                  R2                  \
R0                  R4                  5       " S S\
R6                  5      5       rg)zACommand to deploy an Apigee archive deployment to an environment.    )absolute_import)division)unicode_literals)apigee)waiter)base)archives)defaults)errors)resource_args)labels_util)log)filesc                   J    \ rS rSrSrSSS.r\S 5       rS rS r	S	 r
S
 rSrg)Deploy    z6Deploy an Apigee archive deployment to an environment.a$     {description}

  `{command}` installs an archive deployment in an Apigee environment.

  By default, the archive deployment will be deployed on the remote management
  plane for the specified Apigee organization. To deploy on a locally running
  Apigee emulator, use the `--local` flag.
  a    To deploy the contents of the current working directory as an archive
  deployment to an environment named ``my-test'', given that the Cloud Platform
  project has been set in gcloud settings, run:

    $ {command} --environment=my-test

  To deploy an archive deployment from a local directory other than the current
  working directory, to an environment named ``my-demo'' in an organization
  belonging to a Cloud Platform project other than the one set in gcloud
  settings, named ``my-org'', run:

    $ {command} --organization=my-org --environment=my-demo --source=/apigee/dev

  To deploy the contents of the current working directory as an archive
  deployment, with the user-defined labels ``my-label1=foo'' and
  ``my-label2=bar'', to an environment named ``my-test'', given that the Cloud
  Platform project has been set in gcloud settings, run:

    $ {command} --environment=my-test --labels=my-label1=foo,my-label2=bar
  )DESCRIPTIONEXAMPLESc           	      R   [         R                  " 5       /n[        R                  " U SSUSSS9  U R	                  SSS9nUR                  SS[        R                  S	S
9  UR                  SS[        R                  SS
9  U R                  SSSSS9  [        R                  " U 5        g )Nzorganization.environmentz=Apigee environment in which to deploy the archive deployment.FT)resource_path	help_textfallthroughs
positionalrequiredzSource input.)mutexhelpz--sourcez.The source directory of the archive to upload.)r   typer   z--bundle-filez-The zip file containing an archive to upload.z--async
store_trueasync_aP  If set, returns immediately and outputs a description of the long running operation that was launched. Else, `{command}` will block until the archive deployment has been successfully deployed to the specified environment.

To monitor the operation once it's been launched, run `{grandparent_command} operations describe OPERATION_NAME`.)actiondestr   )
r
   !GCPProductOrganizationFallthroughr   AddSingleResourceArgument	add_groupadd_argumentr   ExpandHomeDirr   AddCreateLabelsFlags)parserr   source_input_groups      %lib/surface/apigee/archives/deploy.pyArgsDeploy.ArgsG   s    >>@AL++0!!  ))?)K##  =	 $ ?
 ##  <	 $ >
 L	  	N $$V,    c                     [         R                  R                  U5      nSU;  a  [        R                  " SUUSS9eUS   $ )aX  Gets the signed URL for uploading the archive deployment.

Args:
  identifiers: A dict of resource identifers. Must contain "organizationsId"
    and "environmentsId"

Returns:
  A str of the upload URL.

Raises:
  googlecloudsdk.command_lib.apigee.errors.RequestError if the "uploadUri"
    field is not included in the GetUploadUrl response.
	uploadUrigetUploadUrlzPlease try again.)resource_typeresource_identifierbody	user_help)r   ArchivesClientGetUploadUrlr   RequestError)selfidentifiersget_upload_url_resps      r*   _GetUploadUrlDeploy._GetUploadUrll   sP     !//<<[I--&)"'	) )
 {++r-   c                     [         R                  " X5      nUR                  (       d6  [        R                  " UR
                  UR                  UR                  5      eg)a@  Issues an HTTP PUT call to the upload URL with the zip file payload.

Args:
  upload_url: A str containing the full upload URL.
  zip_file_path: A str of the local path to the zip file.

Raises:
  googlecloudsdk.command_lib.apigee.errors.HttpRequestError if the response
    status of the HTTP PUT call is not 200 (OK).
N)cmd_libUploadArchiveokr   HttpRequestErrorstatus_codereasoncontent)r8   
upload_urlzip_file_pathupload_archive_resps       r*   _UploadArchiveDeploy._UploadArchive   sS     "//
J!!##$7$C$C$7$>$>$7$?$?A A "r-   c                     0 nX$S'   U(       a%  0 US'   UR                  5        H  u  pVXdS   U'   M     [        R                  R                  X5      n[        R                  R                  U5      nU$ )a1  Creates the archive deployment.

Args:
  identifiers: A dict of resource identifers. Must contain "organizationsId"
    and "environmentsId"
  upload_url: A str containing the full upload URL.
  labels: A dict of the key/value pairs to add as labels.

Returns:
  A dict containing the operation metadata.
gcs_urilabels)itemsr   r5   CreateArchiveDeploymentOperationsClient	SplitName)	r8   r9   rE   rL   	post_datakvapi_response	operations	            r*   _DeployArchiveDeploy._DeployArchive   sr     I%ii,,.$!!"(A !((@@ L''11,?Ir-   c                 x   UR                   R                  R                  5       R                  5       n[        R
                  " U5      nSn [        R                  " UR                  5      nUR                  (       a(  UR                  UR                  5        UR                  nOUR                  5       nU R                  U5      nU R                  Xe5        U R                  X&U5      nSU;  d  SU;  a%  [        R                   " SR#                  U5      5      eSUS   ;   a%  US   S    H  n[$        R&                  " U5        M     [$        R(                  " SUS   5        UR*                  (       a,  UU(       a#  [-        US	5      (       a  UR/                  5         $ $ $ [        R0                  " [2        R4                  " US   5      US   S
R#                  US   5      SS9  U(       a#  [-        US	5      (       a  UR/                  5         ggg! U(       a#  [-        US	5      (       a  UR/                  5         f f f = f)zRun the deploy command.NorganizationuuidzUnknown operation response: {}warningsmetadataz$Started archives deploy operation %snameClosez&Waiting for operation [{}] to completei  )messagewait_ceiling_ms)CONCEPTSenvironmentParseAsDictr   GetUpdateLabelsDictFromArgsr>   LocalDirectoryArchivesourcebundle_fileValidateZipFilePathZipr;   rH   rV   r   OperationErrorformatr   warninginfor   hasattrr^   WaitForr   	LROPoller)	r8   argsr9   
labels_arglocal_dir_archiverF   rE   rU   rm   s	            r*   Run
Deploy.Run   s   --++113::<K88>J"!77D			--d.>.>?(()--/%%k2j
*4%%kzJi	y	(F),C##,33I>@ 	@	y,	, ,Z8G
++g
 9	hh5y7HI	 
w'8'BB!  C	 nn


9^4
5
F
:AA! 
w'8'BB!  C		w'8'BB!  C	s   D(H AH ,H9 N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr+   r;   rH   rV   ru   __static_attributes__rw   r-   r*   r   r       sA    >!-F "- "-H,.A".!"r-   r   N)r|   
__future__r   r   r   googlecloudsdk.api_libr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   !googlecloudsdk.command_lib.apigeer	   r>   r
   r   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   googlecloudsdk.core.utilr   ReleaseTracksReleaseTrackALPHABETADescribeCommandr   rw   r-   r*   <module>r      s|    H &  ' ) . ( A 6 4 ; < # * D%%++T->->-C-CDk"T!! k" Ek"r-   