
    \                        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 ddlmZ dd
lmZ ddlmZ ddlmZ ej,                  Z G d dej.                        Zd Zd Zd8dZd Zd Zd8dZ	 	 d9dZd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd  Z(d! Z)d" Z*d# Z+d$ Z,d% Z-	 	 	 d:d&Z.d' Z/d( Z0	 d8d)Z1d*ed+ed,ed-e2d.e2d/e2d0dfd1Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9y);zACode that's shared between multiple backend-services subcommands.    )absolute_import)division)unicode_literals)Any)encoding)poller)waiter)base)
exceptions)reference_utils)log)
propertiesc                        e Zd Z fdZ xZS )CacheKeyQueryStringExceptionc                 ,    t         t        |   d       y )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   z%CacheKeyQueryStringException.__init__&   s    	
&6	56    )__name__
__module____qualname__r   __classcell__)r   s   @r   r   r   $   s    6 6r   r   c                      t         j                  j                  j                  j	                         } | t        j                  d       yy)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                      t                y)z0Gets the default compute flags scope enum value.N)r#    r   r   GetDefaultScoper&   :   s    :<	r   Nc                    | j                  d      }i }|D ]o  }|sd|v r|j                  dd      \  }}nd}d }|dv r)||v rt        j                  dd ||      z        |||<   Rt        j                  dd	 ||      z         |r| st        j                  dd
      d|v rd|v rt        j                  dd      |j                         }d|v rd|_        n'd|v rd|_        n|d|_        n|j                  |_        d|v sd|v rZ|j                  d      |_        |j                  d      |_        |j                  r|j                  st        j                  dd      |S )z$Returns IAP settings from arguments.,=   Tc                 H    t        |       }|j                  d      r|dd  }|S )Nur*   )repr
startswith)srs     r   _Reprz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 --iapr2   r3   z0Must specify only one of [enabled] or [disabled]Fr4   r5   zMBoth [oauth2-client-id] and [oauth2-client-secret] must be specified together)splitr   InvalidArgumentExceptionBackendServiceIAPr2   getoauth2ClientIdoauth2ClientSecret)	iap_argmessagesexisting_iap_settingssubargsiap_arg_parsedsubargvaluer1   iap_settingss	            r   GetIAPrD   @   s    MM#'.f
f}ll3*mfee  * *	>	!11?%-OQ 	Q$nV//
,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                       y)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   IapBestPracticesNoticerF      s    *r   c                       y)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   IapHttpWarningrH      s    Or   c                    d}| j                   rX| j                  d}n0| j                  d}n!|t        j                  k(  r| j
                  d}|t        j                  |d      y| j                  rX| j                  d}n0| j                  d}n!|t        j                  k(  r| j                  d}|t        j                  |d	      yy)
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#max_in_flight_requests_per_endpointr   r7   network_endpoint_groupmax_rate_per_instancemax_connections_per_instance#max_in_flight_requests_per_instance)argsrelease_trackinvalid_args      r   _ValidateGroupMatchesArgsr]      s    +	!!--k		*	*	64k+++44@;k//
<   ""!!--k		*	*	64k+++44@;k//
D   #r   c                    | j                   j                  }|}|j                  r ||j                        }d}d}|t        j                  k(  rG|j
                  r;| j                   j                  }| j                   j                  |j
                        }t        ||       d}||j                  k(  r|j                  d}n,|j                  d}n|j                  d}n|j                  d}|t        j                  k(  rB|j                  d}n3|j                  	 d}n#|j                  	 d}n|||j                   k(  rd	}|t#        j$                  |d
      y||j&                  k(  r|j                  d}n,|j(                  d}n|j*                  d}n|j,                  d}|t        j                  k(  rB|j                  d}n3|j                  	 d}n#|j                  	 d}n|||j                   k(  rd	}|t#        j$                  |d      y||j.                  k(  r#|j0                  t#        j$                  dd      y|t        j                  k(  r||j2                  k(  r|j(                  d}n\|j*                  d}nM|j,                  d}n>|j                  d}n/|j                  d}n |j                  d}n||j                   k7  rd}|t#        j$                  |d      yyy)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-connectionsrN   rK   z--max-in-flight-requestsrO   rL   z--traffic-duration=LONGz&cannot be set with RATE balancing modez
--max-raterM   rJ   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_moderS   rT   traffic_durationTrafficDurationValueValuesEnumr]   RATEmax_utilizationmax_connectionsrX   rR   max_in_flight_requestsrY   rU   LONGr   r7   
CONNECTIONmax_raterW   rQ   UTILIZATIONrV   	IN_FLIGHT)	r=   add_or_update_backend_argscurrent_balancing_moder[   balancing_mode_enumra   rb   traffic_duration_enumr\   s	            r   ValidateBalancingModeArgsrq      sg   " !((EE)...("113N|)))
$
5
5$,,KK''FF"33 6F+*///!11='k	#	3	3	?'k	#	@	@	L4k	#	@	@	L4k***	#	:	:	F0
$
H
H >
$
H
H >

+"7"<"<<///
?A A  ,777!11='k	#	,	,	8 k	#	9	9	E-k	#	9	9	E-k***	#	:	:	F0
$
H
H >
$
H
H >

+"7"<"<<///
EG G  ,888!88D//
$
9  E |)))
/99
9!**6 k	#	9	9	E-k	#	9	9	E-k	#	3	3	?'k	#	@	@	L4k	#	@	@	L4k	277	7Kk//
D  # : *r   c                    | j                   | j                   |_        | j                  | j                  |_        | j                  +| j                  |_        | j                  sg |_        g |_        | j                  | j                  |_        d|_        g |_        | j                  | j                  |_        d|_        g |_        | j                  | j                  |_        | j                  | j                  |_        yy)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)rZ   cache_key_policys     r   UpdateCacheKeyPolicyr   .  s	    
$$0'+'F'F$	  ,#'#>#> 	((4*.*M*M'...0+.0+	**6-- **.',.)	**6-- **.',.)	''3*.*L*L'	((4+/+N+N( 5r   c                     | j                   d u xs | j                   }|s#| j                  | j                  
t               y y N)rw   r{   r|   r   )cache_key_policy_argsinclude_query_strings     r   ValidateCacheKeyPolicyArgsr   O  sV     ::dB ;::  
>>J>>J(** 	K 
r   c                     | j                    xsh | j                   xsY | j                   xsJ | j                  d      xs7 | j                  d      xs$ | j                  d      xs | j                  d      S )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   )ru   rs   rw   IsSpecifiedrZ   s    r   HasCacheKeyPolicyArgsForCreater   Z  s      ))
) =--
-=11
1= 

=
>= 

=
>	=
 

:
;= 

;
<>r   c                 $    | j                  d      S )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   s  s     
		-	..r   c                 $    | j                  d      S )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                 $    | j                  d      S )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                    | j                  d      xsp | j                  d      xs] | j                  d      xsJ | j                  d      xs7 | j                  d      xs$ | j                  d      xs | j                  d      S )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.
  rs   ru   rw   r{   r|   r}   r   r   r   s    r   HasCacheKeyPolicyArgsForUpdater     s     

7
8 =


3
4=


;
<= 

=
>= 

=
>	=
 

:
;= 

;
<>r   c                     | j                   j                         }|j                  ,|j                  j                  |j                  j                  }t	        |       t        ||       |S )aq  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.
  )r=   CacheKeyPolicy	cdnPolicycacheKeyPolicyr   r   )clientrZ   backend_servicer   s       r   GetCacheKeyPolicyr     s`     __335+..:&00??T"t-.	r   c                    i }t        |      }|rN| j                  j                  j                  |j                        |d<   |rt        |      r|j                  |d<   |r" | j                  j                  di ||_        yy)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   r=   
SubsettingPolicyValueValuesEnumr   r   r   
subsetting)r   rZ   r   use_subset_sizesubsetting_argsadd_subsettings         r   ApplySubsettingArgsr     s     /$T*.OO..DD""$  6t<&*&A&Aol#!;!;!;!No!NO r   c                     t        |      r5| j                  j                  j                  |j                        |_        yy)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   r=   BackendService'IpAddressSelectionPolicyValueValuesEnumr   ipAddressSelectionPolicyr   rZ   r   s      r   !ApplyIpAddressSelectionPolicyArgsr     s:     %T*&&NN,,	
 , +r   c                    |j                   |j                  dk(  rG|j                  | j                  j	                         |_        |j                   |j                  _        n|j                  dk(  r|j                  | j                  j                         |_        |j                  j                  )| j                  j                         |j                  _        |j                   |j                  j                  _        |j                  |j                  dk(  r|j                  | j                  j	                         |_        |j                  j                  )| j                  j                         |j                  _        |j                  |j                  j                  _        n|j                  |_        |j                  |j                  dk(  rG|j                  | j                  j	                         |_        |j                  |j                  _        y|j                  dk(  r|j                  | j                  j                         |_        |j                  j                  )| j                  j                         |j                  _        |j                  |j                  j                  _        yyy)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strongSessionAffinityCookier=   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                 6   d}|j                   rRg }|j                   j                         D ]1  \  }}|j                  | j                  j	                  ||             3 |S |j
                  ,|j
                  j                  |j
                  j                  }|S )ax  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appendr=   ,BackendServiceCdnPolicyNegativeCachingPolicyr   negativeCachingPolicy)r   rZ   r   r   r   r   s         r   GetNegativeCachingPolicyr   :  s     !	!! 11779	c$$
//
F
FS G "# : 
! 	 	!!-!!77C / 9 9 O O	  r   c                     d}|j                   r>g }|j                   D ]-  }|j                  | j                  j                  |             / |S )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   r=   1BackendServiceCdnPolicyBypassCacheOnRequestHeader)r   rZ   r   headers       r   GetBypassCacheOnRequestHeadersr   V  sZ     %)!	))&(#66%,,
//
K
K L !" 7
 
)(r   c                 N   |j                    t        j                  |j                         }n| j                  j	                         }|j
                  r4| j                  j                  j                  |j
                        |_        |j                  r4| j                  j                  j                  |j                        |_
        |j                  r|j                  |_        |j                  r|j                  |_        || j                  j	                         k7  r||_         yy)aZ  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   CopyProtoMessager=   &BackendServiceConnectionTrackingPolicy,connection_persistence_on_unhealthy_backends7ConnectionPersistenceOnUnhealthyBackendsValueValuesEnum(connectionPersistenceOnUnhealthyBackendstracking_modeTrackingModeValueValuesEnumtrackingModeidle_timeout_secidleTimeoutSecenable_strong_affinityenableStrongAffinity)r   rZ   r   connection_tracking_policys       r   !ApplyConnectionTrackingPolicyArgsr   k  s    --9!)!:!:00"2 	>>@  
66>>	@	@==
? G
 
>>	$	$T%7%7	8 + 
040E0E-	  ## 3  oo<<>@/IO,@r   c                    |j                    t        j                  |j                         }n| j                  j	                         }|rt        |      }nt        |      }|rt        | ||      |_        |r"|j                  d      r|j                  |_        |j                  |j                  |_        |j                  r4| j                  j                  j                  |j                        |_        |j"                  |j"                  |_        |j&                  |j&                  |_        |j*                  |j*                  |_        |r|j                  dk(  xr |j"                  du }|j.                  s|r|j1                  d       d|_        |j                  dk(  xr |j&                  du }	|j2                  s|	r|j1                  d       d|_        |j                  dk(  xs |j                  dk(  xr |j*                  du }
|j4                  s|
r|j1                  d       d|_        |j6                  |j6                  |_        t;        | ||      }|||_        |j>                  r(|j8                  stA        jB                  d       d	|_        |r<|jD                  s|j6                  $|j6                  s|j1                  d
       g |_        |jF                  |jF                  |_$        tK        | |      }|||_&        |rH|jN                  r|j1                  d       d|_$        |jP                  r|j1                  d       g |_&        || j                  j	                         k7  r||_         yy)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   r=   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   rZ   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    s5   . ***?+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4VT5DF('>J$	!!**D*D KK	#$ "&J))				*43H3H=>)+j&	'!%!7!7J$B64$P!$0-LJ*  78#'j ..CD/1j,6??::<< *O =r   c                 l    | j                  d      s"| j                  d      s| j                  d      ryy)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
    s7     56
23
'(r   c                 *   t        |      r|j                  r|j                  n| j                         }|j                  |j                   |_        |j
                  |j
                  |_        |j                  |j                  |_        ||_        yy)aY  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)r=   rZ   r   failover_policys       r   ApplyFailoverPolicyArgsr    s     4 *9*H*H&&--/  ((4//
/ 6%%1/3/M/Mo,&&*&9&9o#%4O" !r   c                    |j                  d      xs7 |j                  d      xs$ |j                  d      xs |j                  d      }| j                  j                  j                  | j                  j                  j                  | j                  j                  j
                  | j                  j                  j                  | j                  j                  j                  | j                  j                  j                  | j                  j                  j                  | j                  j                  j                  g}|r$|j                  |vrt        j                  dd      |r|j                  r|j                  }n| j                         }|j                   |j                   |_        |j$                  |j$                  |_        |j(                  *| j                  j+                  |j(                        |_        |j.                  0|j.                  |_        |j.                  s||j3                  d       ||_        yy)	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   r7   	logConfigBackendServiceLogConfigr  enabler  
sampleRater  OptionalModeValueValuesEnumoptionalModer  optionalFieldsr   )r=   rZ   r   r   logging_specifiedvalid_protocols
log_configs          r   ApplyLogConfigArgsr,  /  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 *O' r   r   rZ   r   project_namelocationr[   returnc                 6   |j                   r| j                  j                         }|j                   j                         D ]N  \  }}|dk(  rt	        j
                  ||||      |_        *|dk(  r||_        7t        j                  dd|z         ||_
        yy)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.
  authenticationConfig)r-  r.  bac_namer[   sniz--tls-settingszInvalid key: %sN)tls_settingsr=   BackendServiceTlsSettingsr   r   #BuildBackendAuthenticationConfigUrlr1  r3  r   r7   tlsSettings)	r   rZ   r   r-  r.  r[   r4  keyrB   s	            r   ApplyTlsSettingsArgsr9  r  s    * 
??<<>L''--/
U	&	&??)!+	 	) %< 11/#5
 	
 0  #/O% r   c                 z    | j                   r| j                   |_        | j                  r| j                  |_        yy)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)rZ   r   s     r   ApplyCustomMetricsr>    s7     
$($7$7O!	$($<$<O! r   c                     |j                   rR| j                  j                         }| j                  j                         |_        d|j                  _        ||_        yy)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_forwardingr=   BackendServiceDynamicForwarding.BackendServiceDynamicForwardingIpPortSelectionipPortSelectionr2   dynamicForwarding)r   rZ   r   dynamic_forwarding_configs       r   IpPortDynamicForwardingrF    sZ     
$$779  	FFH - 9=--5(AO% %r   c                 J    | j                  d      s| j                  d      ryy)zReturns 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   HasZonalAffinityArgsrJ    s+     
01T5E5E&6 r   c                 
   t        |      r|j                   t        j                  |j                        }n| j                  j                         }|j                   t        j                  |j                        }n| j                  j                         }|j                  r4| j                  j                  j                  |j                        |_
        |j                  r|j                  |_        ||_        ||_        yy)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)rJ  !networkPassThroughLbTrafficPolicyr   r   r=   /BackendServiceNetworkPassThroughLbTrafficPolicyzonalAffinity<BackendServiceNetworkPassThroughLbTrafficPolicyZonalAffinityrH  SpilloverValueValuesEnum	spilloverrI  spilloverRatio)r   rZ   r   &network_pass_through_lb_traffic_policyzonal_affinitys        r   ZonalAffinityrU    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                 \   |j                         dk(  rM| j                  j                  j                   | j                  j
                  di |j                               S | j                  j                  j                   | j                  j                  di |j                               S )z"Send Backend Services get request.compute.regionBackendServicesr%   )	
Collectionapitools_clientregionBackendServicesGetr=   &ComputeRegionBackendServicesGetRequestAsDictbackendServices ComputeBackendServicesGetRequest)r   backend_service_refs     r   SendGetRequestra    s    ##%)HH!!77;;>>> 	,!((*	,- - 
			/	/	3	36foo66 *&&(*
+ +r   c                    d|j                   i}|j                         dk(  rd}|j                  |d<   nd}| j                  |j                  ||      }t        j                  ||      }t        j                  |||      S )a  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.
  projectrW  zcompute.regionOperationsregionzcompute.globalOperations)params
collection)	rc  rX  rd  Parser   r   Pollerr	   WaitFor)		resourcesservice	operationr`  messagere  rf  operation_refoperation_pollers	            r   WaitForOperationrp    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   rS   Errorr   r#   r&   rD   rF   rH   r]   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r,  strr9  r>  rF  rJ  rU  ra  rp  r%   r   r   <module>r}     s^   H &  '  % < . ( . > = # *  6?#8#8 6>B+P
H  	~BOB+>2	/	4	9>,.O* NQb!8)*&JX "'6;&*o+d 5: 	@+F'/'/
'/ '/ 	'/
 '/ '/ 
'/T
=B((V+Br   