
    @
                     h    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d	 Zd
edefdZy)z0Common validation methods for some SQL commands.    )absolute_import)division)unicode_literalsN)validate)arg_parsersc                      ddfd} | S )zReturns a function that validates an instance name using predefined rules.

  Returns:
    function: str -> str, usable as an argparse type
  z^[a-z][a-z0-9-:.]*zVmust be composed of lowercase letters, numbers, and hyphens; must start with a letter.c                     t        j                  dz   |       s%t        j                  dj	                  |             t        j                  |        | S )N$zBad value [{0}]: {1})rematchr   ArgumentTypeErrorformatapi_validateValidateInstanceName)valuedescriptionpatterns    .lib/googlecloudsdk/command_lib/sql/validate.pyParsez*InstanceNameRegexpValidator.<locals>.Parse'   sK    88GcM5)))
 
'
'{
;= =%%e,L     )r   r   r   s    @@r   InstanceNameRegexpValidatorr      s     "'-+ 
,r   c                 :    	 t        |        y# t        $ r Y yw xY w)a-  Checks if the backup request is project level.

  Project level requests will have backup_id in string format whearas they will
  be integer values for instance level backup requests.

  Args:
    backup_id: The id of the requested backup.

  Returns:
    True if is a project level backup request.
  FT)int
ValueError	backup_ids    r   IsProjectLevelBackupRequestr   1   s'    	N  
 s    	r   returnc                     | xr d| v S )a  Checks if the backup request is a backupdr backup by checking if the backup id contains /backupVaults.

  A backupdr backup will have the backup in the format of
  projects/{project}/locations/{location}/backupVaults/{backup_vault}/dataSources/{data_source}/backups/{backup}.

  Args:
    backup_id: The id of the requested backup.

  Returns:
    True if the request is a backupdr backup request.
  z/backupVaultsr   r   s    r   IsBackupDrBackupRequestr!   E   s     
	3)33r   )__doc__
__future__r   r   r   r   googlecloudsdk.api_lib.sqlr   r   googlecloudsdk.callioper   r   r   strboolr!   r   r   r   <module>r(      s9    7 &  ' 	 ? /.(4s 4t 4r   