
    
                         d Z ddlZddlmZ ddlmZ ej                   G d dej                               Zdede	fd	Z
d
 Zd Zy)zThreat Detection utils.    N)
k8s_object)	resourcesc                   v    e Zd ZdZ ej
                         Z ej
                         Z ej
                         Zy)ThreatDetectionStatezThreat Detection state.N)	__name__
__module____qualname____doc__enumautoDISABLEDENABLEDREQUIRE_REDEPLOY     ;lib/googlecloudsdk/command_lib/run/threat_detection_util.pyr   r      s-    TYY[(DIIK'TYY[r   r   statereturnc                     | t         j                  k(  ry| t         j                  k(  ry| t         j                  k(  ryt	        d|        )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                 ~   | syt        |       st        j                  | _        yt        j                  | _        | j
                  syt        j                  j                  | j
                  d| j                  j                  id      }|j                  |      }|r"t        |      st        j                  | _        yyy)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    | j                   j                  t        j                  d      j	                         dk(  S )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>r7      sV      1 ) !499 ! !?%9 ?c ?KDr   