
                             S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  Sr
\R                  " S	5      r\R                  " S
\R                  -  5      r\R                  " S\R                  -  5      r\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " S5      rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#S  r$S! r%g)"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                 x    A [        U5      Ul        UR                  S;  a  [        SUR                  -  5      eU$ )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    A [        U5      nUc  [        U5      nXBl        U$ [        U5      nUS-   U-   Ul        U$ )z0Deletes an Event Threat Detection custom module./customModules/r   +_ValidateAndGetCustomModuleFullResourceNamename_ValidateAndGetCustomModuleIdr   r   r   r   custom_modulecustom_module_ids         r   -DeleteEventThreatDetectionCustomModuleReqHookr   7   sO    	 &&^?EMH
 
* 5T:)),<<CH	*r   c                 z    A [        U5      nUc  [        U5      nXBl        U$ [        U5      nUS-   U-   Ul        U$ )z-Gets an Event Threat Detection custom module.r   r   r   s         r   *GetEventThreatDetectionCustomModuleReqHookr!   E   sO    	 &&^?EMH 
* 5T:)),<<CH	*r   c                 z    A [        U5      nUc  [        U5      nXBl        U$ [        U5      nUS-   U-   Ul        U$ )z7Gets an effective Event Threat Detection custom module.z/effectiveCustomModules/)r   4_ValidateAndGetEffectiveCustomModuleFullResourceNamer   r   r   s         r   3GetEffectiveEventThreatDetectionCustomModuleReqHookr$   R   sO    	 &&^HNMH 
* 5T:225EECH	*r   c                 (    A [        U5      Ul        U$ )z,Lists Event Threat Detection custom modules.r   r   r   s      r   ,ListEventThreatDetectionCustomModulesReqHookr'   _       	$T*#*	*r   c                 (    A [        U5      Ul        U$ )z7Lists descendant Event Threat Detection custom modules.r&   r   s      r   6ListDescendantEventThreatDetectionCustomModulesReqHookr*   f   r(   r   c                 (    A [        U5      Ul        U$ )z6Lists effective Event Threat Detection custom modules.r&   r   s      r   5ListEffectiveEventThreatDetectionCustomModulesReqHookr,   m   r(   r   c                     A [        U5      nSnUc  [        U5      nO[        U5      nUS-   U-   nUR                  nXBl        UR
                  b  XFR
                  l        U$ )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   so    	 &&^DTJ4T:"336FF@@((..:5G--2	*r   c                     A [        U5      nUc  [        U5      nXBl        O[        U5      nUS-   U-   Ul        [	        UR
                  5      Ul        UR                  S;  a  [        SUR                  -  5      eU$ )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H4T:)),<<CH#CNN3#.	"FF
	+-1-B-B	CD D 
*r   c                     U R                   n[        R                  U5      (       a  U$ [        S[        R                  -  5      e)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      sD    ''"(()9::9%--.	 r   c                 f    U R                   n[        R                  U5      (       a  U$ [        5       e)z/Validates a custom module's full resource name.)r   _ETD_CUSTOM_MODULE_PATTERNr:   _InvalidResourceNamer   r   s     r   r   r      s-    $$-%%m44r   c                 f    U R                   n[        R                  U5      (       a  U$ [        5       e)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                     SU ;   a2  [         R                  U 5      (       a	  U [        -   $ [        [         5      e[        R                  U 5      (       a  SU -   [        -   $ [        S[        R                  -  5      e)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      sq    L!++L99N**
,-G
HH''55l*^;;5 (()	 r   c                     SU ;   a2  [         R                  U 5      (       a	  U [        -   $ [        [         5      eSU -   [        -   $ )z'Validates and normalizes a folder name.rC   zfolders/)_FOLDER_NAME_PATTERNrE   rF   rG   )folders    r   _NormalizeFolderrN      sA    F]%%f--n$$
,-A
BB	f	~	--r   c                     SU ;   a2  [         R                  U 5      (       a	  U [        -   $ [        [         5      eSU -   [        -   $ )z(Validates and normalizes a project name.rC   z	projects/)_PROJECT_NAME_PATTERNrE   rF   rG   )projects    r   _NormalizeProjectrR      sA    G^&&w//~%%
,-B
CC	w		//r   c                     U R                   b  [        U R                   5      $ U R                  b  [        U R                  5      $ U R                  b  [        U R                  5      $ g)zValidates parent.N)rI   rJ   rM   rN   rQ   rR   )r   s    r   r   r      sT    	"!$"3"344	[[DKK((	\\T\\**	r   c                      [        S5      $ )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    [        SU R                  -  5      $ )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 "

+; < ZZ#++, 
 (*zz #++,( $
 ::m4 ZZ(CD zz,/ 

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