
                         >   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSK	Jr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  \R.                  " \R0                  R2                  \R0                  R4                  5       " S S\R6                  5      5       rg)z?Command to authorize a service agent to manage other resources.    )absolute_import)division)unicode_literals)projects_api)lake)storage_api)storage_util)apis)
exceptions)base)resource_args)utilc                   `    \ rS rSrSrSS0r\S 5       r\R                  " S5      S 5       r
Srg	)
	Authorize!   zAuthorize a service agent to manage resources.

The service agent for the primary project will be granted an IAM role on a
secondary project, a Cloud Storage bucket, or a BigQuery dataset.
EXAMPLESa            To authorize the service agent in project `test-project` to manage
          resources in the project `test-project2`, run:

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

          To authorize the service agent in project `test-project` to manage the
          Cloud Storage bucket `dataplex-storage-bucket`, run:

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

          To authorize the service agent in project `test-project` to manage the
          BigQuery dataset `test-dataset` in project `test-project2`, run:

            $ {command} --project=test-project --bigquery-dataset-resource=test-dataset --secondary-project=test-project2
          c                     [         R                  " U S5        U R                  SSSS9nUR                  SSS9  UR                  SS	S9  UR                  S
S9nUR                  SSSS9  UR                  SSSS9  g )Nz(to grant a role to the service agent in.Tz;The resource on which to grant a role to the service agent.)mutexrequiredhelpz--storage-bucket-resourcezNThe identifier of the Cloud Storage bucket that the service agent will manage.)r   z--project-resourcezLThe identifier of the project whose resources the service agent will manage.z(Fields to identify the BigQuery dataset.z--bigquery-dataset-resourcezJThe identifier of the BigQuery dataset that the service agent will 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/authorize.pyArgsAuthorize.Args<   s    : !!J " J
 #a      ((7 ) M %	   	      z-Status code: {status_code}. {status_message}.c                 P   UR                   R                  R                  5       nS[        [        R
                  " UR                  5      5      -   S-   nUR                  S5      (       aG  [        R                  " 5       R                  [        R                  " UR                  5      SU-   S5      $ UR                  S5      (       Ga  [        R                  " SS5      R!                  UR"                  UR$                  S	9n[        R&                  " SS5      R(                  R+                  US
9n[,        R.                  " [        R                  " SS5      R0                  R2                  XSS5        [        R&                  " SS5      R(                  R5                  [        R                  " SS5      R7                  UR"                  UR$                  US95      $ UR                  S5      (       a9  [8        R                  " [        R:                  " UR<                  5      SU-   S5      $ g )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   StorageClientAddIamPolicyBindingr	   BucketReferencer"   r
   GetMessagesModuleBigqueryDatasetsGetRequestr#   secondary_projectGetClientInstancedatasetsGetr    AddServiceAccountToDatasetPolicyDatasetAccessValueListEntryPatchBigqueryDatasetsPatchRequestr   ParseProjectr*   )selfargsproject_refservice_accountget_dataset_requestr)   s         r   RunAuthorize.Rune   s    --''--/K 3%%k&<&<=$ 23O 122&&(<<

&
&t'C'C
D
o
-/LN N 344 22
d6666.. 7 0  &&
d$HSS1DS%E 
++

 
 T
2
:
:
O
O
$AC ##J5>>DD

 
 T
2
O
O66.. P     *++--

#
#D$9$9
:
o
-/LN N ,r     N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   gcloud_exception CatchHTTPErrorRaiseHTTPExceptionrG   __static_attributes__rI   r    r   r   r   !   sQ      -& & &P 4457N7Nr    r   N)rN   
__future__r   r   r   +googlecloudsdk.api_lib.cloudresourcemanagerr   googlecloudsdk.api_lib.dataplexr   googlecloudsdk.api_lib.storager   r	   googlecloudsdk.api_lib.utilr
   r   rQ   googlecloudsdk.callioper   #googlecloudsdk.command_lib.dataplexr   #googlecloudsdk.command_lib.projectsr   r/   ReleaseTracksReleaseTrackALPHAGACommandr   rI   r    r   <module>ra      s|    F '  ' D 0 6 7 , F ( = D D%%++T->->-A-ABcN cN CcNr    