
                         X    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
y)
z1Shared util methods common to BQExports commands.    )absolute_import)division)unicode_literalsN)errors)utilc                    | j                   }t        j                  d      j                  |      }t        j                  d      j                  |      }|s0|s.d|v rt	        j
                  d      t	        j
                  d      |r|S |rGt        j                  |       }|t	        j
                  d      t        j                  |       dz   |z   S y)aO  Returns relative resource name for a v1 B2igQuery export.

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

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

  Examples:

  args with BIG_QUERY_EXPORT="organizations/123/bigQueryExports/config1"
  returns the BIG_QUERY_EXPORT

  args with BIG_QUERY_EXPORT="config1" and projects="projects/123" returns
  projects/123/bigQueryExports/config1
  zT(organizations|projects|folders)/.*/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$!^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$/vBigQuery export must match the full resource name, or `--organization=`, `--folder=` or `--project=` must be provided.zRBigQuery export id does not match the pattern '^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$'.N/bigQueryExports/)BIG_QUERY_EXPORTrecompilematchr   InvalidSCCInputErrorr   GetParentFromNamedArguments)argsbq_export_namelong_name_formatshort_name_formatparents        =lib/googlecloudsdk/command_lib/scc/bqexports/bqexport_util.py"ValidateAndGetBigQueryExportV1Namer      s    & ((.ZZ\	E.  jj!DEKK 
"3
n''M 
 ''1 
 --d3F~''M  
*
*4
0      c                     t        j                  d      }t        j                  d      }t        j                  d      }| j                  }t        j                  | d      }|j                  |      r6t        j                  |       }|t        j                  d      | d| d| S |j                  |      r|S |j                  |      r|j                  d      \  }}| d| d| S t        j                  d      )	a  Returns relative resource name for a v2 Big Query export.

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

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

  Examples:

  args with BIG_QUERY_EXPORT="organizations/123/bigQueryExports/config1"
  and location="locations/us" returns
  organizations/123/locations/us/bigQueryExports/config1

  args with
  BIG_QUERY_EXPORT="folders/123/locations/us/bigQueryExports/config1"
  and returns folders/123/locations/us/bigQueryExports/config1

  args with BIG_QUERY_EXPORT="config1", projects="projects/123", and
  locations="us" returns projects/123/bigQueryExports/config1
  r	   zT(organizations|projects|folders)/.+/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$za(organizations|projects|folders)/.+/locations/.+/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$v2r   z/locations/r   zBigQuery export must match (organizations|projects|folders)/.+/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$ (organizations|projects|folders)/.+/locations/.+/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$ or [a-zA-Z0-9-_]{1,128}$.)
r   r   r   r   ValidateAndGetLocationr   r   r   r   split)	r   
id_pattern nonregionalized_resource_patternregionalized_resource_patternbq_export_idlocationr   parent_segment
id_segments	            r   "ValidateAndGetBigQueryExportV2Namer&   V   s   0 zz=>*%'ZZ\&" #%**i# &&,((t4( l#--d3F~''M  X[
*;L>JJ #((6 &++L9#/#5#56I#J ^Z[
2CJ<PP###	 r   )__doc__
__future__r   r   r   r   googlecloudsdk.command_lib.sccr   r   r   r&    r   r   <module>r+      s'     8 &  ' 	 1 /7t<r   