
                         L    S r SSKrSSKJr  SSKJr  S rS rS rS rS	 r	S
 r
g)z4Shared util methods common to Notification commands.    N)errors)utilc                     [         R                  " S5      nUR                  U 5      (       d  [        R                  " S5      eU R                  S5      S   $ )Nz#(organizations|projects|folders)/.*zrWhen providing a full resource path, it must also include the pattern the organization, project, or folder prefix./notificationConfigs/r   )recompilematchr   InvalidSCCInputErrorsplit)notification_config_nameresource_patterns     Elib/googlecloudsdk/command_lib/scc/notifications/notification_util.py#GetParentFromNotificationConfigNamer      sU    ZZ EF			 8	9	9

%
%	7  
"	'	'(?	@	CC    c                 @    U R                  S5      nUS   S-   US   -   $ )N/r      )r   )resource_namelist_organization_componentss     r   GetParentFromResourceNamer       s.    !.!4!4S!9	%a	(3	.1Ma1P	PPr   c                 ^   [         R                  " S5      n[         R                  " S5      nU R                  nUR                  U5      (       d,  UR                  U5      (       d  [        R
                  " S5      eUR                  U5      (       a  U$ [        R                  " U 5      S-   U-   $ )aV  Returns relative resource name for a v1 notification config.

Validates on regexes for args containing full names or short names with
resources. Localization is supported by the
ValidateAndGetNotificationConfigV2Name method.

Args:
  args: an argparse object that should contain .NOTIFICATIONCONFIGID,
    optionally 1 of .organization, .folder, .project

Examples:

args with NOTIFICATIONCONFIGID="organizations/123/notificationConfigs/config1"
returns the NOTIFICATIONCONFIGID

args with NOTIFICATIONCONFIGID="config1" and projects="projects/123" returns
projects/123/notificationConfigs/config1
M(organizations|projects|folders)/.+/notificationConfigs/[a-zA-Z0-9-_]{1,128}$[a-zA-Z0-9-_]{1,128}$zNotificationConfig must match either (organizations|projects|folders)/.+/notificationConfigs/[a-zA-Z0-9-_]{1,128})$ or [a-zA-Z0-9-_]{1,128}$.r   )r   r   NOTIFICATIONCONFIGIDr	   r   InvalidNotificationConfigErrorr   GetParentFromNamedArguments)argsr   
id_patternnotification_config_ids       r   &ValidateAndGetNotificationConfigV1Namer    %   s    & ZZU zz12*44			
 
344

/
/	!  233!! &&t, r   c                 <   U R                  S5      (       a  SU R                  ;   aj  [        R                  " S5      nUR	                  U R                  5      (       a  U R                  R                  S5      S   $ [        R                  " S5      eU R                  $ g)z?Returns the location from the location arg, or throws an error.locationr   z^locations/.*$zRWhen providing a full resource path, it must include the pattern '^locations/.*$'.global)IsKnownAndSpecifiedr"   r   r   r	   r   r   r
   )r   long_patterns     r   ValidateAndGetLocationFromV2Argr'   Q   s    	j))
dmmZZ 01l			DMM	*	*}}""3'++)) 
 	
 ]]r   c                    [         R                  " S5      n[         R                  " S5      n[         R                  " S5      nU R                  n[        R                  " U S5      nUR                  U5      (       a  [        R                  " U 5       SU SU 3$ UR                  U5      (       a  U$ UR                  U5      (       a  UR                  S5      u  pgU SU SU 3$ [        R                  " S5      e)a  Returns relative resource name for a v2 notification config.

Validates on regexes for args containing full names with locations or short
names with resources.

Args:
  args: an argparse object that should contain .NOTIFICATIONCONFIGID,
    optionally 1 of .organization, .folder, .project; and optionally .location

Examples:

args with NOTIFICATIONCONFIGID="organizations/123/notificationConfigs/config1"
and location="locations/us" returns
organizations/123/locations/us/notificationConfigs/config1

args with
NOTIFICATIONCONFIGID="folders/123/locations/us/notificationConfigs/config1"
and returns folders/123/locations/us/notificationConfigs/config1

args with NOTIFICATIONCONFIGID="config1", projects="projects/123", and
locations="us" returns projects/123/notificationConfigs/config1
r   r   zZ(organizations|projects|folders)/.+/locations/.+/notificationConfigs/[a-zA-Z0-9-_]{1,128}$v2z/locations/r   zNotificationConfig must match (organizations|projects|folders)/.+/notificationConfigs/[a-zA-Z0-9-_]{1,128})$, (organizations|projects|folders)/.+/locations/.+/notificationConfigs/[a-zA-Z0-9-_]{1,128})$, or [a-zA-Z0-9-_]{1,128}$.)
r   r   r   r   ValidateAndGetLocationr	   r   r   r   r   )r   r    nonregionalized_resource_patternregionalized_resource_patternr   r"   parent_segment
id_segments           r   &ValidateAndGetNotificationConfigV2Namer/   e   s
   . zz12*%'ZZU&" #%**b#  44((t4( ,--..t45[
J_`v_wxx #(()?@@!! &++,BCC#9#?#?$ ^ [
2G
|TT--#	 r   c                     U R                   nSU;   a  Ub  [        R                  " S5      egUc  [        R                  " S5      eg)zAValidates that only a full resource or resouce args are provided.r   NzOnly provide a full resource name (organizations/123/notificationConfigs/test-config) or an --(organization|folder|project) flag, not both.z{A corresponding parent by a --(organization|folder|project) flag must be provided if it is not included in notification ID.)r   r   r   )r   parentr   s      r    ValidateMutexOnConfigIdAndParentr2      s`    44""11B   ~

/
/	@  r   )__doc__r   googlecloudsdk.command_lib.sccr   r   r   r   r    r'   r/   r2    r   r   <module>r6      s5     ; 	 1 /DQ
)X(6rr   