
    W#                     N   S r SSKJr  SSKJr  SSKJr  SSKJrJrJr  SSK	J
r
  SSKJr  SSKJr  S	rS
\R                   SSS\\   S\4S jrS
\R                   SSS\\   S\4S jrS
\R                   SS4S jrS
\R                   SSS\\\4   4S jr S"S
\R                   SSS\4S jjrS
\R                   SSS\S\S\\\\   4   4
S jr S#S
\R                   SSS\S\S\S\\\\   4   4S jjrS
\R                   4S jrS rS
\R                   SSS\
R:                  4S  jrg!)$z2The BigQuery CLI row access policy client library.    )absolute_import)division)print_function)AnyDictList)iam)bigquery_client)bq_id_utilsz!roles/bigquery.filteredDataViewerbqclientpolicy_referencez4bq_id_utils.ApiClientHelper.RowAccessPolicyReferencegranteesfilter_predicatec                    UR                   UR                  UR                  UR                  S.UUS.nU R	                  5       R                  5       R                  UR                   UR                  UR                  US9R                  5       $ )a  Create a row access policy on the given table reference.

Arguments:
 bqclient: BigQuery client to use for the request.
 policy_reference: Reference to the row access policy to create.
 grantees: Users or groups that can access rows protected by the row access
   policy.
 filter_predicate: A SQL boolean expression that needs to be true for a row to
   be included in the result.

Returns:
  rowAccessPolicy: The created row access policy defined in
  google3/google/cloud/bigquery/v2/row_access_policy.proto;l=235;rcl=642795091
	projectId	datasetIdtableIdpolicyIdrowAccessPolicyReferencefilterPredicater   )r   r   r   body)r   r   r   r   GetRowAccessPoliciesApiClientrowAccessPoliciesinsertexecuter   r   r   r   row_access_policys        /platform/bq/clients/client_row_access_policy.pycreate_row_access_policyr!      s    , (11'11%--&//	# *	 ,,.v$..$.."** 	   wy
    c                 2   UR                   UR                  UR                  UR                  S.UUS.nU R	                  5       R                  5       R                  UR                   UR                  UR                  UR                  US9R                  5       $ )a  Update a row access policy on the given table reference.

Arguments:
 bqclient: BigQuery client to use for the request.
 policy_reference: Reference to the row access policy to update.
 grantees: Users or groups that can access rows protected by the row access
   policy.
 filter_predicate: A SQL boolean expression that needs to be true for a row to
   be included in the result.

Returns:
  rowAccessPolicy: The updated row access policy defined in
  google3/google/cloud/bigquery/v2/row_access_policy.proto;l=235;rcl=642795091
r   r   )r   r   r   r   r   )r   r   r   r   r   r   updater   r   s        r    update_row_access_policyr%   ?   s    , (11'11%--&//	# *	 ,,.v$..$.."**#,,    wyr"   c                 >    [        X5      nSU;   a  [        X5        U$ )z5Get a row access policy on the given table reference.r   ) _get_row_access_policy_reference_set_row_access_policy_grantees)r   r   responses      r    get_row_access_policyr*   k   s#    
 .hI(8+#H7	/r"   returnc                     U R                  5       R                  5       R                  UR                  UR                  UR
                  UR                  S9R                  5       $ )zEReturns the RowAccessPolicyReference for the given row access policy.r   )r   r   getr   r   r   r   r   )r   r   s     r    r'   r'   w   sZ     ,,.
s$..$.."**#,,	   wy
r"   forcec                     U R                  5       R                  5       R                  UR                  UR                  UR
                  UR                  US9R                  5       $ )z8Delete a row access policy on the given table reference.)r   r   r   r   r.   )r   r   deleter   r   r   r   r   )r   r   r.   s      r    delete_row_access_policyr1      s]     ,,.v$..$.."**#,,   wyr"   table_referencez*bq_id_utils.ApiClientHelper.TableReference	page_size
page_tokenc                     U R                  5       R                  5       R                  UR                  UR                  UR
                  UUS9R                  5       $ )z8Lists row access policies for the given table reference.)r   r   r   pageSize	pageToken)r   r   listr   r   r   r   r   r2   r3   r4   s       r    _list_row_access_policiesr:      sW     ,,.t#--#--!))   wyr"   max_concurrent_iam_callsc                 Z    [        U UUUS9nSU;   a  US   nU H  n[        U US9  M     U$ )aL  Lists row access policies for the given table reference.

Arguments:
  bqclient: BigQuery client to use for the request.
  table_reference: Reference to the table.
  page_size: Number of results to return.
  page_token: Token to retrieve the next page of results.
  max_concurrent_iam_calls: Number of concurrent calls to getIAMPolicy.

Returns:
  A dict that contains entries:
    'rowAccessPolicies': a list of row access policies, with an additional
      'grantees' field that contains the row access policy grantees.
    'nextPageToken': nextPageToken for the next page, if present.
r9   r   )r   r   )r:   r(   )r   r2   r3   r4   r;   r)   row_access_policiesr   s           r    &list_row_access_policies_with_granteesr>      sP    , '%	( H$"#670%- 1
 
/r"   c                     [         R                  R                  R                  " S0 US   D6n[	        XS9n[        U5      nXAS'   g)z1Sets the grantees on the given Row Access Policy.r   )r   	referencer   N )r   ApiClientHelperRowAccessPolicyReferenceCreate get_row_access_policy_iam_policy/_get_grantees_from_row_access_policy_iam_policy)r   r   row_access_policy_ref
iam_policyr   s        r    r(   r(      sT    
 !!::AA 89 
 0* =ZH("*Jr"   c                     U R                  S5      nU(       d  / $ [        S U 5       S5      nU(       d  / $ UR                  S/ 5      $ )zAReturns the filtered data viewer members of the given IAM policy.bindingsc              3   \   #    U  H"  nUR                  S 5      [        :X  d  M  Uv   M$     g7f)roleN)r-   _FILTERED_DATA_VIEWER_ROLE).0bindings     r    	<genexpr>B_get_grantees_from_row_access_policy_iam_policy.<locals>.<genexpr>   s+      !g[[ $>> '!s   ,	,Nmembers)r-   next)rH   rJ   filtered_data_viewer_bindings      r    rF   rF      sR    ^^J'(	I!%!
 " 
&I	%	)	))R	88r"   r@   c                 D   [         R                  " U[         R                  R                  SS9  SUR                  < SUR
                  < SUR                  < SUR                  < 3nU R                  5       R                  5       R                  US9R                  5       $ )ac  Gets IAM policy for the given row access policy resource.

Arguments:
  bqclient: BigQuery client to use for the request.
  reference: the RowAccessPolicyReference for the row access policy resource.

Returns:
  The IAM policy attached to the given row access policy resource.

Raises:
  BigqueryTypeError: if reference is not a RowAccessPolicyReference.
rE   )methodz	projects/z
/datasets/z/tables/z/rowAccessPolicies/)resource)r   	typecheckrB   rC   r   r   r   r   GetIAMPolicyApiClientr   getIamPolicyr   )r   r@   formatted_resources      r    rE   rE      s      !!::/ 










  $$&|/|0wy	r"   N)F)   )__doc__
__future__r   r   r   typingr   r   r   google.api_corer	   clientsr
   utilsr   rM   BigqueryClientstrr!   r%   r*   r'   boolr1   intr:   r>   r(   rF   PolicyrE   rA   r"   r    <module>rh      s   8 &  % " "   #  A (,,(L( 3i( 	(V),,)L) 3i) 	)X	,,	L	,,L 
#s(^* ,,L (,,A  	
 
#tCy.4 %&#,,#A# # 	#
 "# 
#tCy.#L+,,+ 9(#,,#E# 	ZZ#r"   