
    .>                    j   S r SSKJr  SSKJr  SSKr SSKJr   SSKJ	r	  Sr
SrS	rS
rSrS\\S.rSrSrSrSrSrSrSrSSS.rSSSSSSSSS S!S"S#S$S%S&S'.rS( rS) rS* rS+ rS, rS- rS:S. jrS/ r S0 r!S1 r"S2 r#S3 r$S4 r%S5 r&S6 r'S7 r(S8 r)S;S9 jr*g! \ a	    SSKJr   Nf = f! \ a	    SSKJ	r	   Nf = f)<zDConversions to translate between legacy YAML and OnePlatform protos.    )absolute_import)annotationsN)dispatchinfo)appinfo<   i  i ʚ;)urlRegexloginauthFailActionsecurityLevelredirectHttpResponseCode)
scriptPath)pathuploadPathRegexhttpHeaders
expirationapplicationReadablemimeTyperequireMatchingFile)staticFilesscriptapiEndpoint)targetRequestCountPerSectargetConcurrentRequeststargetRequestCountPerSecond)targetWriteBytesPerSectargetWriteOpsPerSectargetReadBytesPerSectargetReadOpsPerSectargetWriteBytesPerSecondtargetWriteOpsPerSecondtargetReadBytesPerSecondtargetReadOpsPerSecond)targetSentBytesPerSectargetSentPacketsPerSectargetReceivedBytesPerSectargetReceivedPacketsPerSectargetSentBytesPerSecondtargetSentPacketsPerSecondtargetReceivedBytesPerSecondtargetReceivedPacketsPerSecond)fixedmanagedUNSPECIFIED_ROLLOUT_STRATEGY)maxInstancesminInstancestargetCpuUtilizationtargetThroughputUtilization)hostProjectIdsubnetALL_TRAFFICPRIVATE_IP_RANGES)zall-trafficzprivate-ranges-only)BUNDLED_SERVICE_TYPE_APP_IDENTITY_SERVICEBUNDLED_SERVICE_TYPE_BLOBSTORE'BUNDLED_SERVICE_TYPE_CAPABILITY_SERVICE!BUNDLED_SERVICE_TYPE_DATASTORE_V3BUNDLED_SERVICE_TYPE_DEFERREDBUNDLED_SERVICE_TYPE_IMAGESBUNDLED_SERVICE_TYPE_MAILBUNDLED_SERVICE_TYPE_MEMCACHEBUNDLED_SERVICE_TYPE_MODULESBUNDLED_SERVICE_TYPE_NAMESPACESBUNDLED_SERVICE_TYPE_NDBBUNDLED_SERVICE_TYPE_SEARCHBUNDLED_SERVICE_TYPE_TASKQUEUESBUNDLED_SERVICE_TYPE_URLFETCHBUNDLED_SERVICE_TYPE_USERS)app_identity_service	blobstorecapability_servicedatastore_v3deferredimagesmailmemcachemodules
namespacesndbsearch	taskqueueurlfetchuserc                    [        U 5      [        ;  a#  [        SU  S[        R                  5        35      e[        [        U 5         $ )zConverts a string to a bundled service type.

Args:
  value: The bundled service name (string).

Returns:
  The corresponding enum value (string).

Raises:
  ValueError: If the provided value is not a valid bundled service name.
zValue "z8" is not a valid bundled service name. Expected one of: )str_BUNDLED_SERVICE_TYPE_ENUM
ValueErrorkeysvalues    Alib/googlecloudsdk/appengine/admin/tools/conversion/converters.pyToBundledServiceTypeEnumr\      sP     	Z11

% 6;;=>	@  
$CJ	//    c                    [        U 5      [        ;  a/  [        SSR                  [        R	                  5       5      -  5      e[        [        U 5         $ )z*Converts a string to a VPC egress setting.z#egress_setting must be one of: [%s],)rU   _VPC_EGRESS_SETTING_MAPrW   joinrX   rY   s    r[   ToVpcEgressSettingEnumrb      sK    Z..
-
((*//1
2	3  
!U	,,r]   c                   ^  T (       d  [        S5      eT T R                  5       :w  a  [        S5      eT R                  S5      (       a  [        ST -  5      eU 4S j$ )aD  Create conversion function which translates from string to enum value.

Args:
  prefix: Prefix for enum value. Expected to be an upper-cased value.

Returns:
  A conversion function which translates from string to enum value.

Raises:
  ValueError: If an invalid prefix (empty, non-upper-cased, etc.) prefix was
  provided.
zA prefix must be providedz#Upper-cased prefix must be provided_z5Prefix should not contain a trailing underscore: "%s"c                X   > SR                  T[        U 5      R                  5       /5      $ )Nrd   )ra   rU   upper)rZ   prefixs    r[   <lambda>EnumConverter.<locals>.<lambda>   s     sxxU)9)9); <=r]   )rW   rf   endswith)rg   s   `r[   EnumConverterrk      s\     

0
11v||~
:
;;__S
?&HJ J 
>=r]   c                V    [        U [        5      (       d  [        SU -  5      eU (       + $ )z6Convert the given boolean value to the opposite value.z"Expected a boolean value. Got "%s")
isinstanceboolrW   rY   s    r[   Notro      s(    	E4	 	 
9EA
BBr]   c                    [        U [        [        45      (       a  [        SU -  5      e[        U [        5      (       a  [        U 5      R                  5       $ [        U 5      $ )a9  Coerces a primitive value into a JSON-compatible string.

Special handling for boolean values, since the Python version (True/False) is
incompatible with the JSON version (true/false).

Args:
  value: value to convert.

Returns:
  Value as a string.

Raises:
  ValueError: when a non-primitive value is provided.
z$Expected a primitive value. Got "%s")rm   listdictrW   rn   rU   lowerrY   s    r[   ToJsonStringrt      sP     d|$$
;eC
DDtu:	Ur]   c                4    [        U 5      R                  5       $ )a  Coerces a primitive value into a upper-case JSON-compatible string.

Special handling for  values whose JSON version is in upper-case.

Args:
  value: value to convert.

Returns:
  Value as a string.

Raises:
  ValueError: when a non-primitive value is provided.
)rU   rf   rY   s    r[   ToUpperCaseJsonStringrv      s     
U			r]   c                   ^  U 4S jnU$ )zCreate conversion function which converts from a string to an integer.

Args:
  handle_automatic: Boolean indicating whether a value of "automatic" should
    be converted to 0.

Returns:
  A conversion function which converts a string to an integer.
c                6   > U S:X  a  T(       a  g[        U 5      $ )N	automaticr   int)rZ   handle_automatics    r[   ConvertStringToInt.<locals>.Convert   s     0u:r]    )r|   r}   s   ` r[   StringToIntr      s    
 
.r]   c                    S[        U 5      -  $ )z9Convert seconds expressed as integer to a Duration value.%ssrz   rY   s    r[   SecondsToDurationr      s    	U	r]   c                    [         R                  " [        R                  5      R	                  U 5      (       d  [        SU -  5      eU S:X  a  gU R                  S5      (       a  S[        U SS 5      [        -  -  $ U $ )zConvert valid pending latency argument to a Duration value of seconds.

Args:
  value: A string in the form X.Xs or XXms.

Returns:
  Duration value of the given argument.

Raises:
  ValueError: if the given value isn't parseable.
zUnrecognized latency: %sry   Nmsr   )	recompiler   _PENDING_LATENCY_REGEXmatchrW   rj   float_MILLISECONDS_PER_SECONDrY   s    r[   LatencyToDurationr      sp     
G22	3	9	9%	@	@
/%7
88
k
^^DE%*%(@@AALr]   c                    [         R                  " [        R                  5      R	                  U 5      (       d  [        SU -  5      eU R                  S5      (       a  S[        U SS 5      [        -  -  $ U $ )zConvert valid idle timeout argument to a Duration value of seconds.

Args:
  value: A string in the form Xm or Xs

Returns:
  Duration value of the given argument.

Raises:
  ValueError: if the given value isn't parseable.
zUnrecognized idle timeout: %smr   N)	r   r   r   _IDLE_TIMEOUT_REGEXr   rW   rj   r{   _SECONDS_PER_MINUTErY   s    r[   IdleTimeoutToDurationr     sd     
G//	0	6	6u	=	=
4u<
==
^^CCcr
O&99::Lr]   c                    [         R                  " [        R                  5      R	                  U 5      (       d  [        SU -  5      e[        R                  " U 5      nSU-  $ )zConvert valid expiration argument to a Duration value of seconds.

Args:
  value: String that matches _DELTA_REGEX.

Returns:
  Time delta expressed as a Duration.

Raises:
  ValueError: if the given value isn't parseable.
zUnrecognized expiration: %sr   )r   r   r   _EXPIRATION_REGEXr   rW   ParseExpiration)rZ   deltas     r[   ExpirationToDurationr   *  sO     
G--	.	4	4U	;	;
2U:
;;

!
!%
(%	r]   c                |   ^  U 4S jnU" [         S5        U" [        S5        U" [        S5        U" [        S5        T $ )aB  Moves several VM-specific automatic scaling parameters to submessages.

For example:
Input {
  "targetSentPacketsPerSec": 10,
  "targetReadOpsPerSec": 2,
  "targetRequestCountPerSec": 3
}
Output {
  "networkUtilization": {
    "targetSentPacketsPerSec": 10
  },
  "diskUtilization": {
    "targetReadOpsPerSec": 2
  },
  "requestUtilization": {
    "targetRequestCountPerSec": 3
  }
}

Args:
  automatic_scaling: Result of converting automatic_scaling according to
    schema.
Returns:
  AutomaticScaling which has moved network/disk utilization related fields to
  submessage.
c                Z   > 0 nU  H  nUT;   d  M  TU   X#'   TU	 M     U(       a  UTU'   g g )Nr   )field_namestarget_field_nametarget
field_nameautomatic_scalings       r[   MoveFieldsTo-ConvertAutomaticScaling.<locals>.MoveFieldsToX  sF    F!
	(	(.z:j) " -3)* r]   requestUtilizationdiskUtilizationnetworkUtilizationstandardSchedulerSettings)#_REQUEST_UTILIZATION_SCALING_FIELDS _DISK_UTILIZATION_SCALING_FIELDS#_NETWORK_UTILIZATION_SCALING_FIELDS_STANDARD_SCHEDULER_SETTINGS)r   r   s   ` r[   ConvertAutomaticScalingr   <  s@    84 24HI/1BC24HI+-HI	r]   c                   S n[        U 5      nUS:X  aw   [        R                  " U S   5      nUR                  (       a  [	        SU S   -   5      e U" U S   S5      U" U S   S5      U" U S   S5      S	.nU S	 U R                  U5        S
n0 n0 XR'   [        U    H  nX`;   d  M
  X   XR   U'   M     [         H  nXp;   d  M
  X   XW'   M     U$ ! [        R
                   a     Nf = f)a  Rejiggers the structure of the url handler based on its type.

An extra level of message nesting occurs here, based on the handler type.
Fields common to all handler types occur at the top-level, while
handler-specific fields will go into a submessage based on handler type.

For example, a static files handler is transformed as follows:
Input {
  "urlRegex": "foo/bar.html",
  "path": "static_files/foo/bar.html"
}
Output {
  "urlRegex": "foo/bar.html",
  "staticFiles": {
    "path": "static_files/foo/bar.html"
  }
}

Args:
  handler: Result of converting handler according to schema.

Returns:
  Handler which has moved fields specific to the handler's type to a
  submessage.
c                0    U R                  S5      S-   U-   $ )zAEquivalent to os.path.join(), except uses forward slashes always./)rstrip)r   regexs     r[   AppendRegexToPath,ConvertUrlHandler.<locals>.AppendRegexToPath  s    ;;sc!E))r]   staticDirectoryr   z>Groups are not allowed in URLs for static directory handlers: 	staticDirz\1z.*z(.*))r   r   r   r   )	_GetHandlerTyper   r   groupsrW   errorupdate_HANDLER_FIELDS_COMMON_HANDLER_FIELDS)handlerr   handler_typecompiledtmpnew_handlerfieldcommon_fields           r[   ConvertUrlHandlerr   g  s    6* !),
 &&!GJ/0h 
LJ ! 	! 

 "'+"6>,W[-A4H%gj&96BC
 	NN3 L+ +|,e)0k& -
 -l")"7k - 
9 88 
s   C C%$C%c                   [         R                  " U S   5      nU S   nUR                  nUR                  (       d  SU-   nUR                  nUR
                  (       d  UR                  S5      S-   n0 nX5S'   XES'   X%S'   U$ )a  Create conversion function which handles dispatch rules.

Extract domain and path from dispatch url,
set service value from service or module info.

Args:
  handler: Result of converting handler according to schema.

Returns:
  Handler which has 'domain', 'path' and 'service' fields.
urlservice*r   z/*domainr   )r   	ParsedURLhost
host_exactr   
path_exactr   )r   dispatch_urldispatch_servicedispatch_domaindispatch_pathr   s         r[   ConvertDispatchHandlerr     s     ''7,Y' %%/		 	 O+O##-		 	 !((-4M+)h%f+i	r]   c                V    SU ;   a  gSU ;   a  gSU ;   a  gSU ;   a  g[        SU -  5      e)	zGet handler type of mapping.

Args:
  handler: Original handler.

Returns:
  Handler type determined by which handler id attribute is set.

Raises:
  ValueError: when none of the handler id attributes are set.
r   r   r   r   r   r   r   zUnrecognized handler type: %s)rW   )r   s    r[   r   r     sA     ggw2W<==r]   c                d    U c  [         $ U [        ;   a  U R                  5       $ [        SU -  5      e)a  Converts the rollout strategy to an enum.

In the YAML file, the user does not use the enum values directly. Therefore we
must convert these to their corresponding enum values in version.proto.

Args:
  value: A string that is a valid rollout strategy ("fixed" or "managed")

Returns:
  Value converted to the proper enum value. Defaults to
  "UNSPECIFIED_ROLLOUT_STRATEGY"

Raises:
  ValueError: When the value is set and is not one of "fixed" or "managed".
z!Unrecognized rollout strategy: %s)2_ENDPOINTS_UNSPECIFIED_ROLLOUT_STRATEGY_ENUM_VALUE"_ENDPOINTS_ROLLOUT_STRATEGY_VALUESrf   rW   rY   s    r[   %ConvertEndpointsRolloutStrategyToEnumr     s5      ]==
00;;=6>??r]   c                \    U c  Sn U R                  S5      (       a  U [        S5      S n SU 0$ )a  Converts the raw entrypoint to a nested shell value.

In the YAML file, the user specifies an entrypoint value. However, the version
resource expects it to be nested under a 'shell' key. In addition, Zeus
always prepends 'exec' to the value provided, so we remove it here as it is
sometimes added client-side by the validation library.

Args:
  entrypoint: string, entrypoint value.

Returns:
  Dict containing entrypoint.
N zexec shell)
startswithlen)
entrypoints    r[   ConvertEntrypointr     s;     J7##CLM*J
:	r]   c                    U (       d  / $ U R                  S5       Vs/ s H)  oR                  5       (       d  M  UR                  5       PM+     sn$ s  snf )a@  Converts a comma-separated string to a list of strings.

Args:
  input_str: A string containing one or more tags, separated by commas, or
    None. Handles empty strings and None by returning an empty list.

Returns:
  A list of strings. The returned strings are stripped and empty strings are
  filtered from the list.
r_   )splitstrip)	input_strvs     r[   CommaSeparatedStringToListr     s=     
I&__S1	?1WWY)!'')1	??	?s
   AA)F)r   z
str | Nonereturnz	list[str])+__doc__
__future__r   r   r   googlecloudsdk.appengine.apir   ImportErrorgoogle.appengine.apir   r   r   _NANOSECONDS_PER_SECONDr   _SCRIPT_FIELDSr   r   r   r   r   r   r   _SUBNETWORK_KEY_FIELDSr`   rV   r\   rb   rk   ro   rt   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r]   r[   <module>r      sd   K & " 	07+2
   $  
 !' #	$  	' #& "
 # 4   5 
 !.  H1C7/+'/-3%+2/( &0(->0,"$
,($(VIX>>0@0*@A  0/0  +*+s"   B B# B B #B21B2