
    I                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z ddl	mZ dd	lmZ dd
lmZ  G d dej                         Z G d de      Zd ZddZd Zy)z9General utilities using operations in Privateca commands.    )absolute_import)division)unicode_literals)encoding)base)messages)waiter)
exceptions)	resourcesc                       e Zd ZdZy)OperationErrorz3Exception for errors encountered from an operation.N__name__
__module____qualname____doc__     6lib/googlecloudsdk/command_lib/privateca/operations.pyr   r      s    ;r   r   c                       e Zd ZdZy)OperationTimeoutErrorz*Exception for when an operation times out.Nr   r   r   r   r   r   !   s    2r   r   c                 V    t         j                  j                  | j                  d      S )z5Get a resource reference to a long running operation.z'privateca.projects.locations.operations)r   REGISTRYParseRelativeNamename)	operations    r   GetOperationRefr   %   s%    				-	-nn?
 r   c                 v   | j                   r7| j                  rt        | j                  j                        | j                  S t        |       }t        j                  t        j                  |      j                        }	 t        j                  |||      S # t        j                  $ r t        d      w xY w)ay  Waits for operation to complete while displaying in-progress indicator.

  Args:
    operation: The Operation resource.
    progress_message: The message to display with the in-progress indicator.
    api_version: The API version.

  Returns:
    The resource that is the result of the operation.

  Raises:
    OperationError: if the operation did not complete successfully
  zRequested action timed out. Please run the describe command on your resource to see if changes were successful, or try again in a few minutes.)doneerrorr   messageresponser   r	   CloudOperationPollerNoResourcesr   GetClientInstanceprojects_locations_operationsWaitForTimeoutErrorr   )r   progress_messageapi_versionoperation_refpollers        r   Awaitr,   ,   s     ^^9??2233!),-11
[)GG&>>&-1ABB			 
	 s   B B8c                 j    t        j                  |       }d|v r|d= t        j                  ||d      S )a  Returns a message from the ResponseValue.

  Operations normally return a ResponseValue object in their response field that
  is somewhat difficult to use. This functions returns the corresponding
  message type to make it easier to parse the response.

  Args:
    response: The ResponseValue object that resulted from an Operation.
    message_type: The type of the message that should be returned

  Returns:
    An instance of message_type with the values from the response filled in.
  z@typeF)throw_on_unexpected_fields)r   MessageToDictmessages_utilDictToMessageWithErrorCheck)r"   message_typemessage_dicts      r   GetMessageFromResponser4   M   s>     ''1,W		2	2LU
 r   N)v1)r   
__future__r   r   r   apitools.base.pyr    googlecloudsdk.api_lib.privatecar   googlecloudsdk.api_lib.utilr   r0   r	   googlecloudsdk.corer
   r   Errorr   r   r   r,   r4   r   r   r   <module>r<      sT    @ &  ' % 1 A . * )<Z%% <3N 3Br   