
                         2   d 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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dlmZ  ej,                  ej.                  j0                  ej.                  j2                         G d dej4                               Zy)z?Command to deauthorize a service agent from managing resources.    )absolute_import)division)unicode_literals)projects_api)lake)storage_util)apis)
exceptions)base)resource_args)utilc                   X    e Zd ZdZddiZed        Z ej                  d      d        Z	y)DeauthorizeLakezDeauthorize a service agent from managing resources.

  The service agent for the primary project will have its IAM role revoked from
  a secondary project, a Cloud Storage bucket, or a BigQuery dataset.
  EXAMPLESa            To deauthorize the service agent in project `test-project` from
          managing resources in the project `test-project2`, run:

            $ {command} --project=test-project --project-resource=test-project2

          To deauthorize the service agent in project `test-project` from
          managing the Cloud Storage bucket `dataplex-storage-bucket`, run:

            $ {command} --project=test-project --storage-bucket-resource=dataplex-storage-bucket

          To deauthorize the service agent in project `test-project` from
          managing the BigQuery dataset `test-dataset` in project
          `test-project2`, run:

            $ {command} --project=test-project --bigquery-dataset-resource=test-dataset --secondary-project=test-project2
          c                    t        j                  | d       | j                  ddd      }|j                  dd       |j                  dd	       |j                  d
      }|j                  ddd       |j                  ddd       y )Nz+to revoke a role from the service agent in.Tz@The resource for which the service agent's role will be revoked.)mutexrequiredhelpz--storage-bucket-resourcezXThe identifier of the Cloud Storage bucket that the service agent will no longer manage.)r   z--project-resourcezVThe identifier of the project whose resources the service agent will no longer manage.z(Fields to identify the BigQuery dataset.z--bigquery-dataset-resourcezTThe identifier of the BigQuery dataset that the service agent will no longer manage.)r   r   z--secondary-projectzDThe identifier of the project where the BigQuery dataset is located.)r   AddProjectArg	add_groupadd_argument)parser
data_groupdataset_groups      )lib/surface/dataplex/lakes/deauthorize.pyArgszDeauthorizeLake.Args:   s    5 !!O " J
 #k   &   ((7 ) M %g  
 	      z-Status code: {status_code}. {status_message}.c                    |j                   j                  j                         }dt        t	        j
                  |j                              z   dz   }|j                  d      r7t        j                  t        j                  |j                        d|z   d      S |j                  d      rt        j                  dd      j                  |j                   |j"                  	      }t        j$                  dd      j&                  j)                  |
      }t        j*                  ||d       t        j$                  dd      j&                  j-                  t        j                  dd      j/                  |j                   |j"                  |            S |j                  d      r7t1        j2                  t	        j4                  |j6                        d|z   d      S y )Nzservice-z(@gcp-sa-dataplex.iam.gserviceaccount.comstorage_bucket_resourcezserviceAccount:zroles/dataplex.serviceAgentbigquery_dataset_resourcebigqueryv2)	datasetId	projectId)request)r#   r$   datasetproject_resource)CONCEPTSprojectParsestrproject_utilGetProjectNumber
projectsIdIsSpecifiedr   $RemoveServiceAccountFromBucketPolicyr   BucketReferencer   r	   GetMessagesModuleBigqueryDatasetsGetRequestr    secondary_projectGetClientInstancedatasetsGet%RemoveServiceAccountFromDatasetPolicyPatchBigqueryDatasetsPatchRequestr   RemoveIamPolicyBindingParseProjectr'   )selfargslake_refservice_accountget_dataset_requestr&   s         r   RunzDeauthorizeLake.Runa   s    }}$$**,H 3%%	!$" "$NOO 1266

&
&t'C'C
D
o
-/LN N 34 22
d6666.. 7 0  &&
d$HSS1DS%E 
00/1NP##J5>>DD

 
 T
2
O
O66.. P    
 *+00

#
#D$9$9
:
o
-/LN N ,r   N)
__name__
__module____qualname____doc__detailed_helpstaticmethodr   gcloud_exception CatchHTTPErrorRaiseHTTPExceptionrB    r   r   r   r      sT      -( $ $L 54457N7Nr   r   N)rF   
__future__r   r   r   +googlecloudsdk.api_lib.cloudresourcemanagerr   googlecloudsdk.api_lib.dataplexr   googlecloudsdk.api_lib.storager   googlecloudsdk.api_lib.utilr	   r
   rI   googlecloudsdk.callioper   #googlecloudsdk.command_lib.dataplexr   #googlecloudsdk.command_lib.projectsr   r,   ReleaseTracksReleaseTrackALPHAGACommandr   rK   r   r   <module>rY      sy    F &  ' D 0 7 , F ( = D D%%++T->->-A-AB]Ndll ]N C]Nr   