
    K                        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\5      r\
R.                  " \
R0                  R2                  5       " S S\
R4                  5      5       r\
R.                  " \
R0                  R8                  5       " S S\5      5       r\
R.                  " \
R0                  R<                  5       " S S\5      5       rg)zaCommand for removing exclusions for preconfigured WAF rule evaluation from security policy rules.    )absolute_import)division)unicode_literals)base_classes)client)base)
exceptions)scope)flags)
propertiesc                       \ rS rSrSr\S 5       r\ SS j5       r\S 5       r\S 5       r	\    SS j5       r
\S	 5       r\S
 5       rSrg)!RemovePreconfigWafExclusionHelper     Remove an exclusion configuration for preconfigured WAF evaluation from a security policy rule.

*{command}* is used to remove an exclusion configuration for preconfigured WAF
evaluation from a security policy rule.

Note that request field exclusions are associated with a target, which can be
a single rule set, or a rule set plus a list of rule IDs under the rule set.

It is possible to remove request field exclusions at 3 levels:
- Remove specific request field exclusions that are associated with a matching
  target.
- Remove all the request field exclusions that are associated with a matching
  target.
- Remove all the request field exclusions that are configured under the
  security policy rule, regardless of the target.

## EXAMPLES

To remove specific request field exclusions that are associated with the
target of 'sqli-stable': ['owasp-crs-v030001-id942110-sqli',
'owasp-crs-v030001-id942120-sqli'], run:

  $ {command} 1000 \
     --security-policy=my-policy \
     --target-rule-set=sqli-stable \
     --target-rule-ids=owasp-crs-v030001-id942110-sqli,owasp-crs-v030001-id942120-sqli
     \
     --request-header-to-exclude=op=EQUALS,val=abc \
     --request-header-to-exclude=op=STARTS_WITH,val=xyz \
     --request-uri-to-exclude=op=EQUALS_ANY

To remove all the request field exclusions that are associated with the target
of 'sqli-stable': ['owasp-crs-v030001-id942110-sqli',
'owasp-crs-v030001-id942120-sqli'], run:

  $ {command} 1000 \
     --security-policy=my-policy \
     --target-rule-set=sqli-stable \
     --target-rule-ids=owasp-crs-v030001-id942110-sqli,owasp-crs-v030001-id942120-sqli

To remove all the request field exclusions that are associated with the target
of 'sqli-stable': [], run:

  $ {command} 1000 \
     --security-policy=my-policy \
     --target-rule-set=sqli-stable

To remove all the request field exclusions that are configured under the
security policy rule, regardless of the target, run:

  $ {command} 1000 \
     --security-policy=my-policy \
     --target-rule-set=*
c                    [         R                  " S5      U l        U R                  R                  USSS9  [         R                  " US5        [
        R                  " 5       U l        U R                  R                  U5        [         R                  " USS9  [         R                  " USS9  [         R                  " USS9  [         R                  " USS9  [         R                  " USS9  [         R                  " USS9  g)z@Generates the flagset for a RemovePreconfigWafExclusion command.zCremove the exclusion configuration for preconfigured WAF evaluationPRIORITY)operation_typecust_metavarF)parseris_addN)r   PriorityArgumentNAME_ARGAddArgumentAddRegionFlagsecurity_policy_flags(SecurityPolicyMultiScopeArgumentForRulesSECURITY_POLICY_ARGAddTargetRuleSetAddTargetRuleIdsAddRequestHeaderAddRequestCookieAddRequestQueryParamAddRequestUriclsr   s     Mlib/surface/compute/security_policies/rules/remove_preconfig_waf_exclusion.pyArgs&RemovePreconfigWafExclusionHelper.ArgsW   s     ))MCL LL     
MO 	FFH ''/	&7	&7	&7	&7	fU;	ve4    Nc                 n    X!R                   :H  =(       a!    [        U5      [        UR                  5      :H  $ N)targetRuleSetsettargetRuleIds)r%   existing_exclusiontarget_rule_settarget_rule_idss       r&   _IsIdenticalTarget4RemovePreconfigWafExclusionHelper._IsIdenticalTargetr   s=    
 >>> B3D 2 @ @ADB Br)   c                    UR                   R                  5       nUR                  S5      =(       d    SnU(       a*  UR                   R                  R                  U5      Ul        UR                  S5      =(       d    SnU(       a  XSl        U$ )zConverts RequestFieldToAdd.op val)messages<SecurityPolicyRulePreconfiguredWafConfigExclusionFieldParamsgetOpValueValuesEnumr5   r7   )r%   compute_clientrequest_field_to_removerequest_fieldr5   r7   s         r&   _ConvertRequestFieldToAdd;RemovePreconfigWafExclusionHelper._ConvertRequestFieldToAddz   s}     		E	E	G  
!	$	$T	*	0bB	

!
!GGR  
 "
%
%e
,
2C
r)   c                 L    / nU H  nXB;  d  M
  UR                  U5        M     U$ r+   )append)r%   existing_request_fieldsrequest_fields_to_removenew_request_fieldsexisting_request_fields        r&   _RemoveRequestFields6RemovePreconfigWafExclusionHelper._RemoveRequestFields   s2     "9		?!!"89 #: r)   c                    UR                   R                  5       nUR                  Ul        UR                  =(       d    /  H  nUR                  R	                  U5        M      / n	U=(       d    /  H#  n
U	R	                  U R                  X5      5        M%     UR                  R                  U R                  UR                  U	5      5        / nU=(       d    /  H#  nUR	                  U R                  X5      5        M%     UR                  R                  U R                  UR                  U5      5        / nU=(       d    /  H#  nUR	                  U R                  X5      5        M%     UR                  R                  U R                  UR                  U5      5        / nU=(       d    /  H$  nUR	                  U R                  UU5      5        M&     UR                  R                  U R                  UR                  U5      5        UR                  (       d4  UR                  (       d#  UR                  (       d  UR                  (       d  gU$ )zUpdates Exclusion.N)r8   1SecurityPolicyRulePreconfiguredWafConfigExclusionr,   r.   rB   r?   requestHeadersToExcludeextendrG   requestCookiesToExcluderequestQueryParamsToExcluderequestUrisToExclude)r%   r<   r/   request_headersrequest_cookiesrequest_query_paramsrequest_urisnew_exclusiontarget_rule_idrequest_headers_to_removerequest_headerrequest_cookies_to_removerequest_cookierequest_query_params_to_removerequest_query_paramrequest_uris_to_removerequest_uris                    r&   _UpdateExclusion2RemovePreconfigWafExclusionHelper._UpdateExclusion   s&    		:	:	<  #5"B"BM,::@b@!!((8 A !#)/R/&&

'
'
GI 0 ))00  !3!K!K!:	<= !#)/R/&&

'
'
GI 0 ))00  !3!K!K!:	<= &("39r9$++

'
'
LN  : --44  ::*	,-
  #)r)##

'
'
DF * &&--  !3!H!H!7	9: 111155..r)   c           	         UR                   R                  5       nUR                  S:X  a  U$ SnUR                  S5      (       dB  UR                  S5      (       d,  UR                  S5      (       d  UR                  S5      (       a  SnUR                  (       a  UR                  R
                  nO/ nU H  nU R                  XsR                  UR                  =(       d    / 5      (       al  U(       ac  U R                  XUR                  UR                  UR                  UR                  5      nU(       a  UR
                  R                  U5        M  M  M  UR
                  R                  U5        M     U$ )zUpdates Preconfig WafConfig.*Frequest_header_to_excluderequest_cookie_to_excluderequest_query_param_to_excluderequest_uri_to_excludeT)r8   (SecurityPolicyRulePreconfiguredWafConfigr0   IsSpecifiedpreconfiguredWafConfig
exclusionsr2   r1   r^   rb   rc   rd   re   rB   )	r%   r<   existing_ruleargsnew_preconfig_waf_confighas_request_field_argsri   	exclusionrT   s	            r&   _UpdatePreconfigWafConfig;RemovePreconfigWafExclusionHelper._UpdatePreconfigWafConfig   sO    	HHJ s"%%"4554559::122#++ 77BBjj					+?+? $ 4 4 :
< 
<!..)G)G,,1143N3NP- $//66}E  " 	!++229=   $#r)   c                 h   UR                   S:X  a  UR                  S5      (       dX  UR                  S5      (       dB  UR                  S5      (       d,  UR                  S5      (       d  UR                  S5      (       a  [        R                  " SS5      eUR                  =(       d    / UR
                  =(       d    / UR                  =(       d    / UR                  =(       d    / 4 HJ  nU HA  nUR                  S	5      =(       d    S
nU(       a  US;  d  M,  [        R                  " S	S5      e   ML     [        R                  " U5      nUR                  nSnU R                  R                  X&R                  [        R                   R"                  S9n	[%        U	SS5      bj  UR                  R'                  UR(                  S[*        R,                  R.                  R0                  R2                  U	R4                  UR6                  S.S9nO^UR                  R'                  UR(                  S[*        R,                  R.                  R0                  R2                  UR6                  S.S9n[        R8                  " XS9n
U
R;                  5       S   nU R=                  X{U5      nU
R?                  US9$ )z7Validates arguments and patches a security policy rule.ra   r1   rb   rc   rd   re   ztarget-rule-setzArguments in [--target-rule-ids, --request-header-to-exclude, --request-cookie-to-exclude, --request-query-param-to-exclude, --request-uri-to-exclude] cannot be specified when --target-rule-set is set to *.r5   r6   )EQUALSSTARTS_WITH	ENDS_WITHCONTAINS
EQUALS_ANYz_A request field operator must be one of [EQUALS, STARTS_WITH, ENDS_WITH, CONTAINS, EQUALS_ANY].N)default_scoperegionz!compute.regionSecurityPolicyRules)projectrx   securityPolicy)
collectionparamszcompute.securityPolicyRules)ry   rz   )r<   r   )preconfig_waf_config) r0   rg   r	   InvalidArgumentExceptionrb   rc   rd   re   r:   r   ComputeApiHolderr   r   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALgetattrParsenamer   VALUEScorery   	GetOrFailrx   security_policySecurityPolicyRuleDescribero   Patch)r%   release_trackrk   request_fieldsr>   r5   holderr<   refsecurity_policy_refsecurity_policy_rulerj   rl   s                r&   Run%RemovePreconfigWafExclusionHelper.Run   s    s"


,
-
-


6
7
7


6
7
7


;
<
<


3
4
411-. 	. 	&&,"d.L.L /
D//52##)r
 *-t$*R  
 
 3323 3 * **=9F]]N
C11CCm.E.E.L.L D N"Hd3?""
))8#**//77AA+22 $ 4 4 # c ""
))2#**//77AA $ 4 4 # c "44,(113A6M"<<t -%%5 & 7 7r)    r+   )NNNN)__name__
__module____qualname____firstlineno____doc__classmethodr'   r2   r?   rG   r^   ro   r   __static_attributes__r   r)   r&   r   r      s    5n 5 54  *.B B  &    (,'+,0$(5 5n  $  $D ;7 ;7r)   r   c                   6    \ rS rSrSrSrSr\S 5       rS r	Sr
g)RemovePreconfigWafExclusionGAi1  r   Nc                 .    [         R                  U5        g r+   )r   r'   r$   s     r&   r'   "RemovePreconfigWafExclusionGA.Argsm  s    %**r)   c                 J    [         R                  U R                  5       U5      $ r+   )r   r   ReleaseTrack)selfrk   s     r&   r   !RemovePreconfigWafExclusionGA.Runs  s$    ,00 r)   r   )r   r   r   r   r   r   r   r   r'   r   r   r   r)   r&   r   r   1  s,    5n ( 
r)   r   c                       \ rS rSrSrSrg)RemovePreconfigWafExclusionBetaiz  r   r   Nr   r   r   r   r   r   r   r)   r&   r   r   z      5r)   r   c                       \ rS rSrSrSrg) RemovePreconfigWafExclusionAlphai  r   r   Nr   r   r)   r&   r   r     r   r)   r   N) r   
__future__r   r   r   googlecloudsdk.api_lib.computer   0googlecloudsdk.api_lib.compute.security_policiesr   googlecloudsdk.callioper   r	   "googlecloudsdk.command_lib.computer
   r   4googlecloudsdk.command_lib.compute.security_policiesr   r   :googlecloudsdk.command_lib.compute.security_policies.rulesgooglecloudsdk.corer   objectr   ReleaseTracksr   GAUpdateCommandr   BETAr   ALPHAr   r   r)   r&   <module>r      s    h &  ' 7 C ( . E _ L *O7 O7d D%%(()ED$6$6 E *EP D%%**+6&C 6 ,6r D%%++,6'F 6 -6r)   