
    \                        S r SSK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S
KJr  SSKJr  SSKrSrSrSr\R6                  R8                  \\R6                  R:                  \\R6                  R<                  \0rSr Sr!Sr"Sr#Sr$ " S S\RJ                  5      r&\R6                  R8                  4S jr'\R6                  R8                  4S jr(\R6                  R8                  SS4S jr)S r*S r+S r,S r-S r.S  r/S3S! jr0S" r1S# r2  S4S$ jr3  S4S% jr4  S4S& jr5 S3S' jr6 S3S( jr7S) r8S* r9S+ r:S5S, jr;S5S- jr<S. r=S/ r>S0 r?S1 r@S2 rAg)6z!Utilities for the cloudbuild API.    N)messages)encoding)cloudbuild_exceptions)apis)base)
exceptions)yaml)resource_property)files
cloudbuildv1v1beta1z'projects/.*/locations/.*/workerPools/.*z)projects/.*/locations/.*/workerPools/(.*)z)projects/.*/locations/(.*)/workerPools/.*globali   @c                        \ rS rSrSrSrSrSrg)WorkerpoolTypes5   r          N)__name__
__module____qualname____firstlineno__UNKNOWNPRIVATEHYBRID__static_attributes__r       8lib/googlecloudsdk/api_lib/cloudbuild/cloudbuild_util.pyr   r   5   s    ''&r   r   c                 F    [         R                  " [        [        U    5      $ )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    r   r!   r!   ;   s#     
			 <] K
M Mr   c                 F    [         R                  " [        [        U    5      $ )zReturns the client class for Cloud Build.

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

Returns:
  base_api.BaseApiClient, Client class for Cloud Build.
)r   GetClientClassr"   r#   r$   s    r   r'   r'   I   s#     
		Y9-H
J Jr   TFc                 P    [         R                  " [        [        U    U(       + US9$ )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.
  skip_activation_prompt: bool, True to skip prompting for service activation.
    Should be used only if service activation was checked earlier in the
    command.

Returns:
  base_api.BaseApiClient, An instance of the Cloud Build client.
)no_httpskip_activation_prompt)r   GetClientInstancer"   r#   )r%   use_httpr*   s      r   r+   r+   W   s*    $ 
		"=1|3	
 r   c                 d    U (       d  g [         R                  " XR                  R                  SS9$ )NT)
sort_items)apitools_encodingDictToAdditionalPropertyMessageBuildSubstitutionsValue)substitutionsr   s     r   EncodeSubstitutionsr4   q   s,    			:	:^^664
I Ir   c                     U (       d  g / n[        [        R                  " U 5      5       H#  u  p4UR                  UR	                  X4S95        M%     U" US9$ )NkeyvalueadditionalProperties)sortedsix	iteritemsappendAdditionalProperty)r3   
value_typesubstitution_propertiesr7   r8   s        r   EncodeTriggerSubstitutionsrB   y   sU    	3==78jc""%%#%;= 9 
)@	AAr   c                    U(       d  U $ 0 nU (       a+  U R                    H  nUR                  X4R                  '   M     [        R                  " U5       H	  u  pVXcU'   M     / n[        UR                  5       5       H7  u  pVUR                  UR                  R                  R                  XVS95        M9     UR                  R                  US9$ )a(  Encodes the trigger substitutions for the update command.

Args:
  old_substitutions: The existing substitutions to be updated.
  substitutions: The substitutions to be added to the existing substitutions.
  messages: A Cloud Build messages module.

Returns:
  The updated trigger substitutions.
r6   r9   )r:   r8   r7   r<   r=   r;   itemsr>   BuildTriggerr2   r?   )old_substitutionsr3   r   substitution_mapsubr7   r8   updated_substitutionss           r   !EncodeUpdatedTriggerSubstitutionsrJ      s     
 55"%))ww 6 MM-0jc!S 1 +1134jc  00CC 	D 	
 5 
			1	10 
2 
 r   c                    U(       d  g/ nU (       al  U R                    H\  nUR                  U;  d  M  UR                  UR                  R                  R                  UR                  UR                  S95        M^     U(       d3  UR                  UR                  R                  R                  5       5        UR                  R	                  US9$ )a  Removes existing substitutions for the update command.

Args:
  old_substitutions: The existing substitutions.
  substitutions_to_be_removed: The substitutions to be removed if exist.
  messages: A Cloud Build messages module.

Returns:
  The updated trigger substitutions.
Nr6   r9   )r:   r7   r>   rE   r2   r?   r8   )rF   substitutions_to_be_removedr   rA   rH   s        r   RemoveTriggerSubstitutionsrM      s     
% 55	3	3&&!!44GGGG399 H 	
 6 
!""00CCE 
			1	12 
2 
 r   c                 ~    U R                   R                  R                  5       /nU R                   R                  US9$ )Nr9   )rE   r2   r?   )r   rA   s     r   EncodeEmptyTriggerSubstitutionsrO      sE    ..AAC 
			1	12 
2 
 r   c                 2   U R                  S5      nU(       d  U $ SnU H  nU(       d  US-  nM    O   U(       a!  XS nU(       d  SUS-
  -  $ SU-  US   -   US'   SR                  USS USS  Vs/ s H  oDR                  5       PM     sn-   5      $ s  snf )zChange a snake_case string into a camelCase string.

Args:
  snake: str, the string to be transformed.

Returns:
  str, the transformed string.
_r   r   N )splitjoin
capitalize)snakepartsleading_blankspss        r   SnakeToCamelStringr[      s     ++c
%	L
 .an	 
 /"E NQ&''^#eAh.E!H	reABi@illni@@	AA@s   2B
c           	      <   Uc  / n[        U [        5      (       aE  [        R                  " U 5       VVs0 s H!  u  p#[	        U5      X!;  a  [        X15      OU_M#     snn$ [        U [        5      (       a  U  Vs/ s H  n[        XA5      PM     sn$ U $ s  snnf s  snf )a  Recursively transform all keys and values from snake_case to camelCase.

If a key is in skip, then its value is left alone.

Args:
  msg: dict, list, or other. If 'other', the function returns immediately.
  skip: contains dict keys whose values should not have camel case applied.

Returns:
  Same type as msg, except all strings that were snake_case are now CamelCase,
  except for the values of dict keys contained in skip.
)
isinstancedictr<   r=   r[   SnakeToCamellist)msgskipr7   valelems        r   r_   r_      s     
\DT c* +HC 	3$'Oc	 	=* 
 #t145L$55J 6s   (B9Bc                    / nU R                  5        H  nU R                  UR                  5      nUR                  (       a	  U(       d  M8  Uc  M=  UR                  S:X  a  SnO3UR                  S:X  a  SnO [        R
                  " UR                  5      n[        US5      (       a4  [        U5       H#  nUR                  SR                  XE5      5        M%     M  UR                  U5        M     U$ )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.
privatePoolV1Configprivate_pool_v1_confighybridPoolConfighybrid_pool_config
all_fieldsz{}.{})
rj   get_assigned_valuenamerepeatedr
   ConvertToSnakeCasehasattrMessageToFieldPathsr>   format)ra   fieldsfieldvrl   fs         r   rp   rp     s     &~~euzz*A~~a}	,	,'::++# 33EJJ?	L	!	!$Q'A
--t/
0 ( 	d%  & 
-r   c                 P   ^ [         R                  " X5      nU4S jmT" U5        U$ )a@  Stuff a dict into a proto message, and fail if there are unused values.

Args:
  obj: dict(), The structured data to be reflected into the message type.
  msg_type: type, The proto message type.

Raises:
  ValueError: If there is an unused value in obj.

Returns:
  Proto message, The message that was created from obj.
c                 `  > [        U [        R                  5      (       a  U R                  5       nU(       a@  [	        U5      S:  a  SSR                  [        U5      5      -  nOUS   n[        SU-  5      eU R                  5        H!  n [        XR                  5      nT" U5        M#     [        U [        5      (       a  [        U 5       H  u  pg T" U5        M     gg! [         a!  n[        SUR                  < U< 35      eSnAff = f! [         a  n[        SXe4-  5      eSnAff = f)	z8Check for any unused fields in nested messages or lists.r   z{%s},r   z.%s: unused.Nz[%d]%s)r]   proto_messagesMessageall_unrecognized_fieldslenrT   r;   
ValueErrorrj   getattrrl   r`   	enumerate)	objunused_fields
unused_msg
used_fieldrs   eiitem_CheckForUnusedFieldss	           r   r   1_UnpackCheckUnused.<locals>._CheckForUnusedFields@  s   #~--..113m	}! )> ??* %Q'*344(*	;#/%

& ) #ts^'!	.

% $   	;jooq9:
:	;  	.8qf,-
-	.s0   C!D!
D+DD
D-D((D-)r/   DictToMessage)r   msg_typera   r   s      @r   _UnpackCheckUnusedr   1  s)     	''6#.6 	*r   c                     Uc  / n [         R                  " XS9n[        U[        5      (       d  [        R                  " US5      e[        XQUX45      $ ! [         R                   a%  n[        R                  " XFR
                  5      eSnAff = f)a  Load a proto message from a stream of JSON or YAML text.

Args:
  stream: file-like object containing the JSON or YAML data to be decoded.
  msg_type: The protobuf message type to create.
  msg_friendly_name: A readable name for the message type, for use in error
    messages.
  skip_camel_case: Contains proto field names or map keys whose values should
    not have camel case applied.
  path: str or None. Optional path to be used in error messages.

Raises:
  ParserError: If there was a problem parsing the stream as a dict.
  ParseProtoException: If there was a problem interpreting the stream as the
  given message type.

Returns:
  Proto message, The message that got decoded.
N	file_hintz Could not parse as a dictionary.)	r	   loadErrorr   ParserErrorinner_errorr]   r^   _YamlToMessage)streamr   msg_friendly_nameskip_camel_casepathstructured_datar   s          r   LoadMessageFromStreamr   `  s    0 OAii7O 
OT	*	*

+
+D,NP P 
3D'
/ / 
 A

+
+D--
@@As   A B( BBc           
          Uc  / n [         R                  " XS9nU Vs/ s H  n[        XqX#U5      PM     sn$ ! [         R                   a%  n[        R                  " XFR
                  5      eSnAff = fs  snf )a  Load multiple proto message from a stream of JSON or YAML text.

Args:
  stream: file-like object containing the JSON or YAML data to be decoded.
  msg_type: The protobuf message type to create.
  msg_friendly_name: A readable name for the message type, for use in error
    messages.
  skip_camel_case: Contains proto field names or map keys whose values should
    not have camel case applied.
  path: str or None. Optional path to be used in error messages.

Raises:
  ParserError: If there was a problem parsing the stream.
  ParseProtoException: If there was a problem interpreting the stream as the
  given message type.

Returns:
  Proto message list of the messages that got decoded.
Nr   )r	   load_allr   r   r   r   r   )r   r   r   r   r   r   r   r   s           r   LoadMessagesFromStreamr     s    0 OAmmF;O "
!$ T%6N!
  
 A

+
+D--
@@A
s   9 A5A2 A--A2c                     [        X5      n  [        X5      nU$ ! [         a  n[        R                  " XBSU-  5      eSnAff = f)a^  Load a proto message from a file containing JSON or YAML text.

Args:
  structured_data: Dict containing the decoded YAML data.
  msg_type: The protobuf message type to create.
  msg_friendly_name: A readable name for the message type, for use in error
    messages.
  skip_camel_case: Contains proto field names or map keys whose values should
    not have camel case applied.
  path: str or None. Optional path to be used in error messages.

Raises:
  ParseProtoException: If there was a problem interpreting the file as the
  given message type.

Returns:
  Proto message, The message that got decoded.
z%sN)r_   r   	Exceptionr   ParseProtoException)r   r   r   r   r   ra   r   s          r   r   r     sT    2 !B/>
_
7C 
* 
 >  
3
3D481H> >	>s    
A>Ac                 ~    [         R                  " U 5       n[        XAUX05      sSSS5        $ ! , (       d  f       g= f)a  Load a proto message from a file containing JSON or YAML text.

Args:
  path: The path to a file containing the JSON or YAML data to be decoded.
  msg_type: The protobuf message type to create.
  msg_friendly_name: A readable name for the message type, for use in error
    messages.
  skip_camel_case: Contains proto field names or map keys whose values should
    not have camel case applied.

Raises:
  files.MissingFileError: If the file does not exist.
  ParserError: If there was a problem parsing the file as a dict.
  ParseProtoException: If there was a problem interpreting the file as the
  given message type.

Returns:
  Proto message, The message that got decoded.
N)r   
FileReaderr   r   r   r   r   ru   s        r   LoadMessageFromPathr     s0    .  .?!08    .
<c                 ~    [         R                  " U 5       n[        XAUX05      sSSS5        $ ! , (       d  f       g= f)al  Load a proto message from a file containing JSON or YAML text.

Args:
  path: The path to a file containing the JSON or YAML data to be decoded.
  msg_type: The protobuf message type to create.
  msg_friendly_name: A readable name for the message type, for use in error
    messages.
  skip_camel_case: Contains proto field names or map keys whose values should
    not have camel case applied.

Raises:
  files.MissingFileError: If the file does not exist.
  ParseProtoException: If there was a problem interpreting the file as the
  given message type.

Returns:
  Proto message list of the messages that got decoded.
N)r   r   r   r   s        r   LoadMessagesFromPathr     s0    , !!/@"19 r   c                 J    [        [        R                  " [        U 5      5      $ )zDetermine if the provided full resource name is a worker pool.

Args:
  resource_name: str, The string to test.

Returns:
  bool, True if the string is a worker pool's full resource name.
)boolrematchWORKERPOOL_NAME_MATCHER)resource_names    r   IsWorkerPoolr     s     
bhh.>	??r   c                     [         R                  " [        U 5      nU(       a  UR                  S5      $ [	        S[
        < S35      e)a2  Get the name part of a worker pool's full resource name.

For example, "projects/abc/locations/def/workerPools/ghi" returns "ghi".

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

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

Returns:
  The worker pool's short name.
r   *The worker pool resource name must match "")r   searchWORKERPOOL_NAME_SELECTORgroupr~   r   r   r   s     r   WorkerPoolShortNamer     s;     )),m
<%
;;q>+. 	/ /r   c                     [         R                  " [        U 5      nU(       a  UR                  S5      $ [	        S[
        < S35      e)aA  Get the region part of a worker pool's full resource name.

For example, "projects/abc/locations/def/workerPools/ghi" returns "def".

Args:
  resource_name: str, A worker pool's full resource name.

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

Returns:
  str, The worker pool's region string.
r   r   r   )r   r   WORKERPOOL_REGION_SELECTORr   r~   r   r   s     r   WorkerPoolRegionr   -  s;     )).
>%
;;q>+. 	/ /r   c                    [        5       nUR                  5       nU R                  Ul        U R                  Ul        U R                  b  U R                  Ul        U(       d  U R                  b  U R                  Ul	        U R                  bX  UR                  5       nU R                  Ul        U R                  Ul        U R                  b  U R                  Ul        XCl        U$ UR#                  5       nU R$                  Ul        U R(                  Ul        U R,                  Ul        U R0                  Ul        XSl        U$ )a   Construct the GitHubEnterpriseConfig resource from the command line args.

Args:
  args: An argparse namespace. All the arguments that were provided to this
      command invocation.
    update: bool, if the args are for an update.

Returns:
  A populated GitHubEnterpriseConfig message.
)r!   GitHubEnterpriseConfighost_urihostUrlapp_idappIdwebhook_key
webhookKeypeered_networkpeeredNetwork
gcs_bucketGCSLocationbucket
gcs_objectobject
generationappConfigJsonGitHubEnterpriseSecretsprivate_key_nameprivateKeyNamewebhook_secret_namewebhookSecretNameoauth_secret_nameoauthSecretNameoauth_client_id_nameoauthClientIdNamesecrets)argsupdater   ghegcs_locationsecret_locations         r   GitHubEnterpriseConfigFromArgsr   B  s
     ('')##+kk#)	!%%CN	D''3++C	__ '')L//L//L" $l$ 
* 668O%)%:%:O"(,(@(@O%&*&<&<O#(,(A(AO%!K	*r   c                 b   [        5       nUR                  5       nU R                  Ul        U R                  Ul        U R                  Ul        UR                  5       nU R                  Ul
        U R                  Ul        U R                  Ul        U(       d  Ub  XCl        U(       d`  U R                   c$  U R"                  b  [$        R&                  " SS5      eU R                   b"  U R                   Ul        U R"                  Ul        U R-                  S5      (       a  U R.                  Ul        U$ )a  Construct the BitbucketServer resource from the command line args.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.
  update: bool, if the args are for an update.

Returns:
  A populated BitbucketServerConfig message.
zpeered-network-ip-rangezG--peered-network is required when specifying --peered-network-ip-range.ssl_ca_file)r!   BitbucketServerConfigr   hostUri	user_nameusernameapi_keyapiKeyBitbucketServerSecrets!admin_access_token_secret_versionadminAccessTokenVersionName read_access_token_secret_versionreadAccessTokenVersionNamewebhook_secret_secret_versionwebhookSecretVersionNamer   r   peered_network_ip_rangec_exceptionsRequiredArgumentExceptionr   peeredNetworkIpRangeIsSpecifiedr   sslCa)r   r   r   bbsr   s        r   BitbucketServerConfigFromArgsr   g  s     (&&(##+#,||#*335/
,, - ++ , .2-O-O/**!K	"t'C'C'O22
#,  &--c!%!=!=c	m$$  CI	*r   c                 :   [        5       nUR                  5       nU R                  Ul        UR	                  5       nU R
                  Ul        U R                  Ul        U R                  Ul
        U R                  Ul        [        U5      (       d  X2l        UR                  5       nU R                   Ul        UR%                  5       nU R&                  Ul        XTl        U R-                  S5      (       a  U R.                  Ul        [        U5      (       d  XBl        U$ )zConstruct the GitLabConfig resource from the command line args.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  A populated GitLabConfig message.
r   )r!   GitLabConfigr   r   GitLabSecretsapi_access_token_secret_versionapiAccessTokenVersionr   readAccessTokenVersionr   webhookSecretVersionapi_key_secret_versionapiKeyVersion_IsEmptyMessager   GitLabEnterpriseConfigr   r   ServiceDirectoryConfigservice_directory_serviceserviceserviceDirectoryConfigr   r   r   enterpriseConfig)r   r   configr   enterprise_configservice_directory_configs         r   GitLabConfigFromArgsr    s      (  "&NN&/""$'"&"F"F'#'#H#H' !%!C!C'55'		!	!N557"mm%<<>%)%C%C"-E*	m$$"..	*	+	+/	-r   c                 r    U c  g[         R                  " U 5      n[        UR                  5       5      (       + $ )NT)r/   MessageToDictanyvalues)messagemessage_dicts     r   r   r     s1    _"009,$$&'	''r   c                     U S L=(       aV    U R                   S L=(       aA    U R                   R                  S L=(       a"    U R                   R                  R                  S L$ N)optionspoolrl   build_configs    r   WorkerPoolIsSpecifiedr    s\    $ 5


d
*5



#
#4
/5 


#
#
(
(
4	r   c                     U S L=(       aV    U R                   S L=(       aA    U R                   R                  S L=(       a"    U R                   R                  R                  S L$ r  )r  r  workerConfigr  s    r   WorkerPoolConfigIsSpecifiedr    s\    $ =


d
*=



#
#4
/= 


#
#
0
0
<	r   c                 $    U (       d  gU [         -  $ )zConverts bytes to GB.

Args:
  size: a size in GB  Does not require size to be a multiple of 1 GB unlike
    utils.BytesToGb from from googlecloudsdk.api_lib.compute

Returns:
  size in bytes.
N)BYTES_IN_ONE_GB)sizes    r   	BytesToGbr    s     
		  r   r  )NN)F)B__doc__enumr   apitools.base.protorpcliter   rz   apitools.base.pyr   r/   !googlecloudsdk.api_lib.cloudbuildr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   r   googlecloudsdk.corer	   googlecloudsdk.core.resourcer
   googlecloudsdk.core.utilr   r<   r"   _GA_API_VERSION_BETA_API_VERSIONReleaseTrackGABETAALPHAr#   r   r   r   DEFAULT_REGIONr  Enumr   r!   r'   r+   r4   rB   rJ   rM   rO   r[   r_   rp   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r  r  r   r   r   <module>r,     s   (  	 A : C , ( > $ : * 
	  	/O_   E G I  dii  %)$5$5$8$8 M "&!2!2!5!5 J ##&& 4IB FBBB6"J,d +/#	$/T ,0 $	#R $(	%V )-8> *.96	@/*/*"J)X!H(!r   