
    <                         S r SSKJr  SSKJr  SSKJ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r\S-   r\S-   rSrS rS rS rS rS rS rS rg)z,Common helper methods for Services commands.    )absolute_import)division)unicode_literalsN)encoding)
exceptions)apis_internal)log)
properties)	transport)retryzgcloud services operations zdescribe {0}zwait {0}zservicemanagement.servicesc                  0    [         R                  " SS5      $ )Nservicemanagementv1)r   _GetMessagesModule     4lib/googlecloudsdk/api_lib/services/services_util.pyGetMessagesModuler   '   s    		)	)*=t	DDr   c                      SSK Jn   [        R                  R                  R
                  R                  5       nU R                  [        R                  US9n[        R                  " SSUS9$ )zDGet a client instance for service management without resource quota.r   )
transports)response_encodingenable_resource_quotar   r   )http_client)googlecloudsdk.core.credentialsr   r
   VALUESbillingquota_projectIsExplicitlySetGetApitoolsTransportr   ENCODINGr   _GetClientInstance)r   r   r   s      r   GetClientInstancer"   ,   si     9 --==? //!**1 0 3+ 
	)	)4[
: :r   c                     U (       a5  [         R                  R                  R                  R	                  U 5        U $ [         R                  R                  R                  R                  SS9n U $ )zValidate the project ID, if supplied, otherwise return the default project.

Args:
  project_id: The ID of the project to validate. If None, gcloud's default
              project's ID will be returned.

Returns:
  The validated project ID.
T)required)r
   r   coreprojectValidateGet)
project_ids    r   GetValidatedProjectr*   @   s\     ""++J7 
 ""''//33T3BJ	r   c                    ^ U4S jn/ n [         R                  " SSSS9R                  X U/SSS9  U(       a  US
   $ S$ ! [         R                   a&    [        R
                  " S	R                  U 5      5      ef = f)aH  Wait till the operation is done.

Args:
  name: The name of operation.
  get_op_func: The function that gets the operation.

Raises:
  exceptions.OperationErrorException: when the getting operation API fails.
  apitools_exceptions.HttpError: Another miscellaneous error with the service.

Returns:
  The result of the operation
c                 z   > T" U 5      nUR                   (       a  UR                  U5        UR                   (       + $ )N)doneappend)nameresultopget_op_funcs      r   _CheckOpWaitOperation.<locals>._CheckOp`   s,    	T	B	wwmmBww;r   g?i'  i@w )exponential_sleep_multiplierwait_ceiling_msmax_wait_msTi  )should_retry_ifsleep_mszTTimed out while waiting for operation {0}. Note that the operation is still pending.r   N)r   RetryerRetryOnResultMaxRetrialsExceptionr   TimeoutErrorformat)r/   r2   r3   r0   s    `  r   WaitOperationr?   Q   s     &	D	MM%("$ %2MVndT %2 %K &$&	 
	#	# D

!
! #66<fTlD DDs   'A   :A:c                    U R                   (       d9  [        R                  R                  SR	                  U R
                  5      5        gU R                  (       aY  [        R                  " SR	                  U R
                  U R                  R                  U R                  R                  5      5      e[        R                  R                  SR	                  U R
                  5      5        g)zPrint the operation.

Args:
  op: The long running operation.

Raises:
  OperationErrorException: if the operation fails.

Returns:
  Nothing.
%Operation "{0}" is still in progress.N@The operation "{0}" resulted in a failure "{1}".
Details: "{2}".&Operation "{0}" finished successfully.)r-   r	   statusPrintr>   r/   errorr   OperationErrorExceptionmessagedetailsr1   s    r   PrintOperationrK   u   s     
JJ<CCBGGLM
XX

,
,Krww(("((*:*:;= = **;BB277KLr   c                    U R                   (       d9  [        R                  R                  SR	                  U R
                  5      5        gU R                  (       aY  [        R                  " SR	                  U R
                  U R                  R                  U R                  R                  5      5      eU R                  (       am  [        R                  R                  SR	                  U R
                  [        R                  " [        R                  " U R                  5      SSSS95      5        g[        R                  R                  S	R	                  U R
                  5      5        g)
zPrint the operation with response.

Args:
  op: The long running operation.

Raises:
  OperationErrorException: if the operation fails.

Returns:
  Nothing.
rA   NrB   %Operation [{0}] complete. Result: {1}T   ,:	sort_keysindent
separatorsrC   )r-   r	   rD   rE   r>   r/   rF   r   rG   rH   rI   responsejsondumpsr   MessageToDictrJ   s    r   PrintOperationWithResponserZ      s     
JJ<CCBGGLM
XX

,
,Krww(("((*:*:;= = [[JJ<CC


""2;;/!		#$ % JJ=DDRWWMNr   c                    U R                   (       d9  [        R                  R                  SR	                  U R
                  5      5        gU R                  (       aX  U R                  R                  nUR                  SS5      n[        R                  " SR	                  U R
                  U5      5      eU R                  (       am  [        R                  R                  SR	                  U R
                  [        R                  " [        R                  " U R                  5      SSS	S
95      5        g[        R                  R                  SR	                  U R
                  5      5        g)zPrint the operation with response for update consumer policy.

Args:
  op: The long running operation.

Raises:
  OperationErrorException: if the operation fails.

Returns:
  Nothing.
rA   NzPlease specify forcez,Please specify --bypass-api-usage-check flagz/The operation "{0}" resulted in a failure "{1}"rM   TrN   rO   rR   rC   )r-   r	   rD   rE   r>   r/   rF   rH   replacer   rG   rV   rW   rX   r   rY   )r1   error_messagemodified_messages      r   1PrintOperationWithResponseForUpdateConsumerPolicyr_      s    
JJ<CCBGGLM
XXHH$$M %,, N 
,
,9@@GG%	
 
 [[JJ/66GGJJ&&r{{3%		

 JJ=DDRWWMNr   )__doc__
__future__r   r   r   rW   apitools.base.pyr   googlecloudsdk.api_lib.servicesr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer	   r
   r   googlecloudsdk.core.utilr   OP_BASE_CMDOP_DESCRIBE_CMDOP_WAIT_CMDSERVICES_COLLECTIONr   r"   r*   r?   rK   rZ   r_   r   r   r   <module>rk      st     3 &  '  % 6 5 # * ) * ,.J&2 E
:("!'HM,O>(Or   