
    t                         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
      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y)zGDeclarative Request Hooks for Security Health Analytics custom modules.    )absolute_import)division)unicode_literalsN)InvalidSCCInputError)CleanUpUserInputz /securityHealthAnalyticsSettingsz([0-9]{1,20})$z^[0-9]{1,19}$z^organizations/[0-9]{1,19}$c                 t    ~ t        |      |_        |j                  dvrt        d|j                  z        |S )z2Creates a Security Health Analytics 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/sha/request_hooks.py0CreateSecurityHealthAnalyticsCustomModuleReqHookr       sG    	$T*#*	"99
	 "&"7"7	89 9 
*    c                 z    ~ t        |      }|t        |      }|dz   |z   |_        |S t        |      }||_        |S )z2Deletes a Security Health Analytics custom module./customModules/r   _ValidateAndGetCustomModuleIdname+_ValidateAndGetCustomModuleFullResourceNamer   r   r   r   custom_module_idcustom_modules         r   0DeleteSecurityHealthAnalyticsCustomModuleReqHookr   +   S    	 &&4T:)),<<CH 
* @EMCH	*r   c                 z    ~ t        |      }|t        |      }|dz   |z   |_        |S t        |      }||_        |S )z/Gets a Security Health Analytics custom module.r   r   r   s         r   -GetSecurityHealthAnalyticsCustomModuleReqHookr!   8   r   r   c                 z    ~ t        |      }|t        |      }|dz   |z   |_        |S t        |      }||_        |S )z:Gets an effective Security Health Analytics custom module.z/effectiveCustomModules/)r   r   r   4_ValidateAndGetEffectiveCustomModuleFullResourceNamer   s         r   6GetEffectiveSecurityHealthAnalyticsCustomModuleReqHookr$   E   sS    	 &&4T:225EECH 
* INMCH	*r   c                 (    ~ t        |      |_        |S )z/Lists Security Health Analytics custom modules.r   r   r   s      r   /ListSecurityHealthAnalyticsCustomModulesReqHookr'   R       	$T*#*	*r   c                 (    ~ t        |      |_        |S )z:Lists descendant Security Health Analytics custom modules.r&   r   s      r   9ListDescendantSecurityHealthAnalyticsCustomModulesReqHookr*   Y   r(   r   c                 (    ~ t        |      |_        |S )z9Lists effective Security Health Analytics custom modules.r&   r   s      r   8ListEffectiveSecurityHealthAnalyticsCustomModulesReqHookr,   `   r(   r   c                     ~ t        |      }d}|j                  }|t        |      }|dz   |z   }nt        |      }||_        |j
                  ||j
                  _        |S )z/Test a Security Health Analytics custom module. r   )r   .testSecurityHealthAnalyticsCustomModuleRequestr   r   r   #securityHealthAnalyticsCustomModule)r   r   r   r   custom_module_nametest_reqr   s          r   /TestSecurityHealthAnalyticsCustomModulesReqHookr3   g   st    	 &&??(4T:"336FFDTJ#(22>8JH005	*r   c                 (    ~ t        |      |_        |S )z4Simulates a Security Health Analytics custom module.r&   r   s      r   3SimulateSecurityHealthAnalyticsCustomModulesReqHookr5   x   r(   r   c                     ~ t        |      }|t        |      }|dz   |z   |_        nt        |      }||_        t	        |j
                        |_        |j                  dvrt        d|j                  z        |S )z2Updates a Security Health Analytics 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   0UpdateSecurityHealthAnalyticsCustomModuleReqHookr9      s    	 &&4T:)),<<CH?EMCH#CNN3#.	"FF
	+-1-B-B	CD D 
*r   c                     | j                   }t        j                  |      st        dt        j                  z        |S )zValidates customModuleId.z1Custom module id does not match the pattern '%s'.)r   _SHA_CUSTOM_MODULE_ID_PATTERNmatchr   pattern)r   r   s     r   r   r      sC    ''	&	,	,-=	>
;%--	./ / r   c                     | j                   }t        j                  dt        j                  z        }|j                  |      st        d      |S )z+Validates custom module full resource name.zT(organizations|projects|folders)/.*/securityHealthAnalyticsSettings/customModules/%stCustom module must match the full resource name, or `--organization=`, `--folder=` or `--project=` must be provided.r   recompiler;   r=   r<   r   r   r   resource_patterns      r   r   r      sZ    $$-ZZ6>>?@ 
			.
	9: : 
r   c                     | j                   }t        j                  dt        j                  z        }|j                  |      st        d      |S )z5Validates effective custom module full resource name.z](organizations|projects|folders)/.*/securityHealthAnalyticsSettings/effectiveCustomModules/%sr?   r@   rC   s      r   r#   r#      sU    $$-ZZe%--. 
			.
~  
r   c                 n   | j                   d| j                   v rNt        j                  | j                         st        dt        j                  z        | j                   t
        z   S t        j                  | j                         st        dt        j                  z        d| j                   z   t
        z   S | j                  rd| j                  v rNt        j                  d      }|j                  | j                        st        d      | j                  t
        z   S d| j                  z   t
        z   S | j                  rd| j                  v rNt        j                  d	      }|j                  | j                        st        d
      | j                  t
        z   S d| j                  z   t
        z   S y)zValidates parent.N/zFWhen providing a full resource path, it must include the pattern '%s'.z-Organization does not match the pattern '%s'.zorganizations/z^folders/.*$zPWhen providing a full resource path, it must include the pattern '^folders/.*$'.zfolders/z^projects/.*$zQWhen providing a full resource path, it must include the pattern '^projects/.*$'.z	projects/)organization_ORGANIZATION_NAME_PATTERNr<   r   r=   _PARENT_SUFFIX_ORGANIZATION_ID_PATTERNfolderrA   rB   project)r   r=   s     r   r   r      s   	"
d'--d.?.?@"0889: 	:   >11%++D,=,=>";$,,-. 	.  $"3"33nDD	[[
dkk

>*g]]4;;'" 	 {{^++$++%66	\\
dll

?+g]]4<<("  	  ||n,,4<<'.88 r   )__doc__
__future__r   r   r   rA   %googlecloudsdk.command_lib.scc.errorsr   $googlecloudsdk.command_lib.scc.hooksr   rJ   rB   r;   rK   rI   r   r   r!   r$   r'   r*   r,   r3   r5   r9   r   r   r#   r    r   r   <module>rS      s    N &  ' 	 F A3 *

+; < %2::o6 'RZZ(EF 


"$	
(9r   