
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 dZ
 ej                  d	      Z ej                  d
ej                  z        Z ej                  dej                  z        Z ej                  d      Z ej                  d      Z ej                  d      Z ej                  d      Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d  Z$d! Z%y)"zDDeclarative Request Hooks for Event Threat Detection custom modules.    )absolute_import)division)unicode_literalsNInvalidSCCInputError)CleanUpUserInputz/eventThreatDetectionSettingsz([0-9]{1,20})$zQ(organizations|projects|folders)/.*/eventThreatDetectionSettings/customModules/%szZ(organizations|projects|folders)/.*/eventThreatDetectionSettings/effectiveCustomModules/%sz[0-9]{1,19}zorganizations/[0-9]{1,19}z
folders/.*zprojects/.*c                 t    ~ t        |      |_        |j                  dvrt        d|j                  z        |S )z0Creates an Event Threat Detection custom module.)enableddisabledzYInvalid custom module enablement state: %s. Enablement state must be enabled or disabled.)_ValidateAndGetParentparentenablement_stater   refargsreqs      Flib/googlecloudsdk/command_lib/scc/custom_modules/etd/request_hooks.py-CreateEventThreatDetectionCustomModuleReqHookr   ,   sG    	$T*#*	"99
	 "&"7"7	89 9 
*    c                 z    ~ t        |      }|t        |      }||_        |S t        |      }|dz   |z   |_        |S )z0Deletes an Event Threat Detection custom module./customModules/r   +_ValidateAndGetCustomModuleFullResourceNamename_ValidateAndGetCustomModuleIdr   r   r   r   custom_modulecustom_module_ids         r   -DeleteEventThreatDetectionCustomModuleReqHookr   7   sQ    	 &&^?EMCH
 
* 5T:)),<<CH	*r   c                 z    ~ t        |      }|t        |      }||_        |S t        |      }|dz   |z   |_        |S )z-Gets an Event Threat Detection custom module.r   r   r   s         r   *GetEventThreatDetectionCustomModuleReqHookr!   E   sQ    	 &&^?EMCH 
* 5T:)),<<CH	*r   c                 z    ~ t        |      }|t        |      }||_        |S t        |      }|dz   |z   |_        |S )z7Gets an effective Event Threat Detection custom module.z/effectiveCustomModules/)r   4_ValidateAndGetEffectiveCustomModuleFullResourceNamer   r   r   s         r   3GetEffectiveEventThreatDetectionCustomModuleReqHookr$   R   sQ    	 &&^HNMCH 
* 5T:225EECH	*r   c                 (    ~ t        |      |_        |S )z,Lists Event Threat Detection custom modules.r   r   r   s      r   ,ListEventThreatDetectionCustomModulesReqHookr'   _       	$T*#*	*r   c                 (    ~ t        |      |_        |S )z7Lists descendant Event Threat Detection custom modules.r&   r   s      r   6ListDescendantEventThreatDetectionCustomModulesReqHookr*   f   r(   r   c                 (    ~ t        |      |_        |S )z6Lists effective Event Threat Detection custom modules.r&   r   s      r   5ListEffectiveEventThreatDetectionCustomModulesReqHookr,   m   r(   r   c                     ~ t        |      }d}|t        |      }nt        |      }|dz   |z   }|j                  }||_        |j
                  ||j
                  _        |S )z2Validates an Event Threat Detection custom module. r   )r   r   r   /validateEventThreatDetectionCustomModuleRequestr    eventThreatDetectionCustomModule)r   r   r   r   custom_module_namer   test_reqs          r   0ValidateEventThreatDetectionCustomModulesReqHookr3   t   ss    	 &&^DTJ4T:"336FF@@(#(..:5GH--2	*r   c                     ~ t        |      }|t        |      }||_        nt        |      }|dz   |z   |_        t	        |j
                        |_        |j                  dvrt        d|j                  z        |S )z0Updates an Event Threat Detection custom module.r   )r
   r   	inheritedzdInvalid custom module enablement state: %s. Enablement state must be enabled, disabled or inherited.)r   r   r   r   r   
updateMaskr   r   r   s         r   -UpdateEventThreatDetectionCustomModuleReqHookr7      s    	 &&^?EMCH4T:)),<<CH#CNN3#.	"FF
	+-1-B-B	CD D 
*r   c                     | j                   }t        j                  |      r|S t        dt        j                  z        )zValidates customModuleId.z1Custom module ID does not match the pattern '%s'.)r   _ETD_CUSTOM_MODULE_ID_PATTERNmatchr   pattern)r   r   s     r   r   r      sA    ''"(()9:9%--.	 r   c                 \    | j                   }t        j                  |      r|S t               )z/Validates a custom module's full resource name.)r   _ETD_CUSTOM_MODULE_PATTERNr:   _InvalidResourceNamer   r   s     r   r   r      s*    $$-%%m4r   c                 \    | j                   }t        j                  |      r|S t               )z:Validates an effective custom module's full resource name.)r   $_ETD_EFFECTIVE_CUSTOM_MODULE_PATTERNr:   r>   r?   s     r   r#   r#      s*    $$-)//>r   c                     d| v r-t         j                  |       r	| t        z   S t        t               t        j                  |       rd| z   t        z   S t        dt        j                  z        )z%Validates an organization name or id./zorganizations/z-Organization does not match the pattern '%s'.)_ORGANIZATION_NAME_PATTERN	fullmatch_PARENT_SUFFIX"_InvalidFullResourcePathForPattern_ORGANIZATION_ID_PATTERNr   r;   )organizations    r   _NormalizeOrganizationrJ      sk    L!++L9N**
,-G
HH''5l*^;;5 (()	 r   c                 |    d| v r-t         j                  |       r	| t        z   S t        t               d| z   t        z   S )z'Validates and normalizes a folder name.rC   zfolders/)_FOLDER_NAME_PATTERNrE   rF   rG   )folders    r   _NormalizeFolderrN      s>    F]%%f-n$$
,-A
BB	f	~	--r   c                 |    d| v r-t         j                  |       r	| t        z   S t        t               d| z   t        z   S )z(Validates and normalizes a project name.rC   z	projects/)_PROJECT_NAME_PATTERNrE   rF   rG   )projects    r   _NormalizeProjectrR      s>    G^&&w/~%%
,-B
CC	w		//r   c                     | j                   t        | j                         S | j                  t        | j                        S | j                  t        | j                        S y)zValidates parent.N)rI   rJ   rM   rN   rQ   rR   )r   s    r   r   r      sT    	"!$"3"344	[[DKK((	\\T\\**	r   c                      t        d      S )zFReturns an error indicating that a module lacks a valid resource name.zuCustom module must match the full resource name, or `--organization=`, `--folder=`, or `--project=` must be provided.r    r   r   r>   r>      s    	8
 r   c                 2    t        d| j                  z        S )zCReturns an error indicating that provided resource path is invalid.zDWhen providing a full resource path, it must match the pattern '%s'.)r   r;   )r;   s    r   rG   rG      s    	L
 r   )&__doc__
__future__r   r   r   re%googlecloudsdk.command_lib.scc.errorsr   $googlecloudsdk.command_lib.scc.hooksr   rF   compiler9   r;   r=   rA   rH   rD   rL   rP   r   r   r!   r$   r'   r*   r,   r3   r7   r   r   r#   rJ   rN   rR   r   r>   rG   rU   r   r   <module>r]      s   K &  ' 	 F A0 *

+; < 'RZZ#++, 
 (2rzz #++,( $
 &2::m4 'RZZ(CD !rzz,/ "

=1 

$$	.0r   