
                            d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ dd	lmZ d
ZdZe	j                   j"                  ee	j                   j$                  ee	j                   j&                  eiZdZdZdZe	j                   j"                  fdZe	j                   j"                  dfdZd Zd Zd Zd Zd Zy)z$Utilities for the cloudbuild v2 API.    )absolute_import)division)unicode_literalsN)apis)base)	resources)resource_property
cloudbuildv2z)projects/.*/locations/.*/memberships/(.*)z/projects/.*/locations/.*/workerPoolSecondGen/.*z1projects/.*/locations/.*/workerPoolSecondGen/(.*)c                 D    t        j                  t        t        |          S )zReturns the messages module for Cloud Build.

  Args:
    release_track: The desired value of the enum
      googlecloudsdk.calliope.base.ReleaseTrack.

  Returns:
    Module containing the definitions of messages for Cloud Build.
  )r   GetMessagesModule	_API_NAMERELEASE_TRACK_TO_API_VERSION)release_tracks    7lib/googlecloudsdk/api_lib/cloudbuild/v2/client_util.pyr   r   .   s#     
			 <] K
M M    Tc                 J    t        j                  t        t        |    |       S )a.  Returns an instance of the Cloud Build client.

  Args:
    release_track: The desired value of the enum
      googlecloudsdk.calliope.base.ReleaseTrack.
    use_http: bool, True to create an http object for this client.

  Returns:
    base_api.BaseApiClient, An instance of the Cloud Build client.
  )no_http)r   GetClientInstancer   r   )r   use_https     r   r   r   <   s'     
		"=1|
 r   c           	         t               }t               }|dk(  rbt        j                  j	                  |dd| ||d      }|j
                  j                  |j                  |j                                     }|S |dk(  rbt        j                  j	                  |dd| ||d	      }|j                  j                  |j                  |j                                     }	|	S y
)zGet a PipelineRun/TaskRun.pipelinerunz*cloudbuild.projects.locations.pipelineRunsr   )
projectsIdlocationsIdpipelineRunsId)
collectionapi_versionparamsnametaskrunz&cloudbuild.projects.locations.taskRuns)r   r   
taskRunsIdN)r   r   r   REGISTRYParseprojects_locations_pipelineRunsGet1CloudbuildProjectsLocationsPipelineRunsGetRequestRelativeNameprojects_locations_taskRuns-CloudbuildProjectsLocationsTaskRunsGetRequest)
projectregionrun_idrun_typeclientmessagespipeline_run_resourcepipeline_runtask_run_resourcetask_runs
             r   GetRunr5   M   s   & (%..44?!!$
	 5  99==BB&335 	C 	89L 9!**00;!! 
	 1  1155>>"//1 	? 	45H O r   c                     t        j                  t        |       }|r|j                  d      S t	        dt        d      )aP  Get the name part of a cluster membership's full resource name.

  For example, "projects/123/locations/global/memberships/cluster2" returns
  "cluster2".

  Args:
    resource_name: A cluster's full resource name.

  Raises:
    ValueError: If the full resource name was not well-formatted.

  Returns:
    The cluster's short name.
     z1The cluster membership resource name must match "")researchCLUSTER_NAME_SELECTORgroup
ValueErrorresource_namematchs     r   ClusterShortNamerA   o   s;     )))=
9%
;;q>), 	- -r   c                     t               }t               }|j                  j                  |j	                  dj                  |                   S )zGet the list of supported Cloud Build locations.

  Args:
    project: The project to search.

  Returns:
    A CloudbuildProjectsLocationsListRequest object.
  zprojects/{}r   )r   r   projects_locationsList&CloudbuildProjectsLocationsListRequestformat)r+   r/   r0   s      r   ListLocationsrG      sN     & (		"	"	'	'55##G, 6 
 r   c                     t        j                  t        |       }|r|j                  d      S t	        dt
        d      )aX  Get the name part of a worker pool second gen's full resource name.

  E.g. "projects/abc/locations/def/workerPoolSecondGen/ghi" returns "ghi".

  Args:
    resource_name: A worker pool second gen's full resource name.

  Raises:
    ValueError: If the full resource name was not well-formatted.

  Returns:
    The worker pool's short name.
  r7   z5The worker pool second gen resource name must match "r8   )r9   r:   #WORKERPOOL_SECOND_GEN_NAME_SELECTORr<   r=   "WORKERPOOL_SECOND_GEN_NAME_MATCHERr>   s     r   WorkerPoolSecondGenShortNamerK      s;     ))7
G%
;;q>69 	: :r   c                 j   g }| j                         D ]  }| j                  |j                        }|j                  r|s-|0t	        j
                  |j                        }t        |d      r2t        |      D ]#  }|j                  dj                  ||             % |j                  |        |S )a  Produce field paths from a message object.

  The result is used to create a FieldMask proto message that contains all field
  paths presented in the object.
  https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/field_mask.proto

  Args:
    msg: A user defined message object that extends the messages.Message class.
    https://github.com/google/apitools/blob/master/apitools/base/protorpclite/messages.py

  Returns:
    The list of field paths.
  
all_fieldsz{}.{})
rM   get_assigned_valuer    repeatedr	   ConvertToSnakeCasehasattrMessageToFieldPathsappendrF   )msgfieldsfieldvr    fs         r   rR   rR      s     &~~euzz*A~~a}11%**=d	L	!$Q'A
--tQ/
0 ( 	d   
-r   )__doc__
__future__r   r   r   r9   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.corer   googlecloudsdk.core.resourcer	   r   GA_API_VERSIONReleaseTrackGABETAALPHAr   r;   rJ   rI   r   r   r5   rA   rG   rK   rR    r   r   <module>re      s    + &  ' 	 , ( ) :	 	.N^   E 6 # 9 $
 %)$5$5$8$8 M %)$5$5$8$84 "D-,&:*r   