
                         b   S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  S rS	 rS
 rS rS rS rS rS\R*                  S\S\R.                  \R0                  R2                  \R4                  R2                  4   4S jrS\R*                  S\R.                  \S4   4S jrg)z<Shared utility functions for Cloud SCC muteconfigs commands.    N)errors)util)times)securitycenter_v1_messages)securitycenter_v2_messagesc                    U R                   b  [        R                  " S5      n[        R                  " S5      nUR                  U R                   5      (       a  U R                   $ UR                  U R                   5      (       a  SU R                    3$ SU R                   ;   a  [        R
                  " S5      e[        R
                  " S5      eU R                  bw  SU R                  ;   aX  [        R                  " S5      nUR                  U R                  5      (       d  [        R
                  " S	5      eU R                  $ S
U R                   3$ U R                  bw  SU R                  ;   aX  [        R                  " S5      nUR                  U R                  5      (       d  [        R
                  " S5      eU R                  $ SU R                   3$ g)zValidates parent.Nz^organizations/[0-9]{1,19}$z^[0-9]{1,19}$zorganizations//z_When providing a full resource path, it must include the pattern '^organizations/[0-9]{1,19}$'.z8Organization does not match the pattern '^[0-9]{1,19}$'.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recompilematchr   InvalidSCCInputErrorfolderproject)argsname_pattern
id_patternpatterns       6lib/googlecloudsdk/command_lib/scc/muteconfigs/util.pyValidateAndGetParentr      s   	"::;<LO,J$++,,))**d//011
d''+ 
 
%
%B  
[[
dkk

>*g]]4;;''))
 	

 {{}%%	\\
dll

?+g]]4<<(())
 	

 ||''     c                     U R                   n[        R                  " S5      nUR                  U5      (       d  [        R
                  " S5      eU$ )zValidate muteConfigId.z!^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$zNMute config id does not match the pattern '^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$'.)mute_configr   r   r   r   r   )r   mute_config_idr   s      r   ValidateAndGetMuteConfigIdr   M   sK    ##.JJ:;'	~	&	&

%
%	0 
 r   c           
      x   U R                   n[        R                  " S5      n[        R                  " S5      nUR                  U5      (       a  U$ UR                  U5      (       a?  US:X  a7  UR	                  S5      nUS    SUS    SU R
                   SUS    SUS	    3	$ U$ [        R                  " S
5      e)z(Validates muteConfig full resource name.zP(organizations|projects|folders)/.*/muteConfigs/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$z](organizations|projects|folders)/.*/locations/.*/muteConfigs/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$v2r	   r      /locations/      zrMute config must match the full resource name, or `--organization=`, `--folder=` or `--project=` must be provided.)r   r   r   r   splitlocationr   r   )r   versionr   resource_patternregionalized_resource_patternmute_config_componentss         r   (ValidateAndGetMuteConfigFullResourceNamer(   Z   s      +ZZX #%**e# #((55 K(($*005&q)*!,B1,E+FkRVR_R_Q``abxyzb{a||}  U  VW  X  ~Y  Z  Z 	##7	 r   c                 F    U R                  S5      nU[        U5      S-
     $ )z/Gets muteConfig id from the full resource name.r	   r   )r"   len)r   r'   s     r   #GetMuteConfigIdFromFullResourceNamer+   w   s)    &,,S1	$: ;a ?	@@r   c                     U R                  S5      nUS:X  a  US    SUS    3$ US:X  a  US    SUS    SUS    SUS    3$ g)	z(Gets parent from the full resource name.r	   v1r   r   r   r    r!   N)r"   )r   r$   r'   s      r   GetParentFromFullResourceNamer.   }   s    &,,S1_ %Q'(*@*C)DEE_ %Q'(*@*C)DAF\]^F_E``abxyzb{a|}}	 r   c                     [        U 5      nUb*  US:X  a  [        X5      n[        U 5      nU SU 3Ul        U$ [        R
                  " X5      U l        [        X5      nXQl        U$ )z&Generates the name of the mute config.r   z/muteConfigs/)r    ValidateAndGetRegionalizedParentr   namescc_utilValidateAndGetLocationr#   r(   )r   reqr$   parentr   r   s         r   GenerateMuteConfigNamer6      so    %&$/=f/5N~&67CH
 
* 33DBDM:4IKH	*r   c                    U R                   b~  SU R                   ;   a]  [        R                  " S5      nUR                  U R                   5      (       d  [        R
                  " S5      eU SU R                    3$ U SU R                    3$ g)zAppends location to parent.Nr	   z^locations/.*$zRWhen providing a full resource path, it must include the pattern '^locations/.*$'.r   )r#   r   r   r   r   r   )r   r5   r   s      r   r0   r0      s    	]]
dmm

+,g]]4==)))) 
 	

 4==/**x{4==/22 r   r   r$   returnc                    US:X  a  [         R                  O[        R                  nU R                  S:X  a  UR
                  R                  $ U R                  S:X  a  UR
                  R                  $ [        R                  " S5      e)zParses and validates type.r   staticdynamicz*Type must be either 'static' or 'dynamic'.)
r   %GoogleCloudSecuritycenterV2MuteConfigr   %GoogleCloudSecuritycenterV1MuteConfigtypeTypeValueValuesEnumSTATICDYNAMICr   r   )r   r$   mute_config_classs      r   ValidateAndGetTyperC      sx     
D !FF%KK 
 
YY(00777yyI00888##2	 r   c                 v   U R                   c  g[        U S5      (       a&  U R                  S:w  a  [        R                  " S5      e [
        R                  " U R                   5      n[
        R                  " U5      $ ! [
        R                  [
        R                  4 a    [        R                  " S5      ef = f)z!Parses and validates expiry time.Nr>   r;   z9Expiry time is only supported for 'dynamic' mute configs.z^Invalid expiry time. See `$ gcloud topic datetimes` for information on supported time formats.)
expiry_timehasattrr>   r   r   r   ParseDateTimeFormatDateTimeDateTimeSyntaxErrorDateTimeValueError)r   expiry_time_dts     r   ValidateAndGetExpiryTimerL      s     
T6tyyI5

%
%C (()9)9:N//

#
#U%=%=	> 

%
%	# s   5A= =;B8)__doc__argparser   typinggooglecloudsdk.command_lib.sccr   r   r2   googlecloudsdk.core.utilr   7googlecloudsdk.generated_clients.apis.securitycenter.v1r   7googlecloudsdk.generated_clients.apis.securitycenter.v2r   r   r   r(   r+   r.   r6   r0   	NamespacestrUnionr=   r?   r<   rC   rL    r   r   <module>rX      s    C  	  1 ; * ^ ^-(`
:A~3 X// # &,,DDXXDDXXZC &


\\#t)r   