
    M                     d    S r SSKJr  SSKJr     SS jr   SS jr  SS jrSS jrS	 rS
 r	g)zCUseful commands for interacting with the Cloud Datastore Admin API.    )	constants)utilNc                 z   [         R                  " 5       nUR                  nUR                  5       n/ Ul        U=(       d    0 n[        UR                  5       5       H7  u  pUR                  R                  UR                  R                  XS95        M9     [        X25      n
U" UU
US9nUR                  U US9nU$ )aX  Returns a request for a Datastore Admin Export.

Args:
  project: the project id to export, a string.
  output_url_prefix: the output GCS path prefix, a string.
  kinds: a string list of kinds to export.
  namespaces:  a string list of namespaces to export.
  labels: a string->string map of client labels.
Returns:
  an ExportRequest message.
keyvalue)labelsentityFilteroutputUrlPrefix)	projectId+googleDatastoreAdminV1ExportEntitiesRequest)r   GetMessages+GoogleDatastoreAdminV1ExportEntitiesRequestLabelsValueadditionalPropertiessorteditemsappendAdditionalProperty_MakeEntityFilterDatastoreProjectsExportRequest)projectoutput_url_prefixkinds
namespacesr	   messagesrequest_classlabels_messager   r   entity_filterexport_requestrequests                1lib/googlecloudsdk/api_lib/datastore/admin_api.pyGetExportEntitiesRequestr#      s      (FF- ,,..(*.%<R&6<<>*jc''..!!444JL + $J6-  ').
 332@ 4 B' 
.    c                 t   [         R                  " 5       nUR                  n[        X25      nUR	                  5       n/ Ul        U=(       d    0 n[        UR                  5       5       H7  u  pUR
                  R                  UR                  R                  XS95        M9     U" XUS9nUR                  U US9$ )aa  Returns a request for a Datastore Admin Import.

Args:
  project: the project id to import, a string.
  input_url: the location of the GCS overall export file, a string.
  kinds: a string list of kinds to import.
  namespaces:  a string list of namespaces to import.
  labels: a string->string map of client labels.
Returns:
  an ImportRequest message.
r   )r	   r
   inputUrl)r   +googleDatastoreAdminV1ImportEntitiesRequest)r   r   +GoogleDatastoreAdminV1ImportEntitiesRequestr   r   r   r   r   r   r   DatastoreProjectsImportRequest)r   	input_urlr   r   r	   r   r   r   r   r   r   import_requests               r"   GetImportEntitiesRequestr,   =   s      (FF-#J6- ,,..(*.% <R&6<<>*jc''..!!444JL + !)M. 
	0	02@ 
1 
B Br$   c           	      `    [         R                  " 5       R                  [        XX#U5      5      $ )aT  Performs a Datastore Admin v1 Export.

Args:
  project: the project id to export, a string.
  output_url_prefix: the output GCS path prefix, a string.
  kinds: a string list of kinds to export.
  namespaces:  a string list of namespaces to export.
  labels: a string->string map of client labels.
Returns:
  a google.longrunning.Operation.
)r   
GetServiceExportr#   )r   r   r   r   r	   s        r"   r/   r/   c   s-     
		!	!w5%'
( (r$   c           	      `    [         R                  " 5       R                  [        XX#U5      5      $ )a^  Performs a Datastore Admin v1 Import.

Args:
  project: the project id to import, a string.
  input_url: the input url of the GCS overall export file, a string.
  kinds: a string list of kinds to import.
  namespaces:  a string list of namespaces to import.
  labels: a string->string map of client labels.
Returns:
  a google.longrunning.Operation.
)r   r.   Importr,   )r   r*   r   r   r	   s        r"   r1   r1   u   s,     
		!	!w5fM
O Or$   c                     U =(       d    / n U  Vs/ s H  n[        U5      PM     n n[        R                  " 5       R                  U=(       d    / U S9$ s  snf )zCreates an entity filter for the given namespaces and kinds.

Args:
  namespaces: a string list of the namespaces to include in the filter.
  kinds: a string list of the kinds to include in the filter.
Returns:
  a GetMessages().EntityFilter (proto).
)r   namespaceIds)_TransformNamespaceIdr   r   "GoogleDatastoreAdminV1EntityFilter)r   r   	namespaces      r"   r   r      sX     R*BLM*Y%i0**M					>	>KRj 
? 
2 2 Ns   Ac                 0    U [         R                  :X  a  gU $ )z@Transforms client namespace conventions into server conventions. )r   DEFAULT_NAMESPACE)namespace_ids    r"   r4   r4      s    Y000	r$   )NNN)
__doc__ googlecloudsdk.api_lib.datastorer   r   r#   r,   r/   r1   r   r4    r$   r"   <module>r>      sT    J 7 1
 $((,$(	$R $((,$(	#BL ?C($O 2 r$   