
    
                         S r SSKrSSKJr  SSKJr  \R                   " S S\R                  5      5       rS\S\	4S	 jr
S
 rS rg)zThreat Detection utils.    N)
k8s_object)	resourcesc                   ~    \ rS rSrSr\R                  " 5       r\R                  " 5       r\R                  " 5       r	Sr
g)ThreatDetectionState   zThreat Detection state. N)__name__
__module____qualname____firstlineno____doc__enumautoDISABLEDENABLEDREQUIRE_REDEPLOY__static_attributes__r       ;lib/googlecloudsdk/command_lib/run/threat_detection_util.pyr   r      s'    YY[(IIK'YY[r   r   statereturnc                     U [         R                  :X  a  gU [         R                  :X  a  gU [         R                  :X  a  g[	        SU  35      e)z"Prints the threat detection state. EnabledzRedeploy revision to enablez Unknown threat detection state: )r   r   r   r   
ValueError)r   s    r   PrintThreatDetectionStater      sK    
"+++
"***
"333(5eW=>>r   c                    U (       d  g[        U 5      (       d  [        R                  U l        g[        R                  U l        U R
                  (       d  g[        R                  R                  U R
                  SU R                  R                  0SS9nUR                  U5      nU(       a'  [        U5      (       d  [        R                  U l        ggg)a  Util to update the threat detection state of a service.

When the threat detection state is enabled on a service, this function ensures
that it is also enabled on the latest revision. If not, it updates the
service's threat_detection_state state to prompt the user to redeploy.

Args:
  service: the service to update the threat detection state for.
  client: a connected serverless operations client to fetch the latest
    revision of the service.
NnamespacesIdzrun.namespaces.revisions)params
collection)_HasThreatDetectionEnabledr   r   threat_detection_stater   latest_created_revisionr   REGISTRYParsemetadata	namespaceGetRevisionr   )serviceclientrevision_refrevisions       r   UpdateThreatDetectionStater-   *   s     

	#G	,	,%9%B%BG"
#7#?#?' 		(	(
##))%%g..889+ * ,
 -(0::%9%J%JG" ;Xr   c                 x    U R                   R                  [        R                  S5      R	                  5       S:H  $ )z<Returns true if threat detection is enabled on the resource.r   true)annotationsgetr   THREAT_DETECTION_ANNOTATIONlower)resources    r   r!   r!   L   s7     

0
0"	r   )r   r   googlecloudsdk.api_lib.runr   googlecloudsdk.corer   uniqueEnumr   strr   r-   r!   r   r   r   <module>r:      sV      1 ) !499 ! !?%9 ?c ?KDr   