
    {d                     X   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	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\	R8                  5      rS,S jrS,S jrS r S-S jr!S-S jr"  S.S jr#S r$S,S  jr%S! r& S,S" jr'S# r(S$ r)S% r*S& r+S' r,S( r-S) r.S* r/g+)/zCFlags and helpers for the compute security policies rules commands.    )absolute_import)division)unicode_literals)arg_parsers)
completers)flags)security_policies_utilsa  
You can specify an exact match or a partial match by using a field operator and
a field value. Available field operators are:
- ``EQUALS'': the operator matches if the field value equals the specified
              value.
- ``STARTS_WITH'': the operator matches if the field value starts with the
                   specified value.
- ``ENDS_WITH'': the operator matches if the field value ends with the specified
                 value.
- ``CONTAINS'': the operator matches if the field value contains the specified
                value.
- ``EQUALS_ANY'': the operator matches if the field value is any value.

A field value must be given if the field operator is not ``EQUALS_ANY'', and
cannot be given if the field operator is ``EQUALS_ANY''. For example,
`--request-header-to-exclude op=EQUALS,val=abc` or
`--request-header-to-exclude op=EQUALS_ANY`.

This flag can be repeated to specify multiple request headers to exclude. For
example,
`--request-header-to-exclude op=EQUALS,val=abc --request-header-to-exclude op=STARTS_WITH,val=xyz`.
z
Target WAF rule set where the request field exclusions being added would apply.

This, together with the target rule IDs (if given), determines the target for
associating request field exclusions. See `--target-rule-ids`.
a  
Target WAF rule set from where to remove the request field exclusions.

This, together with the target rule IDs (if given), determines the target for
associating request field exclusions. See `--target-rule-ids`.

Note that the removal of request field exclusions is restricted to those
associated with a matching target. Set this flag to * if you want to remove
request field exclusions regardless of the target.
a  
A comma-separated list of target rule IDs under the WAF rule set where the
request field exclusions being added would apply. If omitted, the added request
field exclusions will be associated with the rule set only, which would apply
to all the rule IDs under the rule set.
z
A comma-separated list of target rule IDs under the WAF rule set from where to
remove the request field exclusions. If omitted, the removal of request field
exclusions is restricted to those associated with the rule set only, without
specific rule IDs.
z
Adds a request cookie to the request field exclusions associated with the rule
set and rule IDs (if given). This specifies a request cookie whose value will
be excluded from inspection during preconfigured WAF evaluation.
z{
Removes a request cookie from the existing request field exclusions associated
with the rule set and rule IDs (if given).
aY  
Adds a request header to the request field exclusions associated with the rule
set and rule IDs (if given). This specifies a request header whose value will be
excluded from inspection during preconfigured WAF evaluation.

Refer to the syntax under `--request-cookie-to-exclude`.

This flag can be repeated to specify multiple request headers.
z
Removes a request header from the existing request field exclusions associated
with the rule set and rule IDs (if given).

Refer to the syntax under `--request-cookie-to-exclude`.

This flag can be repeated to specify multiple request headers.
a  
Adds a request query parameter to the request field exclusions associated with
the rule set and rule IDs (if given). This specifies a request query parameter
in the query string or in the POST body whose value will be excluded from
inspection during preconfigured WAF evaluation.

Refer to the syntax under `--request-cookie-to-exclude`.

This flag can be repeated to specify multiple request query parameters.
a  
Removes a request query parameter from the existing request field exclusions
associated with the rule set and rule IDs (if given).

Refer to the syntax under `--request-cookie-to-exclude`.

This flag can be repeated to specify multiple request query parameters.
aX  
Adds a request URI to the request field exclusions associated with the rule set
and rule IDs (if given). This specifies a request URI from the request line to
be excluded from inspection during preconfigured WAF evaluation.

Refer to the syntax under `--request-cookie-to-exclude`.

This flag can be repeated to specify multiple request URIs.
z
Removes a request URI from the existing request field exclusions associated with
the rule set and rule IDs (if given).

Refer to the syntax under `--request-cookie-to-exclude`.

This flag can be repeated to specify multiple request URIs.
a  
      - ``ip'': each client IP address has this limit enforced separately
      - ``all'': a single limit is applied to all requests matching this rule
      - ``http-header'': key type takes the value of the HTTP header configured
                         in enforce-on-key-name as the key value
      - ``xff-ip'': takes the original IP address specified in the X-Forwarded-For
                    header as the key
      - ``http-cookie'': key type takes the value of the HTTP cookie configured
                         in enforce-on-key-name as the key value
      - ``http-path'': key type takes the value of the URL path in the request
      - ``sni'': key type takes the value of the server name indication from the
                  TLS session of the HTTPS request
      - ``region-code'': key type takes the value of the region code from which
                         the request originates
      - ``tls-ja3-fingerprint'': key type takes the value of JA3 TLS/SSL
                                 fingerprint if the client connects using HTTPS,
                                 HTTP/2 or HTTP/3
      - ``user-ip'': key type takes the IP address of the originating client,
                     which is resolved based on user-ip-request-headers
                     configured with the security policy
      - ``tls-ja4-fingerprint'': key type takes the value of JA4 TLS/SSL
                                 fingerprint if the client connects using HTTPS,
                                 HTTP/2 or HTTP/3
c                   (   ^  \ rS rSrU 4S jrSrU =r$ )SecurityPolicyRulesCompleter   c                 2   > [         [        U ]
  " SSS0UD6  g )N
collectioncompute.securityPolicyRules )superr   __init__)selfkwargs	__class__s     Glib/googlecloudsdk/command_lib/compute/security_policies/rules/flags.pyr   %SecurityPolicyRulesCompleter.__init__   s#    	
&6 <0<4:<    r   )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r   r      s    < <r   r   c           
          U R                  SU(       a  SOS-   SU(       a  SOS[        SR                  U(       a  SOSU5      S9  g)	z+Adds the priority argument to the argparse.names PRIORITY*NThe priority of the rule{0} to {1}. Rules are evaluated in order from highest priority to lowest priority where 0 is the highest priority and 2147483647 is the lowest priority.)metavarnargs	completerhelp)add_argumentr   format)parser	operation	is_plurals      r   AddPriorityr/      sF    yb)C$,>>Df b)?5  7r   c                     [         R                  " SU(       a  SOS-   [        SSS[         R                  R                  UU(       a  SOSSR                  U(       a  SOSU 5      S	9	$ )
Nr    r!   r"   r   z!compute.regionSecurityPolicyRulesFTr%   )r(   global_collectionregional_collectionregion_hiddenscope_flags_usagepluralrequireddetailed_help)compute_flagsResourceArgumentr   ScopeFlagsUsageDONT_USE_SCOPE_FLAGSr+   )r-   r.   s     r   PriorityArgumentr<      s^    		'	'yb),5=%55JJ"<<BFcB	=3
5 5r   c                 L    [         R                  " U SU[         R                  S9$ )zOAdds the region argument to the argparse to specify the security policy region.zsecurity policy)explanation)r8   AddRegionFlag&REGION_PROPERTY_EXPLANATION_NO_DEFAULT)r,   r-   s     r   r?   r?      s)    		$	$FF	
H Hr   c                     U R                  SUSS9nUR                  S[        R                  " 5       SSS9  UR                  SS	S
9  g)+Adds the matcher arguments to the argparse.TSecurity policy rule matcher.)mutexr6   r)   --src-ip-rangesSRC_IP_RANGELThe source IPs/IP ranges to match for this rule. To match all IPs specify *.typer&   r)   --expressionAThe Cloud Armor rules language expression to match for this rule.r)   N	add_groupr*   r   ArgListr,   r6   matchers      r   
AddMatcherrR      sf    8*I  K'	 *	  , 
N  Pr   c                    U R                  USS9nUR                  S[        R                  " 5       SSS9  UR                  SSS	9  UR                  S
[        R                  " 5       SSS9  UR                  S[        R                  " 5       SSS9  UR                  S[        R                  " 5       SSS9  UR                  S[        R                  " 5       SSS9  UR                  S[        R                  " 5       SSS9  UR                  S[        R                  " 5       SSS9  UR                  S[        R                  " 5       SSS9  UR                  S[        R                  " 5       SSS9  g )!rB   rC   r6   r)   rE   rF   rG   rH   rJ   rK   rL   z--network-user-defined-fieldszNAME;VALUE:VALUE:...zPEach element names a defined field and lists the matching values for that field.z--network-src-ip-rangesz--network-dest-ip-rangesDEST_IP_RANGEzQThe destination IPs/IP ranges to match for this rule. To match all IPs specify *.z--network-ip-protocolsIP_PROTOCOLa   The IP protocols to match for this rule. Each element can be an 8-bit unsigned decimal number (e.g. "6"), range (e.g."253-254"), or one of the following protocol names: "tcp", "udp", "icmp", "esp", "ah", "ipip", or "sctp". To match all protocols specify *.z--network-src-portsSRC_PORTzThe source ports to match for this rule. Each element can be an 16-bit unsigned decimal number (e.g. "80") or range (e.g."0-1023"), To match all source ports specify *.z--network-dest-ports	DEST_PORTzThe destination ports to match for this rule. Each element can be an 16-bit unsigned decimal number (e.g. "80") or range (e.g."0-1023"), To match all destination ports specify *.z--network-src-region-codesSRC_REGION_CODEzThe two letter ISO 3166-1 alpha-2 country code associated with the source IP address to match for this rule. To match all region codes specify *.z--network-src-asnsSRC_ASNzZBGP Autonomous System Number associated with the source IP address to match for this rule.NrM   rP   s      r   AddMatcherAndNetworkMatcherr[      s   =  ?'	 *	  , 
N  P 
% $	    
 *	  , 
  *	  , 
 	   
 C	  E 
 H	  J 
" 	  ! 
 .	  0r   c           
      x    SSSSSSSSS	S
.	nU(       a  UR                  SS05        U R                  SUS USS9  g)z)Adds the action argument to the argparse.z/Allows the request from HTTP(S) Load Balancing.zADenies the request from TCP/SSL Proxy and Network Load Balancing.zYDenies the request from HTTP(S) Load Balancing, with an HTTP response status code of 403.zYDenies the request from HTTP(S) Load Balancing, with an HTTP response status code of 404.zYDenies the request from HTTP(S) Load Balancing, with an HTTP response status code of 502.z(DEPRECATED) Redirects the request from HTTP(S) Load Balancing, for reCAPTCHA Enterprise assessment. This flag choice is deprecated. Use --action=redirect and --redirect-type=google-recaptcha instead.zMRedirects the request from HTTP(S) Load Balancing, based on redirect options.zXEnforces rate-based ban action from HTTP(S) Load Balancing, based on rate limit options.zREnforces throttle action from HTTP(S) Load Balancing, based on rate limit options.)	allowdenydeny-403deny-404deny-502zredirect-to-recaptcharedirectzrate-based-banthrottle	fairsharezWhen traffic reaches the threshold limit, requests from the clients matching this rule begin to be rate-limited using the Fair Share algorithm.z--actionc                 "    U R                  5       $ Nlowerxs    r   <lambda>AddAction.<locals>.<lambda>c  
    QWWYr   z>The action to take if the request matches the match condition.)choicesrI   r6   r)   N)updater*   )r,   r6   support_fairshareactionss       r   	AddActionrr   2  sz    
 A
M)))P
) ?"'F NN$  	K  Mr   c                 $    U R                  SSS9  g)*Adds the preview argument to the argparse.z--descriptionz.An optional, textual description for the rule.rL   Nr*   r,   s    r   AddDescriptionrw   h  s    L  Nr   c                 l    U(       a  S[         R                  0nOSSS.nU R                  "  SSS0UD6  g)rt   action
store_trueN)ry   defaultr)   z.If specified, the action will not be enforced.)z	--preview)r   StoreTrueFalseActionr*   )r,   
for_updater   s      r   
AddPreviewr~   n  sB    889F$6F; 	r   c                 R    SS/nU R                  SUS SS9  U R                  SSS	9  g
)z6Adds redirect action related argument to the argparse.google-recaptchaexternal-302z--redirect-typec                 "    U R                  5       $ rf   rg   ri   s    r   rk   $AddRedirectOptions.<locals>.<lambda>  rm   r   z}      Type for the redirect action. Default to ``external-302'' if unspecified
      while --redirect-target is given.
      rn   rI   r)   z--redirect-targetz      URL target for the redirect action. Must be specified if the redirect
      type is ``external-302''. Cannot be specified if the redirect type is
      ``google-recaptcha''.
      rL   Nru   )r,   redirect_types     r   AddRedirectOptionsr   z  sJ    %~6-
	   	
  r   c           	         U R                  S[        SS9  U R                  S[        SS9  S/nU R                  SUS S	S
9  / SQnU R                  SUS SS
9  SS/nU R                  SUS SS
9  U R                  SSS9  / SQnU R                  SUS S[        -   S
9  U R                  SSS9  U R                  S[        R                  " [
        R                  SSS 9S!S"[        -   S#-   S$9  U R                  S%[        S&S9  U R                  S'[        S(S9  U R                  S)[        S*S9  U(       a&  U R                  S+[        S,S9  U R                  S-S.S9  g/g/)0z5Adds rate limiting related arguments to the argparse.z--rate-limit-threshold-countzTNumber of HTTP(S) requests for calculating the threshold for rate limiting requests.)rI   r)   z#--rate-limit-threshold-interval-seczIInterval over which the threshold for rate limiting requests is computed.r]   z--conform-actionc                 "    U R                  5       $ rf   rg   ri   s    r   rk   %AddRateLimitOptions.<locals>.<lambda>  rm   r   zAction to take when requests are under the given threshold. When requests are throttled, this is also the action for all requests which are not dropped.r   )r_   r`   zdeny-429ra   r^   rb   z--exceed-actionc                 "    U R                  5       $ rf   rg   ri   s    r   rk   r     rm   r   a        Action to take when requests are above the given threshold. When a request
      is denied, return the specified HTTP response code. When a request is
      redirected, use the redirect options based on --exceed-redirect-type and
      --exceed-redirect-target below.
      r   r   z--exceed-redirect-typec                 "    U R                  5       $ rf   rg   ri   s    r   rk   r     rm   r   zR      Type for the redirect action that is configured as the exceed action.
      z--exceed-redirect-targetz      URL target for the redirect action that is configured as the exceed
      action when the redirect type is ``external-302''.
      rL   )ipallzhttp-headerzxff-ipzhttp-cookiez	http-pathsnizregion-codeztls-ja3-fingerprintzuser-ipztls-ja4-fingerprintz--enforce-on-keyc                 "    U R                  5       $ rf   rg   ri   s    r   rk   r     rm   r   zQ      Different key types available to enforce the rate limit threshold limit on:z--enforce-on-key-namea6        Determines the key name for the rate limit key. Applicable only for the
      following rate limit key types:
      - http-header: The name of the HTTP header whose value is taken as the key
      value.
      - http-cookie: The name of the HTTP cookie whose value is taken as the key
      value.
      z--enforce-on-key-configs      )element_type
min_length
max_lengthz[[all],[ip],[xff-ip],[http-cookie=HTTP_COOKIE],[http-header=HTTP_HEADER],[http-path],[sni],[region-code],[tls-ja3-fingerprint],[user-ip],[tls-ja4-fingerprint]]zZ      Specify up to 3 key type/name pairs to rate limit.
      Valid key types are:
      z
    Key names are only applicable to the following key types:
    - http-header: The name of the HTTP header whose value is taken as the key value.
    - http-cookie: The name of the HTTP cookie whose value is taken as the key value.
    rH   z--ban-threshold-counta        Number of HTTP(S) requests for calculating the threshold for
      banning requests. Can only be specified if the action for the
      rule is ``rate-based-ban''. If specified, the key will be banned
      for the configured ``BAN_DURATION_SEC'' when the number of requests
      that exceed the ``RATE_LIMIT_THRESHOLD_COUNT'' also exceed this
      ``BAN_THRESHOLD_COUNT''.
      z--ban-threshold-interval-secax        Interval over which the threshold for banning requests is
      computed. Can only be specified if the action for the rule is
      ``rate-based-ban''. If specified, the key will be banned for the
      configured ``BAN_DURATION_SEC'' when the number of requests that
      exceed the ``RATE_LIMIT_THRESHOLD_COUNT'' also exceed this
      ``BAN_THRESHOLD_COUNT''.
      z--ban-duration-secz      Can only be specified if the action for the rule is
      ``rate-based-ban''. If specified, determines the time (in seconds)
      the traffic will continue to be banned by the rate limit after
      the rate falls below the threshold.
      z--exceed-action-rpc-status-codez?Status code, which should be an enum value of [google.rpc.Code]z"--exceed-action-rpc-status-messagez5Developer-facing error message, should be in English.N)r*   int,_RATE_LIMIT_ENFORCE_ON_KEY_TYPES_DESCRIPTIONr   rO   r	   ParseEnforceOnKeyConfig)r,   support_rpc_statusconform_actionsexceed_actionsexceed_redirect_typesenforce_on_keys         r   AddRateLimitOptionsr     s(   
 	$!  # 	+   I/%	  '. 	
	  	 .~>#
	   	 
  . 	U45	   	
  	 	 .FF p
 	5	5
		  4 	
  
 	$
  
 	
   
)M	  P ,E  H r   c                 N    U R                  SS[        R                  " 5       SS9  g)z5Adds request-headers-to-add argument to the argparse.z--request-headers-to-addREQUEST_HEADERS_TO_ADDzt      A comma-separated list of header names and header values to add to
      requests that match this rule.
      )r&   rI   r)   N)r*   r   ArgDictrv   s    r   AddRequestHeadersToAddr   5  s,     & 
	  r   c                 H    U R                  SSU(       a  [        O[        S9  g)z.Adds target-rule-set argument to the argparse.z--target-rule-setTrT   N)r*   0_WAF_EXCLUSION_TARGET_RULE_SET_HELP_TEXT_FOR_ADD3_WAF_EXCLUSION_TARGET_RULE_SET_HELP_TEXT_FOR_REMOVEr,   is_adds     r   AddTargetRuleSetr   A  s'    	 <H	  Jr   c                 p    U R                  S[        R                  " 5       SU(       a  [        O[        S9  g)z.Adds target-rule-ids argument to the argparse.z--target-rule-idsRULE_IDrH   N)r*   r   rO   0_WAF_EXCLUSION_TARGET_RULE_IDS_HELP_TEXT_FOR_ADD3_WAF_EXCLUSION_TARGET_RULE_IDS_HELP_TEXT_FOR_REMOVEr   s     r   AddTargetRuleIdsr   J  s3     	 <H  Jr   c                     U R                  S[        R                  " [        [        S.S/S9SU(       a  [        O[
        S9  g)z8Adds request-cookie-to-exclude argument to the argparse.z--request-cookie-to-excludeopvalr   specrequired_keysappendrI   ry   r)   N)r*   r   r   str/_WAF_EXCLUSION_REQUEST_COOKIE_HELP_TEXT_FOR_ADD2_WAF_EXCLUSION_REQUEST_COOKIE_HELP_TEXT_FOR_REMOVEr   s     r   AddRequestCookier   T  I    # !6	#
 	 ;G  	Ir   c                     U R                  S[        R                  " [        [        S.S/S9SU(       a  [        O[
        S9  g)z8Adds request-header-to-exclude argument to the argparse.z--request-header-to-excluder   r   r   r   r   N)r*   r   r   r   /_WAF_EXCLUSION_REQUEST_HEADER_HELP_TEXT_FOR_ADD2_WAF_EXCLUSION_REQUEST_HEADER_HELP_TEXT_FOR_REMOVEr   s     r   AddRequestHeaderr   b  r   r   c                     U R                  S[        R                  " [        [        S.S/S9SU(       a  [        O[
        S9  g)z=Adds request-query-param-to-exclude argument to the argparse.z --request-query-param-to-excluder   r   r   r   r   N)r*   r   r   r   4_WAF_EXCLUSION_REQUEST_QUERY_PARAM_HELP_TEXT_FOR_ADD7_WAF_EXCLUSION_REQUEST_QUERY_PARAM_HELP_TEXT_FOR_REMOVEr   s     r   AddRequestQueryParamr   p  sJ    ( !6	#
 	 @L  	Nr   c                     U R                  S[        R                  " [        [        S.S/S9SU(       a  [        O[
        S9  g)z5Adds request-uri-to-exclude argument to the argparse.z--request-uri-to-excluder   r   r   r   r   N)r*   r   r   r   ,_WAF_EXCLUSION_REQUEST_URI_HELP_TEXT_FOR_ADD/_WAF_EXCLUSION_REQUEST_URI_HELP_TEXT_FOR_REMOVEr   s     r   AddRequestUrir   ~  sI      !6	#
 	 8D  	Fr   c                     U R                  S[        R                  " 5       SSS9  U R                  S[        R                  " 5       SSS9  g)zBAdds reCAPTCHA token evaluation related arguments to the argparse.z--recaptcha-action-site-keysSITE_KEYz      A comma-separated list of site keys to be used during the validation of
      reCAPTCHA action-tokens. The provided site keys need to be created from
      the reCAPTCHA API under the same project where the security policy is created.
      rH   z--recaptcha-session-site-keysz      A comma-separated list of site keys to be used during the validation of
      reCAPTCHA session-tokens. The provided site keys need to be created from
      the reCAPTCHA API under the same project where the security policy is created.
      N)r*   r   rO   rv   s    r   AddRecaptchaOptionsr     sX    $ 
	  	 	% 
	  	r   N)F)T)TF)0__doc__
__future__r   r   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   compute_completersr   r8   4googlecloudsdk.command_lib.compute.security_policiesr	   &_WAF_EXCLUSION_REQUEST_FIELD_HELP_TEXTr   r   r   r   r   r   r   r   r   r   r   r   r   ListCommandCompleterr   r/   r<   r?   rR   r[   rr   rw   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s.   J &  ' / O E X* &.4 0	7 34 07 33 -	3- /6 -6- 2
3 /6 2	8 4; 70 ,3 /0 ,4<#5#J#J <
75"HPB0L  %3MlN	. cHL	JJIINFr   