
                            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  \R                  \R                   " \R"                  R$                  5       " S
 S\R&                  5      5       5       rg)z/'logging views add_iam_policy_binding' command.    )absolute_import)division)unicode_literals)util)
exceptions)arg_parsers)base)iam_utilc                   `    \ rS rSrSrSS0r\S 5       r\R                  " S5      S 5       r
Srg	)
AddIamPolicyBinding   z%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                     U R                  SSS9  [        R                  " U S5        [        R                  " U SS5        U R                  SS[        R
                  " SS	5      S
S9  [        R                  " U SS9  g)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ArgsAddIamPolicyBinding.Args2   s     F   	vBCF ((0CD7	   **6F    z-Status code: {status_code}. {status_message}.c           	         [         R                  " [         R                  " [         R                  " U5      SUR                  5      SUR                  5      n[         R
                  " 5       n[         R                  " U5      n[        R                  " U5      n[        R                  " UR                  UR                  UUR                  UR                  US9  [         R                  " X$5      n[        R                  " US5        U$ )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   RunAddIamPolicyBinding.RunD   s     ""**40)T[[	
 	D !Ht$F44T:I//%--'}}{{YY -GT>2Nr    N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   gcloud_exception CatchHTTPErrorRaiseHTTPExceptionr8   __static_attributes__r:   r   r   r   r      sP     .  -  G G" 445r   r   N)r?   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   googlecloudsdk.api_lib.utilr   rB   googlecloudsdk.callioper   r	   googlecloudsdk.command_lib.iamr
   UniverseCompatibleReleaseTracksReleaseTrackGACommandr   r:   r   r   <module>rO      sk    6 '  ' / F / ( 3 D%%(()F$,, F * Fr   