
    R                        S 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Jr  SS
KJr  SSKJr  SSKJr  \R,                  r " S S\R.                  5      rS rS rS8S jrS rS rS8S jr  S9S jrS r S r!S r"S r#S r$S r%S r&S r'S  r(S! r)S" r*S# r+S$ r,S% r-   S:S& jr.S' r/S( r0 S8S) jr1S*\S+\S,\S-\2S.\2S/\2S0S4S1 jr3S2 r4S3 r5S4 r6S5 r7S6 r8S7 r9g);zACode that's shared between multiple backend-services subcommands.    )absolute_import)division)unicode_literals)Any)encoding)poller)waiter)base)
exceptions)reference_utils)log)
propertiesc                   (   ^  \ rS rSrU 4S jrSrU =r$ )CacheKeyQueryStringException$   c                 ,   > [         [        U ]  S5        g )Nzcache-key-query-string-whitelist and cache-key-query-string-blacklist may only be set when cache-key-include-query-string is enabled.)superr   __init__)self	__class__s    Qlib/googlecloudsdk/command_lib/compute/backend_services/backend_services_utils.pyr   %CacheKeyQueryStringException.__init__&   s    	
&6	56     )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r   r   $   s    6 6r   r   c                      [         R                  R                  R                  R	                  5       n U b  [
        R                  " S5        gg)z?Warns if core/default_regional_backend_service property is set.NzPcore/default_regional_backend_service property is deprecated and has no meaning.)r   VALUEScore default_regional_backend_serviceGetBoolr   warning)default_regionals    r   8IsDefaultRegionalBackendServicePropertyNoneWarnOtherwiser(   .   sC     ==EEG !KK	 "r   c                      [        5         g)z0Gets the default compute flags scope enum value.N)r(   r   r   r   GetDefaultScoper*   :   s    :<	r   Nc                 0   U R                  S5      n0 nU H{  nU(       d  M  SU;   a  UR                  SS5      u  pVOSnS nUS;   a+  XT;   a   [        R                  " SSU" U5      -  5      eXdU'   M]  [        R                  " SS	U" U5      -  5      e   U(       a  U (       d  [        R                  " SS
5      eSU;   a  SU;   a  [        R                  " SS5      eUR                  5       nSU;   a  SUl        O*SU;   a  SUl        OUc  SUl        OUR                  Ul        SU;   d  SU;   ae  UR                  S5      Ul        UR                  S5      Ul        UR                  (       a  UR                  (       d  [        R                  " SS5      eU$ )z$Returns IAP settings from arguments.,=   Tc                 R    [        U 5      nUR                  S5      (       a  USS  nU$ )Nur.   )repr
startswith)srs     r   _ReprGetIAP.<locals>._ReprQ   s*    
q'a	
c		abEhr   )enableddisabledoauth2-client-idoauth2-client-secretz--iapz(Sub-argument %s specified multiple timeszInvalid sub-argument %sz(Must provide value when specifying --iapr7   r8   z0Must specify only one of [enabled] or [disabled]Fr9   r:   zMBoth [oauth2-client-id] and [oauth2-client-secret] must be specified together)splitr   InvalidArgumentExceptionBackendServiceIAPr7   getoauth2ClientIdoauth2ClientSecret)	iap_argmessagesexisting_iap_settingssubargsiap_arg_parsedsubargvaluer5   iap_settingss	            r   GetIAPrI   @   s    MM#'.f
f}ll3*mfee  * *		!11?%-OQ 	Q$V//
,uV}<> >- 2 
w

-
-;= = . Z>%A

-
-CE E ++-,. L^# L$ L088LN*."0"4"45G"HL&4&8&89O&PL# &&l.M.M//
     
r   c                      g)NzIAP only protects requests that go through the Cloud Load Balancer. See the IAP documentation for important security best practices: https://cloud.google.com/iap/r   r   r   r   IapBestPracticesNoticerK      s    *r   c                      g)NzIAP has been enabled for a backend service that does not use HTTPS. Data sent from the Load Balancer to your VM will not be encrypted.r   r   r   r   IapHttpWarningrM      s    Or   c                    SnU R                   (       ar  U R                  b  SnOGU R                  b  SnO7U[        R                  :X  d  U[        R
                  :X  a  U R                  b  SnUb  [        R                  " US5      egU R                  (       ar  U R                  b  SnOGU R                  b  SnO7U[        R                  :X  d  U[        R
                  :X  a  U R                  b  SnUb  [        R                  " US	5      egg)
zHValidate if the group arg is used with the correct group specific flags.N--max-rate-per-endpoint--max-connections-per-endpoint%--max-in-flight-requests-per-endpointz#cannot be set with --instance-group--max-rate-per-instance--max-connections-per-instance%--max-in-flight-requests-per-instancez+cannot be set with --network-endpoint-group)instance_groupmax_rate_per_endpointmax_connections_per_endpointReleaseTrackALPHABETA#max_in_flight_requests_per_endpointr   r<   network_endpoint_groupmax_rate_per_instancemax_connections_per_instance#max_in_flight_requests_per_instance)argsrelease_trackinvalid_args      r   _ValidateGroupMatchesArgsrc      s   +	!!--k		*	*	64k+++L---

2
2
>;k//
<   ""!!--k		*	*	64k+++L---

2
2
>;k//
D   #r   c                    U R                   R                  nUnUR                  (       a  U" UR                  5      nSnSnU[        R                  :X  d  U[        R
                  :X  aL  UR                  (       a;  U R                   R                  nU R                   R                  UR                  5      n[        X5        SnXTR                  :X  a  UR                  b  SnO/UR                  b  SnOUR                  b  SnOUR                  b  SnU[        R                  :X  d  U[        R
                  :X  aF  UR                  b  SnO6UR                   b  SnO%UR                    b  SnOUb  XgR"                  :X  a  S	nUb  [$        R&                  " US
5      egXTR(                  :X  a  UR                  b  SnO/UR*                  b  SnOUR,                  b  SnOUR.                  b  SnU[        R                  :X  d  U[        R
                  :X  aF  UR                  b  SnO6UR                   b  SnO%UR                    b  SnOUb  XgR"                  :X  a  S	nUb  [$        R&                  " US5      egXTR0                  :X  a%  UR2                  b  [$        R&                  " SS5      egU[        R                  :X  d  U[        R
                  :X  a  XTR4                  :X  a  UR*                  b  SnOaUR,                  b  SnOQUR.                  b  SnOAUR                  b  SnO1UR                  b  SnO!UR                  b  SnOXgR"                  :w  a  SnUb  [$        R&                  " US5      eggg)a  Check whether the setup of the backend LB related fields is valid.

Args:
  messages: API messages class, determined by release track.
  add_or_update_backend_args: argparse Namespace. The arguments provided to
    add-backend or update-backend commands.
  current_balancing_mode: BalancingModeValueValuesEnum. The balancing mode of
    the existing backend, in case of update-backend command. Must be None
    otherwise.
  release_track: The release track of the command.
Nz--max-utilizationz--max-connectionsrS   rP   z--max-in-flight-requestsrT   rQ   z--traffic-duration=LONGz&cannot be set with RATE balancing modez
--max-raterR   rO   z,cannot be set with CONNECTION balancing modez--network-endpoint-groupz-cannot be set with UTILIZATION balancing modez5--traffic-duration=TRAFFIC_DURATION_UNSPECIFIED/SHORTz+cannot be set with IN_FLIGHT balancing mode)BackendBalancingModeValueValuesEnumbalancing_moderX   rY   rZ   traffic_durationTrafficDurationValueValuesEnumrc   RATEmax_utilizationmax_connectionsr^   rW   max_in_flight_requestsr_   r[   LONGr   r<   
CONNECTIONmax_rater]   rV   UTILIZATIONr\   	IN_FLIGHT)	rB   add_or_update_backend_argscurrent_balancing_modera   balancing_mode_enumrg   rh   traffic_duration_enumrb   s	            r   ValidateBalancingModeArgsrw      s   " !((EE)...("113N|)))]l>O>O-O"33$,,KK''FF"33 6F+///!11='k	#	3	3	?'k	#	@	@	L4k	#	@	@	L4k+++L---	#	:	:	F0
$
H
H >
$
H
H >

+"<"<<///
?A A  777!11='k	#	,	,	8 k	#	9	9	E-k	#	9	9	E-k+++L---	#	:	:	F0
$
H
H >
$
H
H >

+"<"<<///
EG G  888!88D//
$
9  E |)))]l>O>O-O777!**6 k	#	9	9	E-k	#	9	9	E-k	#	3	3	?'k	#	@	@	L4k	#	@	@	L4k	77	7Kk//
D  ! 	8 .Pr   c                     U R                   b  U R                   Ul        U R                  b  U R                  Ul        U R                  b0  U R                  Ul        U R                  (       d  / Ul        / Ul        U R                  b  U R                  Ul        SUl        / Ul        U R                  b  U R                  Ul        SUl        / Ul        U R                  b  U R                  Ul        U R                  b  U R                  Ul        gg)zSets the cache_key_policy according to the command line arguments.

Args:
  args: Arguments specified through command line.
  cache_key_policy: new CacheKeyPolicy to be set (or preexisting one if using
    update).
NT)cache_key_include_protocolincludeProtocolcache_key_include_hostincludeHostcache_key_include_query_stringincludeQueryStringqueryStringWhitelistqueryStringBlacklist cache_key_query_string_whitelist cache_key_query_string_blacklistcache_key_include_http_headerincludeHttpHeaderscache_key_include_named_cookieincludeNamedCookies)r`   cache_key_policys     r   UpdateCacheKeyPolicyr   2  s	    
$$0'+'F'F$	  ,#'#>#> 	((4*.*M*M'...0+.0+	**6-- **.',.)	**6-- **.',.)	''3*.*L*L'	((4+/+N+N( 5r   c                     U R                   S L =(       d    U R                   nU(       d%  U R                  c  U R                  b
  [        5       eg g N)r}   r   r   r   )cache_key_policy_argsinclude_query_strings     r   ValidateCacheKeyPolicyArgsr   S  sV     ::dB ;::  
>>J>>J(** 	K 
r   c                 D   U R                   (       + =(       d    U R                  (       + =(       dq    U R                  (       + =(       dY    U R                  S5      =(       dA    U R                  S5      =(       d)    U R                  S5      =(       d    U R                  S5      $ )a  Returns true if create request requires a CacheKeyPolicy message.

Args:
  args: The arguments passed to the gcloud command.

Returns:
  True if there are cache key policy related arguments which require adding
  a CacheKeyPolicy message in the create request.
r   r   r   r   )r{   ry   r}   IsSpecifiedr`   s    r   HasCacheKeyPolicyArgsForCreater   ^  s      ))
) =--
-=11
1= 

=
>= 

=
>	=
 

:
;= 

;
<>r   c                 $    U R                  S5      $ )zReturns true if request requires a Subsetting message.

Args:
  args: The arguments passed to the gcloud command.

Returns:
  True if request requires a Subsetting message.
subsetting_policyr   r   s    r   HasSubsettingArgsr   w  s     
		-	..r   c                 $    U R                  S5      $ )zReturns true if request requires a Subsetting.subset_size field.

Args:
  args: The arguments passed to the gcloud command.

Returns:
  True if request requires a Subsetting.subset_size field.
subsetting_subset_sizer   r   s    r   HasSubsettingSubsetSizeArgsr     s     
		2	33r   c                 $    U R                  S5      $ )zReturns true if request requires an IP address selection policy.

Args:
  args: The arguments passed to the gcloud command.

Returns:
  True if request requires an IP address selection policy.
ip_address_selection_policyr   r   s    r   HasIpAddressSelectionPolicyArgsr     s     
		7	88r   c                 D   U R                  S5      =(       d    U R                  S5      =(       dq    U R                  S5      =(       dY    U R                  S5      =(       dA    U R                  S5      =(       d)    U R                  S5      =(       d    U R                  S5      $ )a  Returns true if update request requires a CacheKeyPolicy message.

Args:
  args: The arguments passed to the gcloud command.

Returns:
  True if there are cache key policy related arguments which require adding
  a CacheKeyPolicy message in the update request.
ry   r{   r}   r   r   r   r   r   r   s    r   HasCacheKeyPolicyArgsForUpdater     s     

7
8 =


3
4=


;
<= 

=
>= 

=
>	=
 

:
;= 

;
<>r   c                     U R                   R                  5       nUR                  b-  UR                  R                  b  UR                  R                  n[	        U5        [        X5        U$ )a_  Validates and returns the cache key policy.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object. If the backend service object
    contains a cache key policy already, it is used as the base to apply
    changes based on args.

Returns:
  The cache key policy.
)rB   CacheKeyPolicy	cdnPolicycacheKeyPolicyr   r   )clientr`   backend_servicer   s       r   GetCacheKeyPolicyr     s]     __335+..:&00??T"t.	r   c                 .   0 n[        U5      nU(       aX  U R                  R                  R                  UR                  5      US'   U(       a  [        U5      (       a  UR                  US'   U(       a"  U R                  R                  " S0 UD6Ul        gg)a  Applies the Subsetting argument(s) to the specified backend service.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object.
  use_subset_size: Should Subsetting.subset_size be used?
policy
subsetSizeNr   )r   rB   
SubsettingPolicyValueValuesEnumr   r   r   
subsetting)r   r`   r   use_subset_sizesubsetting_argsadd_subsettings         r   ApplySubsettingArgsr     s     /$T*.OO..DD""$  6t<<&*&A&Aol#!'!;!;!No!NO r   c                     [        U5      (       a5  U R                  R                  R                  UR                  5      Ul        gg)zApplies the IP address selection policy argument to the backend service.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object.
N)r   rB   BackendService'IpAddressSelectionPolicyValueValuesEnumr   ipAddressSelectionPolicyr   r`   r   s      r   !ApplyIpAddressSelectionPolicyArgsr     s=     %T**&&NN,,	
 , +r   c                    UR                   b  UR                  S:X  aH  UR                  c  U R                  R	                  5       Ul        UR                   UR                  l        OUR                  S:X  a  UR                  c  U R                  R                  5       Ul        UR                  R                  c)  U R                  R                  5       UR                  l        UR                   UR                  R                  l        UR                  b  UR                  S:X  a  UR                  c  U R                  R	                  5       Ul        UR                  R                  c)  U R                  R                  5       UR                  l        UR                  UR                  R                  l        OUR                  Ul        UR                  b  UR                  S:X  aH  UR                  c  U R                  R	                  5       Ul        UR                  UR                  l        gUR                  S:X  a  UR                  c  U R                  R                  5       Ul        UR                  R                  c)  U R                  R                  5       UR                  l        UR                  UR                  R                  l        ggg)a  Applies the --affinity-cookie-name and --affinity-cookie-ttl arguments to the backend service.

The values are written into the backend_service message as follows:

- HTTP_COOKIE: name copied into backend_service.hashPolicy.httpCookie.name,
  TTL copied into backendService.affinityCookieTtlSec.
- GENERATED_COOKIE: TTL copied into backendService.affinityCookieTtlSec.
- STRONG_COOKIE_AFFINITY: name copied into
  backendService.strongSessionAffinityCookie.name, TTL copied into
  backendService.strongSessionAffinityCookie.ttl. (STRONG_COOKIE_AFFINITY
  does not fall back to affinityCookieTtlSec the same way HTTP_COOKIE does.)

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object.
NSTRONG_COOKIE_AFFINITYHTTP_COOKIE)affinity_cookie_namesession_affinitystrongSessionAffinityCookierB   BackendServiceHttpCookienameconsistentHash"ConsistentHashLoadBalancerSettings
httpCookie,ConsistentHashLoadBalancerSettingsHttpCookieaffinity_cookie_ttlttlDurationsecondsaffinityCookieTtlSecaffinity_cookie_pathpathr   s      r   ApplyAffinityCookieArgsr     sd   $ 
* 88		4	4	<OO446 	3 
#
# 116 
		-	/		'	'	/OO>>@ 	& 
	'	'	2	2	:OOHHJ 	&&1 8<7P7Po$$//4	)  88		4	4	<OO446 	3 
	4	4	8	8	@OO$$& 	337 
"
" 1155= .2-E-Eo*	* 88		4	4	<OO446 	3 
#
# 116 
		-	/		'	'	/OO>>@ 	& 
	'	'	2	2	:OOHHJ 	&&1 8<7P7Po$$//4 
0 +r   c                 >   SnUR                   (       aO  / nUR                   R                  5        H-  u  pEUR                  U R                  R	                  XES95        M/     U$ UR
                  b-  UR
                  R                  b  UR
                  R                  nU$ )af  Returns the negative caching policy.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object. If the backend service object
    contains a negative caching policy already, it is used as the base to
    apply changes based on args.

Returns:
  The negative caching policy.
N)coder   )negative_caching_policyitemsappendrB   ,BackendServiceCdnPolicyNegativeCachingPolicyr   negativeCachingPolicy)r   r`   r   r   r   r   s         r   GetNegativeCachingPolicyr   >  s     !	!! 11779	$$
//
F
F G "# : 
! 	 	!!-!!77C / 9 9 O O	  r   c                     SnUR                   (       a=  / nUR                    H+  nUR                  U R                  R                  US95        M-     U$ )zReturns bypass cache on request headers.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.

Returns:
  The bypass cache on request headers.
N)
headerName)bypass_cache_on_request_headersr   rB   1BackendServiceCdnPolicyBypassCacheOnRequestHeader)r   r`   r   headers       r   GetBypassCacheOnRequestHeadersr   Z  sZ     %)!	))&(#66%,,
//
K
K L !" 7
 
)(r   c                 z   UR                   b!  [        R                  " UR                   5      nOU R                  R	                  5       nUR
                  (       a4  U R                  R                  R                  UR
                  5      Ul        UR                  (       a4  U R                  R                  R                  UR                  5      Ul
        UR                  (       a  UR                  Ul        UR                  (       a  UR                  Ul        UU R                  R	                  5       :w  a  X2l         gg)aL  Applies the connection tracking policy arguments to the specified backend service.

If there are no arguments related to connection tracking policy, the backend
service remains unmodified.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object.
N)connectionTrackingPolicyr   CopyProtoMessagerB   &BackendServiceConnectionTrackingPolicy,connection_persistence_on_unhealthy_backends7ConnectionPersistenceOnUnhealthyBackendsValueValuesEnum(connectionPersistenceOnUnhealthyBackendstracking_modeTrackingModeValueValuesEnumtrackingModeidle_timeout_secidleTimeoutSecenable_strong_affinityenableStrongAffinity)r   r`   r   connection_tracking_policys       r   !ApplyConnectionTrackingPolicyArgsr   o  s    --9!)!:!:00"2 	>>@  
66>>	@	@==
? G
 
>>	$	$T%7%7	8 + 
040E0E-	  ## 3  oo<<>@/I,@r   c                    UR                   b!  [        R                  " UR                   5      nOU R                  R	                  5       nU(       a  [        U5      nO[        U5      nU(       a  [        XU5      Ul        U(       a'  UR                  S5      (       a  UR                  Ul        UR                  b  UR                  Ul        UR                  (       a4  U R                  R                  R                  UR                  5      Ul        UR"                  b  UR"                  Ul        UR&                  b  UR&                  Ul        UR*                  b  UR*                  Ul        U(       Ga  UR                  S:H  =(       a    UR"                  SL nUR.                  (       d  U(       a  UR1                  S5        SUl        UR                  S:H  =(       a    UR&                  SL n	UR2                  (       d  U	(       a  UR1                  S5        SUl        UR                  S:H  =(       d    UR                  S:H  =(       a    UR*                  SL n
UR4                  (       d  U
(       a  UR1                  S5        SUl        UR6                  b  UR6                  Ul        [;        XU5      nUb  Xl        UR>                  (       a.  UR8                  (       d  [@        RB                  " S5        S	Ul        U(       aG  URD                  (       d  UR6                  b)  UR6                  (       d  UR1                  S
5        / Ul        URF                  b  URF                  Ul$        [K        X5      nUb  Xl&        U(       aR  URN                  (       a  UR1                  S5        SUl$        URP                  (       a  UR1                  S5        / Ul&        X`R                  R	                  5       :w  a  Xbl         gg)a  Applies the CdnPolicy arguments to the specified backend service.

If there are no arguments related to CdnPolicy, the backend service remains
unmodified.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object.
  is_update: True if this is called on behalf of an update command instead of
    a create command, False otherwise.
  apply_signed_url_cache_max_age: If True, also adds the
    signedUrlCacheMaxAgeSec parameter to the CdnPolicy if present in the input
    arguments.
  cleared_fields: Reference to list with fields that should be cleared. Valid
    only for update command.
Nsigned_url_cache_max_ageUSE_ORIGIN_HEADERSzcdnPolicy.clientTtlzcdnPolicy.defaultTtlFORCE_CACHE_ALLzcdnPolicy.maxTtlzSetting a negative cache policy also enabled negative caching. If this was not intended, disable negative caching with `--no-negative-caching`.TzcdnPolicy.negativeCachingPolicyzcdnPolicy.serveWhileStalez%cdnPolicy.bypassCacheOnRequestHeaders))r   r   r   rB   BackendServiceCdnPolicyr   r   r   r   r   r   signedUrlCacheMaxAgeSecrequest_coalescingrequestCoalescing
cache_modeCacheModeValueValuesEnum	cacheMode
client_ttl	clientTtldefault_ttl
defaultTtlmax_ttlmaxTtlno_client_ttlr   no_default_ttl
no_max_ttlnegative_cachingnegativeCachingr   r   r   r   r&   no_negative_caching_policiesserve_while_staleserveWhileStaler   bypassCacheOnRequestHeadersno_serve_while_stale"no_bypass_cache_on_request_headers)r   r`   r   	is_updateapply_signed_url_cache_max_agecleared_fields
cdn_policyadd_cache_key_policyshould_clean_client_ttlshould_clean_default_ttlshould_clean_max_ttlr   r   s                r   ApplyCdnPolicyArgsr    s,   . ***?+D+DEJ88:J9$?9$? 1& PJ#(8(8 )" )")-)F)FJ&	(#'#:#:J 	__"OOCC55dooF 	__ ??J	! ,,J	\\J#2FF  ;#'??d#: 412!j $3G G !=$($4$4$< 623"j!__0DD E $3D D5 $ 4  ../j	&!%!6!6J4V5DF('>$	!!**D*D KK	#$ "&J))				*43H3H=>)+j&	'!%!7!7J$B6$P!$0-L*  78#'j ..CD/1j,??::<< * =r   c                     U R                  S5      (       d,  U R                  S5      (       d  U R                  S5      (       a  gg)zReturns true if at least one of the failover policy args is defined.

Args:
  args: The arguments passed to the gcloud command.
connection_drain_on_failoverdrop_traffic_if_unhealthyfailover_ratioTFr   r   s    r   HasFailoverPolicyArgsr  
  s@     566
233
'((r   c                 J   [        U5      (       a  UR                  (       a  UR                  OU R                  5       nUR                  b  UR                  (       + Ul        UR
                  b  UR
                  Ul        UR                  b  UR                  Ul        X2l        gg)aK  Applies the FailoverPolicy arguments to the specified backend service.

If there are no arguments related to FailoverPolicy, the backend service
remains unmodified.

Args:
  messages: The available API proto messages.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service proto message object.
N)	r  failoverPolicyBackendServiceFailoverPolicyr   disableConnectionDrainOnFailoverr  dropTrafficIfUnhealthyr  failoverRatio)rB   r`   r   failover_policys       r   ApplyFailoverPolicyArgsr    s     4  *9*H*H&&--/  ((4//
/ 6%%1/3/M/Mo,&&*&9&9o#%4" !r   c                    UR                  S5      =(       dA    UR                  S5      =(       d)    UR                  S5      =(       d    UR                  S5      nU R                  R                  R                  U R                  R                  R                  U R                  R                  R
                  U R                  R                  R                  U R                  R                  R                  U R                  R                  R                  U R                  R                  R                  U R                  R                  R                  /nU(       a'  UR                  U;  a  [        R                  " SS5      eU(       a  UR                  (       a  UR                  nOU R                  5       nUR                   b  UR                   Ul        UR$                  b  UR$                  Ul        UR(                  b*  U R                  R+                  UR(                  5      Ul        UR.                  b6  UR.                  Ul        UR.                  (       d  Ub  UR3                  S5        Xbl        gg)	a  Applies the LogConfig arguments to the specified backend service.

If there are no arguments related to LogConfig, the backend service
remains unmodified.

Args:
  messages: The available API proto messages.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service proto message object.
  cleared_fields: Reference to list with fields that should be cleared. Valid
    only for update command.
enable_logginglogging_sample_ratelogging_optionallogging_optional_fieldsz
--protocolzcan only specify --enable-logging, --logging-sample-rate, --logging-optional or --logging-optional-fields if the protocol is HTTP/HTTPS/HTTP2/H2C/TCP/SSL/UDP/UNSPECIFIED.NzlogConfig.optionalFields)r   r   ProtocolValueValuesEnumHTTPHTTPSHTTP2TCPSSLUDPUNSPECIFIEDH2Cprotocolr   r<   	logConfigBackendServiceLogConfigr  enabler  
sampleRater  OptionalModeValueValuesEnumoptionalModer  optionalFieldsr   )rB   r`   r   r  logging_specifiedvalid_protocols
log_configs          r   ApplyLogConfigArgsr2  3  s   & '( 5			/	05			,	-5 
		3	4	  55::55;;55;;55995599559955AA5599	/ ?33?J

-
-I    ",,j335j&--j+"66j(

*
*
F
F## 
 ##/"&">">j))n.H89 *' r   r   r`   r   project_namelocationra   returnc                    [        US5      (       a  UR                  (       a  U R                  R                  5       nUR                  R	                  5        HO  u  pxUS:X  a  [
        R                  " UUUUS9Ul        M)  US:X  a  Xl        M7  [        R                  " SSU-  5      e   Xbl        g[        US5      (       aD  UR                  (       a2  U R                  R                  5       nUR                  Ul        Xbl        ggg)	a  Applies the TlsSettings arguments to the specified backend service.

If there are no arguments related to TlsSettings, the backend service remains
unmodified.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service proto message object.
  project_name: The project name of the backend service.
  location: The location of the backend service.
  release_track: The release track of the backend service.
tls_settingsauthenticationConfig)r3  r4  bac_namera   sniz--tls-settingszInvalid key: %sidentityN)hasattrr7  rB   BackendServiceTlsSettingsr   r   #BuildBackendAuthenticationConfigUrlr8  r:  r   r<   tlsSettingsr;  )	r   r`   r   r3  r4  ra   r7  keyrG   s	            r   ApplyTlsSettingsArgsrA  v  s    * T>""t'8'8??<<>L''--/
	&	&??)!+	 	) %< 11/#5
 	
 0  #/tZ  T]]??<<>L MML". &3 r   c                     U R                   (       a  U R                   Ul        U R                  (       a  U R                  Ul        gg)zApplies the Custom Metrics argument to the backend service.

Args:
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object.
N)custom_metricscustomMetricscustom_metrics_file)r`   r   s     r   ApplyCustomMetricsrF    s7     
$($7$7O!	$($<$<O! r   c                     UR                   (       aQ  U R                  R                  5       nU R                  R                  5       Ul        SUR                  l        X2l        gg)zEnables the Ip Port Dynamic Forwarding in the backend service.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object.
TN)ip_port_dynamic_forwardingrB   BackendServiceDynamicForwarding.BackendServiceDynamicForwardingIpPortSelectionipPortSelectionr7   dynamicForwarding)r   r`   r   dynamic_forwarding_configs       r   IpPortDynamicForwardingrN    sX     
$$779  	FFH - 9=--5(A% %r   c                 ^    U R                  S5      (       d  U R                  S5      (       a  gg)zReturns true if at least one of the zonal affinity args is defined.

Args:
  args: The arguments passed to the gcloud command.
zonal_affinity_spilloverzonal_affinity_spillover_ratioTFr   r   s    r   HasZonalAffinityArgsrR    s3     
011T5E5E&6 6 r   c                 0   [        U5      (       Ga  UR                  b!  [        R                  " UR                  5      nOU R                  R                  5       nUR                  b!  [        R                  " UR                  5      nOU R                  R                  5       nUR                  (       a4  U R                  R                  R                  UR                  5      Ul
        UR                  (       a  UR                  Ul        XCl        UUl        gg)zApplies the Zonal Affinity related aguments in the backend service.

Args:
  client: The client used by gcloud.
  args: The arguments passed to the gcloud command.
  backend_service: The backend service object.
N)rR  !networkPassThroughLbTrafficPolicyr   r   rB   /BackendServiceNetworkPassThroughLbTrafficPolicyzonalAffinity<BackendServiceNetworkPassThroughLbTrafficPolicyZonalAffinityrP  SpilloverValueValuesEnum	spilloverrQ  spilloverRatio)r   r`   r   &network_pass_through_lb_traffic_policyzonal_affinitys        r   ZonalAffinityr]    s     $88D/7/H/H

;
;0,
 //
I
I
K - .;;G00
0
>
>n
 //
V
V
X  $$!'!m!m  "G  "G

'
'"n **&*&I&In#;I8 	/ 5;  r   c                 ^   UR                  5       S:X  aM  U R                  R                  R                  U R                  R
                  " S0 UR                  5       D65      $ U R                  R                  R                  U R                  R                  " S0 UR                  5       D65      $ )z"Send Backend Services get request.compute.regionBackendServicesr   )	
Collectionapitools_clientregionBackendServicesGetrB   &ComputeRegionBackendServicesGetRequestAsDictbackendServices ComputeBackendServicesGetRequest)r   backend_service_refs     r   SendGetRequestri    s    ##%)HH!!77;;>> 	,!((*	,- - 
			/	/	3	3oo66 *&&(*
+ +r   c                     SUR                   0nUR                  5       S:X  a  SnUR                  US'   OSnU R                  UR                  XVS9n[
        R                  " X5      n[        R                  " XU5      $ )ak  Waits for the backend service operation to finish.

Args:
  resources: The resource parser.
  service: apitools.base.py.base_api.BaseApiService, the service representing
    the target of the operation.
  operation: The operation to wait for.
  backend_service_ref: The backend service reference.
  message: The message to show.

Returns:
  The operation result.
projectr_  zcompute.regionOperationsregionzcompute.globalOperations)params
collection)	rk  r`  rl  Parser   r   Pollerr	   WaitFor)		resourcesservice	operationrh  messagerm  rn  operation_refoperation_pollers	            r   WaitForOperationrx  	  s~     *223&##%)HH+J*11F8+J//nnV " <-]]7@	(	AAr   r   )NN)FFN):__doc__
__future__r   r   r   typingr   apitools.base.pyr   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   r   "googlecloudsdk.command_lib.computer   googlecloudsdk.corecore_exceptionsr   r   rX   Errorr   r(   r*   rI   rK   rM   rc   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r2  strrA  rF  rN  rR  r]  ri  rx  r   r   r   <module>r     s^   H &  '  % < . ( . > = # *  6?#8#8 6>B+P
H  	BJOB+>2	/	4	9>,.O* NQb!8)*&JX "'6;&*o+d 5: 	@+F+/+/
+/ +/ 	+/
 +/ +/ 
+/\
=B((V+Br   