
                            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
dZe	j                   e	j                  e	j                  j                          G d de	j"                                      Zee_        y)z'logging views set_iam_policy' command.

Set the IAM policy for a logging view resource.

This command replaces the existing IAM policy for an logging view resource,
given a file encoded in JSON or YAML that contains the IAM policy.
    )absolute_import)division)unicode_literals)util)arg_parsers)base)iam_utilz+
        Set an IAM policy for a view.
    z
        To set the IAM policy using a json file 'my_policy.json' for the view `my-view` in `my-bucket` in the `global` location, run:

        $ {command} my-view /path/to/my_policy.json --bucket=my-bucket --location=global
    )DESCRIPTIONEXAMPLESc                   &    e Zd ZdZed        Zd Zy)SetIamPolicyzSet IAM policy for a view.c                     | j                  dd       t        j                  | d       t        j                  | dd       | j                  ddt	        j
                  dd	      d
       t        j                  |        y)z Register flags for this command.VIEW_IDz!ID of the view to set IAM policy.)helpzview to set IAM policyTz.Location of the bucket that contains the view.z--bucketz.+zmust be non-emptyz(ID of the bucket that contains the view.)requiredtyper   N)add_argumentr   AddParentArgsAddBucketLocationArgr   RegexpValidatorr	   AddArgForPolicyFile)parsers    +lib/surface/logging/views/set_iam_policy.pyArgszSetIamPolicy.Args1   s~     	(KLv78F ((0CD7	     (    c                    t        j                  t        j                  t        j                  |      d|j                        d|j                        }t        j
                         }t        j                  |j                  |j                        \  }}t        j                  ||      }t        j                  |d       |S )zThis is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The IAM policy.
    bucketsviewszlogging view)r   CreateResourceNameGetBucketLocationFromArgsbucketr   GetMessagesr	   ParseYamlOrJsonPolicyFilepolicy_filePolicyr   LogSetIamPolicy)selfargsviewmessagespolicy_resultss          r   RunzSetIamPolicy.RunA   s     ""**40)T[[	
 	D !H22(//IFA f-GT>2Nr   N)__name__
__module____qualname____doc__staticmethodr   r.    r   r   r   r   ,   s     #) )r   r   N)r2   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   r   googlecloudsdk.command_lib.iamr	   DETAILED_HELPUniverseCompatibleReleaseTracksReleaseTrackGACommandr   detailed_helpr4   r   r   <module>r@      s    '  ' / / ( 3		 D%%(()*4<< * * *Z + r   