
                             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Zdd
Z G d de
j                        Z G d de      Z G d de      Zy	)z*Utilities for Cloud Pub/Sub Snapshots API.    )absolute_import)division)unicode_literals)
list_pager)apis)
exceptionsc                 2    t        j                  dd|       S )Npubsubv1no_http)r   GetClientInstancer   s    .lib/googlecloudsdk/api_lib/pubsub/snapshots.pyr   r      s    			$	@@    Nc                 6    | xs
 t               } | j                  S N)r   MESSAGES_MODULE)clients    r   GetMessagesModuler       s    (&(&			r   c                       e Zd ZdZy)NoFieldsSpecifiedErrorz:Error when no fields were specified for a Patch operation.N)__name__
__module____qualname____doc__ r   r   r   r   %   s    Br   r   c                       e Zd ZdZd Zy)_SnapshotUpdateSettingz-Data container class for updating a snapshot.c                      || _         || _        y r   )
field_namevalue)selfr    r!   s      r   __init__z_SnapshotUpdateSetting.__init__,   s     DODJr   N)r   r   r   r   r#   r   r   r   r   r   )   s
    5r   r   c                   <    e Zd ZdZd	dZd	dZd Zd Zd
dZddZ	y)SnapshotsClientz6Client for snapshots service in the Cloud Pub/Sub API.Nc                     |xs
 t               | _        |xs t        |      | _        | j                  j                  | _        y r   )r   r   r   messagesprojects_snapshots_service)r"   r   r'   s      r   r#   zSnapshotsClient.__init__4   s5    /-/DK9 1& 9DMKK22DMr   c                     | j                   j                  | j                   j                  |j                         ||      |j                               }| j                  j                  |      S )zCreates a Snapshot.)subscriptionlabelstags)createSnapshotRequestname)r'   $PubsubProjectsSnapshotsCreateRequestCreateSnapshotRequestRelativeNamer)   Create)r"   snapshot_refsubscription_refr,   r-   
create_reqs         r   r3   zSnapshotsClient.Create9   sk    CC"mmAA)668 B  &&( D *J ==
++r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zGets a Snapshot.

    Args:
      snapshot_ref (Resource): Resource reference to the Snapshot to get.
    Returns:
      Snapshot: The snapshot.
    snapshot)r'   !PubsubProjectsSnapshotsGetRequestr2   r)   Get)r"   r4   get_reqs      r   r;   zSnapshotsClient.GetC   s>     mm==**, > .G==W%%r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zDeletes a Snapshot.r8   )r'   $PubsubProjectsSnapshotsDeleteRequestr2   r)   Delete)r"   r4   
delete_reqs      r   r?   zSnapshotsClient.DeleteO   s=    CC**, D .J==
++r   c                     | j                   j                  |j                         |      }t        j                  | j
                  ||dd      S )aE  Lists Snapshots for a given project.

    Args:
      project_ref (Resource): Resource reference to Project to list
        Snapshots from.
      page_size (int): the number of entries in each batch (affects requests
        made, but not the yielded results).
    Returns:
      A generator of Snapshots in the Project.
    )projectpageSize	snapshotsrC   )
batch_sizefieldbatch_size_attribute)r'   "PubsubProjectsSnapshotsListRequestr2   r   YieldFromListr)   )r"   project_ref	page_sizelist_reqs       r   ListzSnapshotsClient.ListU   sR     }}??((* @ H ##xI
< <r   c                    t        d|      g}| j                  j                  |j                               }g }|D ]K  }|j                  t        ||j                  |j                         |j                  |j                         M |st        d      | j                  j                  | j                  j                  |dj                  |            |j                               }| j                  j                  |      S )a6  Updates a Snapshot.

    Args:
      snapshot_ref (Resource): Resource reference for the snapshot to be
        updated.
      labels (LabelsValue): The Cloud labels for the snapshot.
    Returns:
      Snapshot: The updated snapshot.
    Raises:
      NoFieldsSpecifiedError: if no fields were specified.
    r,   )r/   z*Must specify at least one field to update.,)r9   
updateMask)updateSnapshotRequestr/   )r   r'   Snapshotr2   r!   setattrr    appendr   #PubsubProjectsSnapshotsPatchRequestUpdateSnapshotRequestjoinr)   Patch)r"   r4   r,   update_settingsr9   update_maskupdate_setting	patch_reqs           r   rX   zSnapshotsClient.Patchh   s     .h?@O}}%%&&( & *HK)				).33^5I5IJ>445 * "#OPPAA"mmAAxx, B . &&(	 B *I ==y))r   )NN)d   r   )
r   r   r   r   r#   r3   r;   r?   rM   rX   r   r   r   r%   r%   1   s#    >3
,
&,<&*r   r%   )Fr   )r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r   r   Errorr   objectr   r%   r   r   r   <module>rd      sU     1 &  ' ' , *A 
CZ-- CV S*f S*r   