
    	                        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  ej                  ej                   j"                  ej                   j$                         G d
 dej&                               Zy)zSet the IAM policy for a key.    )absolute_import)division)unicode_literals)base)iam)iam_util)flags)resource_argsc                   &    e Zd ZdZed        Zd Zy)SetIamPolicya  Set the IAM policy for a key.

  Sets the IAM policy for the given key as defined in a JSON or YAML file.

  See https://cloud.google.com/iam/docs/managing-policies for details of
  the policy file format and contents.

  ## EXAMPLES
  The following command will read am IAM policy defined in a JSON file
  'policy.json' and set it for the key `frodo` with the keyring
  `fellowship` and location `global`:

    $ {command} frodo policy.json --keyring=fellowship --location=global
  c                 X    t        j                  | dd       | j                  dd       y )NTkeypolicy_filez%JSON or YAML file with the IAM policy)help)r
   AddKmsKeyResourceArgForKMSadd_argument)parsers    &lib/surface/kms/keys/set_iam_policy.pyArgszSetIamPolicy.Args1   s.    ,,VT5A
 .H J    c                 (   t        j                         }t        j                  |j                  |j
                        \  }}t        j                  |      }t        j                  |||      }t        j                  |j                         d       |S )Nr   )cloudkms_baseGetMessagesModuler   ParseYamlOrJsonPolicyFiler   Policyr	   ParseCryptoKeyNamer   SetCryptoKeyIamPolicyLogSetIamPolicyName)selfargsmessagespolicyupdate_maskcrypto_key_refresults          r   RunzSetIamPolicy.Run7   sy    ..0H"<<T=M=M=E__NFK --d3N&&~v{KF^002E:Mr   N)__name__
__module____qualname____doc__staticmethodr   r'    r   r   r   r      s"    $ J J
	r   r   N)r+   
__future__r   r   r   googlecloudsdk.api_lib.cloudkmsr   r   r   googlecloudsdk.calliopegooglecloudsdk.command_lib.iamr   googlecloudsdk.command_lib.kmsr	   r
   ReleaseTracksReleaseTrackBETAGACommandr   r-   r   r   <module>r8      sl    $ &  ' A / ( 3 0 8 D%%**D,=,=,@,@A"4<< " B"r   