
                            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 ej                   ej                   ej"                  j$                         G d
 dej&                                      Zy)z/'logging views add_iam_policy_binding' command.    )absolute_import)division)unicode_literals)util)
exceptions)arg_parsers)base)iam_utilc                   X    e Zd ZdZddiZed        Z ej                  d      d        Z	y)AddIamPolicyBindingz%Add IAM policy binding to a log view.EXAMPLESa|            To add an IAM policy binding for the role 'roles/my-role'
          for the user 'my-user@gmail.com' on my-view, run:

            $ {command} my-view --member='user:my-user@gmail.com' --role='roles/my-role' --bucket=my-bucket --location=global


          To add a binding with a condition, run:

            $ {command} my-view --member='user:my-user@gmail.com' --role='roles/my-role' --bucket=my-bucket --location=global --condition=expression=[expression],title=[title],description=[description]

          See https://cloud.google.com/iam/docs/managing-policies for details about IAM policies and member types.
          c                    | j                  dd       t        j                  | d       t        j                  | dd       | j                  ddt	        j
                  dd	      d
       t        j                  | d       y)z Register flags for this command.VIEW_IDz,ID of the view that contains the IAM policy.)helpz!view that contains the 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   )add_conditionN)add_argumentr   AddParentArgsAddBucketLocationArgr   RegexpValidatorr
   AddArgsForAddIamPolicyBinding)parsers    3lib/surface/logging/views/add_iam_policy_binding.pyArgszAddIamPolicyBinding.Args2   s     F   	vBCF ((0CD7	   **6F    z-Status code: {status_code}. {status_message}.c                    t        j                  t        j                  t        j                  |      d|j                        d|j                        }t        j
                         }t        j                  |      }t        j                  |      }t        j                  |j                  |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 updated policy.
    bucketsviews)binding_message_typecondition_message_typepolicymemberrole	conditionzlogging view)r   CreateResourceNameGetBucketLocationFromArgsbucketr   GetMessagesGetIamPolicyr
   ValidateAndExtractCondition"AddBindingToIamPolicyWithConditionBindingExprr#   r$   SetIamPolicyLogSetIamPolicy)selfargsviewmessagesr"   r%   resultss          r   RunzAddIamPolicyBinding.RunD   s     ""**40)T[[	
 	D !Ht$F44T:I//%--'}}{{YY f-GT>2Nr   N)
__name__
__module____qualname____doc__detailed_helpstaticmethodr   gcloud_exception CatchHTTPErrorRaiseHTTPExceptionr6    r   r   r   r      sS     .  -  G G" 5445r   r   N)r:   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   googlecloudsdk.api_lib.utilr   r=   googlecloudsdk.callioper   r	   googlecloudsdk.command_lib.iamr
   UniverseCompatibleReleaseTracksReleaseTrackGACommandr   r?   r   r   <module>rJ      sm    6 '  ' / F / ( 3 D%%(()F$,, F * Fr   