
    A                         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dlmZ e	j"                   G d de	j$                               Zy)z:Implementation of service agent command for Cloud Storage.    )absolute_import)division)unicode_literalsN)api_factory)base)requests)storage_url)log)
propertiesc                   0    e Zd ZdZdddZed        Zd Zy)ServiceAgentz^Manage a project's Cloud Storage service agent, which is used to perform Cloud KMS operations.z
      *{command}* displays the Cloud Storage service agent, which is used to
      perform Cloud KMS operations against your a default or supplied project.
      If the project does not yet have a service agent, *{command}* creates one.

      aj  
      To show the service agent for your default project:

        $ {command}

      To show the service account for ``my-project'':

        $ {command} --project=my-project

      To authorize your default project to use a Cloud KMS key:

        $ {command} --authorize-cmek=projects/key-project/locations/us-east1/keyRings/key-ring/cryptoKeys/my-key
      )DESCRIPTIONEXAMPLESc                 P    | j                  dt        j                  d             y )Nz--authorize-cmeka              Adds appropriate encrypt/decrypt permissions to the specified Cloud
            KMS key. This allows the Cloud Storage service agent to write and
            read Cloud KMS-encrypted objects in buckets associated with the
            service agent's project.)help)add_argumenttextwrapdedent)parsers    $lib/surface/storage/service_agent.pyArgszServiceAgent.Args;   s)    
__ ( )  *    c                    t        j                  t        j                  j                        }|j                         }|j                  rt        j                  |j                  d|z          t        j                  dj                  t        j                  j                  j                  j!                         |j                               y t        j                  |       y )NzserviceAccount:z9Authorized project {} to encrypt and decrypt with key:
{})r   get_apir	   ProviderPrefixGCSget_service_agentauthorize_cmekr   AddCryptoKeyPermissionr
   Printformatr   VALUEScoreprojectGet)selfargsapiservice_agents       r   RunzServiceAgent.RunE   s    


k88<<
=C))+M%%d&9&9&7-&GI	ii
F
M
M$$,,002D4G4GIJ 
iir   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   r*    r   r   r   r      s/    f

-0 * *r   r   )r.   
__future__r   r   r   r   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   $googlecloudsdk.command_lib.artifactsr   "googlecloudsdk.command_lib.storager	   googlecloudsdk.corer
   r   UniverseCompatibleCommandr   r1   r   r   <module>r:      sN    A &  '  6 ( 9 : # * 04<< 0 0r   