
                              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dl	m
Z
 dd	lmZ dd
lmZ d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdZ d Z!y)z/A library that is used to support our commands.    )absolute_import)division)unicode_literalsN)apis)waiter)
exceptions)
properties)	resourcesc                  .    t        j                  dd      S )z1Shortcut to get the latest Bigtable Admin client.bigtableadminv2)r   GetClientInstance     +lib/googlecloudsdk/api_lib/bigtable/util.pyGetAdminClientr          				66r   c                  .    t        j                  dd      S )z3Shortcut to get the latest Bigtable Admin messages.r   r   )r   GetMessagesModuler   r   r   GetAdminMessagesr   $   r   r   c                      dj                  dt        j                  j                  j                  j                         g      S )N/projects)joinr	   VALUEScoreprojectGetr   r   r   
ProjectUrlr   )   s1    	:z0055==AACD	EEr   c                 :    dj                  t               d| g      S )Nr   	locations)r   r   )locations    r   LocationUrlr#   -   s    	:<h7	88r   c                     t               }t        j                  | |j                        }t        j                  |||      S )N)r   r   CloudOperationPoller
operationsWaitFor)result_serviceoperation_refmessageclientpollers        r   _Awaitr-   1   s5    &&&~v7H7HI&	w	77r   c                 D    t               }t        |j                  | |      S )z5Waits for cluster long running operation to complete.)r   r-   projects_instances_clustersr)   r*   r+   s      r   AwaitClusterr1   7   s    &	22M7	KKr   c                 D    t               }t        |j                  | |      S )z6Waits for instance long running operation to complete.)r   r-   projects_instancesr0   s      r   AwaitInstancer4   =   s    &	))='	BBr   c                 D    t               }t        |j                  | |      S )z9Waits for app profile long running operation to complete.)r   r-   projects_instances_appProfilesr0   s      r   AwaitAppProfiler7   C   s    &	55}g	NNr   c                 D    t               }t        |j                  | |      S )z3Waits for table long running operation to complete.)r   r-   projects_instances_tablesr0   s      r   
AwaitTabler:   I   s    &	00-	IIr   c                 D    t               }t        |j                  | |      S )z4Waits for backup long running operation to complete.)r   r-   #projects_instances_clusters_backupsr0   s      r   AwaitBackupr=   O   s$    &	00-
 r   c                 D    t               }t        |j                  | |      S )z:Waits for logical view long running operation to complete.)r   r-   projects_instances_logicalViewsr0   s      r   AwaitLogicalViewr@   W   s    &	66w	OOr   c                 D    t               }t        |j                  | |      S )z?Waits for materialized view long running operation to complete.)r   r-   $projects_instances_materializedViewsr0   s      r   AwaitMaterializedViewrC   ]   s$    &	11='
 r   c                     t         j                  j                  |t        j                  j
                  j                  j                  | dd      S )z+Get a resource reference to an app profile.
projectsIdinstancesIdz,bigtableadmin.projects.instances.appProfilesparams
collectionr
   REGISTRYParser	   r   r   r   	GetOrFail)instanceapp_profiles     r   GetAppProfileRefrQ   e   sL    				!	!"))..66@@! @ 
" 
 r   c                     t         j                  j                  |t        j                  j
                  j                  j                  | dd      S )z&Get a resource reference to a cluster.rE   z)bigtableadmin.projects.instances.clustersrH   rK   )rO   clusters     r   GetClusterRefrT   q   sK    				!	!"))..66@@! = 
" 
 r   c                     t         j                  j                  |t        j                  j
                  j                  j                  | dd      S )z+Get a resource reference to a logical view.rE   z-bigtableadmin.projects.instances.logicalViewsrH   rK   )rO   logical_views     r   GetLogicalViewRefrW   }   sL    				!	!"))..66@@! A 
" 
 r   c                 V    t         j                  j                  | j                  d      S )z5Get a resource reference to a long running operation.zbigtableadmin.operations)r
   rL   ParseRelativeNamename)	operations    r   GetOperationRefr\      s%    				-	-nn0
 r   c                     t         j                  j                  | dt        j                  j
                  j                  j                  id      S )z(Get a resource reference to an instance.rF   z bigtableadmin.projects.instancesrH   rK   )rO   s    r   GetInstanceRefr^      sJ    				!	!

))..66@@ 4 
" 
 r   c                     t         j                  j                  |t        j                  j
                  j                  j                  | dd      S )z$Get a resource reference to a table.rE   z'bigtableadmin.projects.instances.tablesrH   rK   )rO   tables     r   GetTableRefra      sK    				!	!"))..66@@! ; 
" 
 r   "CLOUD_BIGTABLE_APP_PROFILE_WARNINGc                    t        j                  | j                        }|j                  d       |j                  d      j                  d      | dg}dg}|d   d   D ]  }|j                  dg       }|D ]g  }|j                  d      j	                  t
              r!|j                  |j                  d             H|j                  |j                  d             i  d}t        |      d	kD  r|d
j                  |      z  }t        |      d	kD  r|d
j                  |      z  }|s| t        j                  | dj                  |d   d   |            )a  Format app profile error message from API and raise new exception.

  The error messages returned from the backend API are not formatted well when
  using the default format. This raises a new generic exception with a well
  formatted error message built from the original response.

  Args:
    exception: HttpError raised by API.

  Raises:
    exceptions.HttpException: Reformatted error raised by API.
  errordetailszErrors:z!Warnings (use --force to ignore):
violationstypedescription    z
	z{}
{}r*   )jsonloadscontentget
startswithWARNING_TYPE_PREFIXappendlenr   r   HttpExceptionformat)	exceptionresponseerrorswarningsdetailrf   	violation	error_msgs           r   FormatErrorMessagesr|      s>    ZZ	))*(ll7#	g		"	"9	-	5
O;&12(!),fL"-J		v		)	)*=	>	m45immM23	   - )]QX&&I[1_V$$I	
O  '!29!=yI	 r   )"__doc__
__future__r   r   r   rk   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   googlecloudsdk.corer	   r
   r   r   r   r#   r-   r1   r4   r7   r:   r=   r@   rC   rQ   rT   rW   r\   r^   ra   rp   r|   r   r   r   <module>r      s     6 &  '  , . . * )7
7
F98LCOJP				 ; 'r   