
    [G                     &   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  e
j$                  e
j&                  j(                        e
j*                   G d de
j,                                      Z e
j$                  e
j&                  j0                        e
j*                   G d de                    Z e
j$                  e
j&                  j4                        e
j*                   G d de                    Zy)z'Command for updating security policies.    )absolute_import)division)unicode_literals)base_classes)client)base)
exceptions)scope)flags)security_policies_utilsc                   0    e Zd ZdZdZed        Zd Zd Zy)UpdateGaUpdate a Compute Engine security policy.

  *{command}* is used to update security policies.

  ## EXAMPLES

  To update the description run this:

    $ {command} SECURITY_POLICY --description='new description'
  Nc                 >   t        j                         | _        | j                  j                  |d       |j	                  dd       t        j
                  |       t        j                  |       t        j                  |       t        j                  |       y )Nupdateoperation_type--description9An optional, textual description for the security policy.help)	r    SecurityPolicyMultiScopeArgumentSECURITY_POLICY_ARGAddArgumentadd_argumentAddCloudArmorAdaptiveProtectionAddAdvancedOptionsAddRecaptchaOptions*AddDdosProtectionConfigWithAdvancedPreviewclsparsers     /lib/surface/compute/security_policies/update.pyArgszUpdateGa.Args.   s    #DDFC''x'H
I  L 
))&1	V$	f%	44V<    c                 z   |j                  d      s|j                  d      s|j                  d      s|j                  d      st|j                  d      sb|j                  d      sP|j                  d      s>|j                  d      s,|j                  d	      sg d
}t        j                  |d      yyyyyyyyy)Validates that at least one field to update is specified.

    Args:
      args: The arguments given to the update command.
    descriptionenable_layer7_ddos_defense#layer7_ddos_defense_rule_visibilityjson_parsingjson_custom_content_types	log_levelrecaptcha_redirect_site_keynetwork_ddos_protectionuser_ip_request_headers)	r   --enable-layer7-ddos-defense%--layer7-ddos-defense-rule-visibility--json-parsing--json-custom-content-types--log-level--recaptcha-redirect-site-key--network-ddos-protection--user-ip-request-headers.Please specify at least one property to updateNIsSpecifiedr	   MinimumArgumentExceptionselfargsparameter_namess      r#   _ValidateArgszUpdateGa._ValidateArgs;   s     ]+9:BC^,89[):;6767o //
KM M 8 8 < * : - D ; ,r%   c                    | j                  |       t        j                  | j                               }| j                  j                  ||j                  t        j                  j                        }t        j                  ||j                        }|j                         d   }|j                  }|j                  }|j                  }|j                   }	|j"                  }
|j                  |j                  }|j%                  d      s|j%                  d      r!t'        j(                  |j                  ||      }|j%                  d      s3|j%                  d      s"|j%                  d      s|j%                  d	      r#t'        j*                  |j                  ||d
      }|j%                  d      r!t'        j,                  |j                  ||	      }	|j%                  d      r!t'        j.                  |j                  ||
      }
|j                  j0                  j                  ||||	|
|j2                        }|j5                  |      S )Ndefault_scoperefcompute_clientr   r)   r*   r+   r,   r-   r0   Fenable_large_body_sizer.   r/   r(   adaptiveProtectionConfigadvancedOptionsConfigrecaptchaOptionsConfigddosProtectionConfigfingerprintsecurity_policy)rA   r   ComputeApiHolderReleaseTrackr   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALr   SecurityPolicyDescriber(   rK   rL   rM   rN   r;   r   CreateAdaptiveProtectionConfigCreateAdvancedOptionsConfigCreateRecaptchaOptionsConfigCreateDdosProtectionConfigmessagesrO   Patchr>   r?   holderrF   rQ   existing_security_policyr(   adaptive_protection_configadvanced_options_configrecaptcha_options_configddos_protection_configupdated_security_policys               r#   RunzUpdateGa.RunU   s-   t**4+<+<+>?F

"
"
4
4fm.E.E.L.L 5 NC++/O.779!<*66K 99 6LL7NN5JJ#$$k56>?
!
@
@mmT#=? ! 	(45%23
!
=
=mm%%*	  56
!
>
>mmT#;=  12
!
<
<mmT#9;  %mm44CC!;573,88 D :   1H IIr%   	__name__
__module____qualname____doc__r   classmethodr$   rA   ri    r%   r#   r   r      s-    	 
= 
=M44Jr%   r   c                   0    e Zd ZdZdZed        Zd Zd Zy)
UpdateBetar   Nc                 l   t        j                         | _        | j                  j                  |d       |j	                  dd       t        j
                  |       t        j                  |       t        j                  |d       t        j                  |       t        j                  |       y )Nr   r   r   r   r   TrH   )
r   r   r   r   r   r   )AddCloudArmorAdaptiveProtectionAutoDeployr   r   r   r    s     r#   r$   zUpdateBeta.Args   s    #DDFC''x'H
I  L 
))&1	33F;	VDA	f%	44V<r%   c                 0   |j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d	      st|j                  d
      sb|j                  d      sP|j                  d      s>|j                  d      s,|j                  d      sg d}t        j                  |d      yyyyyyyyyyyyyy)r'   r(   r)   r*   r+   r,   r-   request_body_inspection_sizer0   r.   r/   .layer7_ddos_defense_auto_deploy_load_threshold4layer7_ddos_defense_auto_deploy_confidence_threshold;layer7_ddos_defense_auto_deploy_impacted_baseline_threshold.layer7_ddos_defense_auto_deploy_expiration_sec)r   r1   r2   r3   r4   r5   r8   --request-body-inspection-sizer6   r7   z0--layer7-ddos-defense-auto-deploy-load-thresholdz6--layer7-ddos-defense-auto-deploy-confidence-thresholdz=--layer7-ddos-defense-auto-deploy-impacted-baseline-thresholdz0--layer7-ddos-defense-auto-deploy-expiration-secr9   Nr:   r=   s      r#   rA   zUpdateBeta._ValidateArgs   sH    	'89ABN+78K(:;569:56LMB
 I
 LMo  //
KM M% N

 N 7 ; 7 < ) 9 , C : 	(r%   c                 N   | j                  |       t        j                  | j                               }| j                  j                  ||j                  t        j                  j                        }t        j                  ||j                        }|j                         d   }|j                  }|j                  }|j                  }|j                   }	|j"                  }
|j                  |j                  }|j%                  d      sU|j%                  d      sD|j%                  d      s3|j%                  d      s"|j%                  d      s|j%                  d	      r!t'        j(                  |j                  ||      }|j%                  d
      sD|j%                  d      s3|j%                  d      s"|j%                  d      s|j%                  d      r#t'        j*                  |j                  ||d      }|j%                  d      r!t'        j,                  |j                  ||	      }	|j%                  d      r!t'        j.                  |j                  ||
      }
|j                  j0                  j                  ||||	|
|j2                        }|j5                  |      S )NrC   rE   r   r)   r*   rw   rx   ry   rz   r+   r,   r-   rv   r0   TrH   r.   r/   rJ   rP   )rA   r   rR   rS   r   rT   rU   rV   rW   rX   r   rY   rZ   r(   rK   rL   rM   rN   r;   r   2CreateAdaptiveProtectionConfigWithAutoDeployConfigr\   r]   r^   r_   rO   r`   ra   s               r#   ri   zUpdateBeta.Run   s}   t**4+<+<+>?F

"
"
4
4fm.E.E.L.L 5 NC++/O.779!<*66K 99 6LL7NN5JJ#$$k56>?IJOPIKIJ
!==mmT#=? !
 	(78K(:;56 "
=
=mm%%)	  56
!
>
>mmT#;=  12
!
<
<mmT#9;  %mm44CC!;573,88 D :   1H IIr%   rj   rp   r%   r#   rr   rr      s.    	 = =+MZ=Jr%   rr   c                   0    e Zd ZdZdZed        Zd Zd Zy)UpdateAlphar   Nc                    t        j                         | _        | j                  j                  |d       |j	                  dd       t        j
                  |       t        j                  |       t        j                  |d       t        j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       |j	                  dd	d d
       y )Nr   r   r   r   r   TrH   --enable-ml
store_truez1Whether to enable Cloud Armor Adaptive Protection)actiondefaultr   )r   r   r   r   r   r   rt   r   r   r   AddDdosProtectionConfigOld AddNetworkDdosAdaptiveProtection'AddNetworkDdosImpactedBaselineThresholdr    s     r#   r$   zUpdateAlpha.Args'  s    #DDFC''x'H
I  L 
))&1	33F;	VDA	f%	44V<	$$V,	**62	11&9
A	  Dr%   c                 0   |j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d      s|j                  d	      st|j                  d
      sb|j                  d      sP|j                  d      s>|j                  d      s,|j                  d      sg d}t        j                  |d      yyyyyyyyyyyyyy)r'   r(   	enable_mlr)   r*   r+   r,   r-   rv   r0   r.   r/    network_ddos_adaptive_protection(network_ddos_impacted_baseline_thresholdddos_protection)r   r   r1   r2   r3   r4   r5   r{   r8   r6   r7   z"--network-ddos-adaptive-protectionz*--network-ddos-impacted-baseline-thresholdz--ddos-protectionr9   Nr:   r=   s      r#   rA   zUpdateAlpha._ValidateArgs>  s?    	'K(89ABN+78K(:;569:56>?FG-.o  //
KM M% / H @ 7 ; 7 < ) 9 , C : ) 	(r%   c           	         | j                  |       t        j                  | j                               }| j                  j                  ||j                  t        j                  j                        }t        j                  ||j                        }|j                         d   }|j                  }|j                  }|j                  }|j                   }	|j"                  }
|j$                  }|j                  |j                  }|j&                   t)        j*                  |j                  |      }|j-                  d      sU|j-                  d      sD|j-                  d      s3|j-                  d      s"|j-                  d      s|j-                  d	      r!t)        j.                  |j                  ||      }|j-                  d
      sD|j-                  d      s3|j-                  d      s"|j-                  d      s|j-                  d      r#t)        j0                  |j                  ||	d      }	|j-                  d      r!t)        j2                  |j                  ||
      }
|j-                  d      r!t)        j4                  |j                  ||      }|j-                  d      r!t)        j6                  |j                  ||      }|j-                  d      r!t)        j8                  |j                  ||      }|j-                  d      r!t)        j:                  |j                  ||      }|j                  j<                  j                  ||||	|
||j>                        }|jA                  |      S )NrC   rE   r   r)   r*   rw   rx   ry   rz   r+   r,   r-   rv   r0   TrH   r.   r   r/   r   r   )r(   cloudArmorConfigrK   rL   rM   rN   rO   rP   )!rA   r   rR   rS   r   rT   rU   rV   rW   rX   r   rY   rZ   r(   r   rK   rL   rM   rN   r   r   CreateCloudArmorConfigr;   r}   r\   r]   CreateDdosProtectionConfigOldr^   4CreateDdosProtectionConfigWithDdosAdaptiveProtectionBCreateDdosProtectionConfigWithNetworkDdosImpactedBaselineThresholdr_   rO   r`   )r>   r?   rb   rF   rQ   rc   r(   cloud_armor_configrd   re   rf   rg   rh   s                r#   ri   zUpdateAlpha.Runh  s<   t**4+<+<+>?F

"
"
4
4fm.E.E.L.L 5 NC++/O.779!<*66K1BB 99 6LL7NN5JJ#$$k~~!2II
--56>?IJOPIKIJ
!==mmT#=? !
 	(78K(:;56 "
=
=mm%%)	  56
!
>
>mmT#;=  )*
!
?
?mmT#9;  12
!
<
<mmT#9;  :;6kk
--5  BC6yy
--5  %mm44CC+!;573,88 D :   1H IIr%   rj   rp   r%   r#   r   r     s1    	 D D,(MTNJr%   r   N)rn   
__future__r   r   r   googlecloudsdk.api_lib.computer   0googlecloudsdk.api_lib.compute.security_policiesr   googlecloudsdk.callioper   r	   "googlecloudsdk.command_lib.computer
   rV   4googlecloudsdk.command_lib.compute.security_policiesr   r   ReleaseTracksrS   GADefaultUniverseOnlyUpdateCommandr   BETArr   ALPHAr   rp   r%   r#   <module>r      s   . &  ' 7 C ( . E F X D%%(()iJt!! iJ  *iJX D%%**+FJ FJ  ,FJR D%%++,]J* ]J  -]Jr%   