
    #                         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j                        Zd Z G d dej&                        Zy)z,Utilities for Eventarc GoogleAPISources API.    )absolute_import)division)unicode_literals)
list_pager)base)common)apis)
exceptions)	resourcesc                       e Zd ZdZy)NoFieldsSpecifiedErrorz:Error when no fields were specified for a Patch operation.N__name__
__module____qualname____doc__     9lib/googlecloudsdk/api_lib/eventarc/google_api_sources.pyr   r      s    Br   r   c                       e Zd ZdZy)$NoProjectSubscriptionsSpecifiedErrorz3Error when no project subscriptions were specified.Nr   r   r   r   r   r   !   s    ;r   r   c                 x    t         j                  j                  | j                  d      }|j	                         S )Nz,eventarc.projects.locations.googleApiSources)
collection)r   REGISTRYParseRelativeNamenameSelfLink)resourcegoogle_api_sourcess     r   GetGoogleAPISourceURIr    %   s9     ));;mm N <  
	$	$	&&r   c                   l     e Zd ZdZ fdZ	 ddZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zed        Z xZS )GoogleApiSourceClientV1zPGoogleApiSource Client for interaction with v1 of Eventarc GoogleApiSources API.c                    t         t        |   t        j                  t        j
                  d       t        j                  t        j                  t        j
                        }|j                  | _	        |j                  | _        y )NzGoogle API source)superr"   __init__r   API_NAMEAPI_VERSION_1r	   GetClientInstanceMESSAGES_MODULE	_messages#projects_locations_googleApiSources_service)selfclient	__class__s     r   r%   z GoogleApiSourceClientV1.__init__/   s]    	
!41--/B
 ##FOOV5I5IJF++DN>>DMr   c                     | j                   j                  |j                         j                         ||j	                         |      }| j
                  j                  |      S )a  Creates a new GoogleAPISource.

    Args:
      google_api_source_ref: Resource, the GoogleAPISource to create.
      google_api_source_message: GoogleAPISource, the googleApiSource message
        that holds googleApiSource's name, destination message bus, logging
        config, crypto key name, etc.
      dry_run: If set, the changes will not be committed, only validated

    Returns:
      A long-running operation for create.
    )parentgoogleApiSourcegoogleApiSourceIdvalidateOnly)r*   6EventarcProjectsLocationsGoogleApiSourcesCreateRequestParentRelativeNameNamer,   Create)r-   google_api_source_refgoogle_api_source_messagedry_run
create_reqs        r   r9   zGoogleApiSourceClientV1.Create:   s_      	MM(//1>>@5388: 	 	N 	
  ==
++r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zGets the requested GoogleApiSource.

    Args:
      google_api_source_ref: Resource, the GoogleApiSource to get.

    Returns:
      The GoogleApiSource message.
    r   )r*   3EventarcProjectsLocationsGoogleApiSourcesGetRequestr7   r,   Get)r-   r:   get_reqs      r   rA   zGoogleApiSourceClientV1.GetS   sD     	JJ&335 	K 	
 
 ==W%%r   c                     | j                   j                  |j                         |      }t        j                  | j
                  |d||d      S )a  List available googleApiSources in location.

    Args:
      location_ref: Resource, the location to list GoogleApiSources in.
      limit: int or None, the total number of results to return.
      page_size: int, the number of entries in each batch (affects requests
        made, but not the yielded results).

    Returns:
      A generator of GoogleApiSources in the location.
    )r1   pageSizegoogleApiSourcesrD   )servicerequestfieldlimit
batch_sizebatch_size_attribute)r*   4EventarcProjectsLocationsGoogleApiSourcesListRequestr7   r   YieldFromListr,   )r-   location_refrI   	page_sizelist_reqs        r   ListzGoogleApiSourceClientV1.Listc   sZ     	KK,,. 	L 	
 
 ## ' r   c                     | j                   j                  |j                         ||      }| j                  j	                  |      S )a  Updates the specified GoogleApiSource.

    Args:
      google_api_source_ref: Resource, the GoogleApiSource to update.
      google_api_source_message: GoogleApiSource, the googleApiSource message
        that holds googleApiSource's name, destination message bus, logging
        config, crypto key name, etc.
      update_mask: str, a comma-separated list of GoogleApiSource fields to
        update.

    Returns:
      A long-running operation for update.
    )r   r2   
updateMask)r*   5EventarcProjectsLocationsGoogleApiSourcesPatchRequestr7   r,   Patch)r-   r:   r;   update_mask	patch_reqs        r   rU   zGoogleApiSourceClientV1.Patch}   sJ    " 	LL&3355" 	M 	
  ==y))r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zDeletes the specified GoogleApiSource.

    Args:
      google_api_source_ref: Resource, the GoogleApiSource to delete.

    Returns:
      A long-running operation for delete.
    r?   )r*   6EventarcProjectsLocationsGoogleApiSourcesDeleteRequestr7   r,   Delete)r-   r:   
delete_reqs      r   rZ   zGoogleApiSourceClientV1.Delete   sD     	MM&335 	N 	
 
 ==
++r   c                    d }|?| j                   j                  | j                   j                  j                  |            }| j                   j                  |j	                         ||j	                         nd|||      }	|H|r#| j                   j                  d      |	_        |	S | j                   j                  d      |	_        |	S |r| j                  |      |	_        |	S )N)logSeverity )r   destinationloggingConfigcryptoKeyNamelabelsT)enabledF)	r*   LoggingConfigLogSeverityValueValuesEnumGoogleApiSourcer7   OrganizationSubscriptionorganizationSubscription_BuildProjectSubscriptionsListprojectSubscriptions)
r-   r:   destination_reflogging_configcrypto_key_namerb   organization_subscriptionproject_subscriptionslogging_config_enumgoogle_api_sources
             r   BuildGoogleApiSourcez,GoogleApiSourceClientV1.BuildGoogleApiSource   s    ! NN88nn22MM 9 
 66"//1& $002)% 7  !,	"NN33 4  	2  NN33 4  	2 	 


-
-.C
D , r   c	                 .   g }	|r|	j                  d       |r|	j                  d       |s|r|	j                  d       |r|	j                  d       |r|	j                  d       |s|r|	j                  d       |	st        d      dj                  |	      S )	a  Builds an update mask for updating a GoogleApiSource.

    Args:
      destination: bool, whether to update the destination.
      logging_config: bool, whether to update the logging config.
      crypto_key: bool, whether to update the crypto key.
      clear_crypto_key: bool, whether to clear the crypto key.
      labels: bool, whether to update the labels.
      organization_subscription: bool, whether to update the organization
        subscription.
      project_subscriptions: bool, whether to update the project subscriptions.
      clear_project_subscriptions: bool, whether to clear the project
        subscriptions.

    Returns:
      The update mask as a string.


    Raises:
      NoFieldsSpecifiedError: No fields are being updated.
    r_   r`   ra   rb   rh   rj   z*Must specify at least one field to update.,)appendr   join)
r-   r_   rl   
crypto_keyclear_crypto_keyrb   rn   ro   clear_project_subscriptionsrV   s
             r   BuildUpdateMaskz'GoogleApiSourceClientV1.BuildUpdateMask   s    @ K')%)" 34 ;/0"#OPP88K  r   c                 B    | j                   j                  j                  S )zReturns the labels value class.)r*   rf   LabelsValuer-   s    r   LabelsValueClassz(GoogleApiSourceClientV1.LabelsValueClass  s    >>))555r   c                 f    |st        d      | j                  j                  t        |            S )NzTMust specify at least one project number or project ID in the project subscriptions.)list)r   r*   ProjectSubscriptionsr   )r-   ro   s     r   ri   z6GoogleApiSourceClientV1._BuildProjectSubscriptionsList	  s7     0$  >>..D9N4O.PPr   c                      y)Nzgoogle-api-sourcesr   r}   s    r   _resource_label_pluralz.GoogleApiSourceClientV1._resource_label_plural  s    r   )F)r   r   r   r   r%   r9   rA   rQ   rU   rZ   rr   rz   r~   ri   propertyr   __classcell__)r/   s   @r   r"   r"   ,   sV    X	? GL,2& 4*2, +Z0!d6Q    r   r"   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.eventarcr   r   googlecloudsdk.api_lib.utilr	   googlecloudsdk.corer
   r   Errorr   r   r    EventarcClientBaser"   r   r   r   <module>r      sd    3 &  ' ' 0 2 , * )CZ-- C<:+;+; <'g d55 g r   