
    4                         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  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 rS rS rS rg)z+Utilities for storage surface IAM commands.    )absolute_import)division)unicode_literals)	cloud_api)gcs_iam_util)iam_util)errors)plurality_checkable_iterator)storage_url)wildcard_iterator)task)task_executor)task_graph_executor)task_status)	task_utilc                 p   [         R                  " U 5      (       d  [        R                  " U 5      $ [         R                  " U [
        R                  R                  S9n[        R                  " U5      nUR                  5       (       a  [        R                  " S5      e[        U5      S   R                  $ )zEGets cloud resource, allowing wildcards that match only one resource.)fields_scopez2get-iam-policy must match a single cloud resource.r   )r   contains_wildcardr   storage_url_from_stringget_wildcard_iteratorr   FieldsScopeSHORTr
   PluralityCheckableIterator	is_pluralr	   InvalidUrlErrorlist)
url_stringresource_iterator%plurality_checkable_resource_iterators      :lib/googlecloudsdk/command_lib/storage/iam_command_util.pyget_single_matching_urlr!   #   s    		,	,Z	8	8..z::'==y44::< #==>OP ( +4466

 
 <> >	3	4Q	7	C	CC    c           
         [         R                  " U 5      nUR                  5       (       dR  S[        R                  " [        U5      R                  5       R                  [        R                  R                  5      4$ [        R                  R                  5       n[        R                  " USU[         R"                  " [         R$                  R&                  SS9US9nUS4$ )a  Executes single or multiple set-IAM tasks with different handling.

Args:
  iterator (iter[set_iam_policy_task._SetIamPolicyTask]): Contains set IAM
    task(s) to execute.
  continue_on_error (bool): If multiple tasks in iterator, determines whether
    to continue executing after an error.

Returns:
  int: Status code. For multiple tasks, the task executor will return if
    any of the tasks failed.
  object|None: If executing a single task, the newly set IAM policy. This
    is useful for outputting to the terminal.
r   TN)increment_typemanifest_path)parallelizabletask_status_queueprogress_manager_argscontinue_on_error)r
   r   r   r   "get_first_matching_message_payloadnextexecutemessagesr   TopicSET_IAM_POLICYr   multiprocessing_contextQueuer   execute_tasksr   ProgressManagerArgsIncrementTypeINTEGER)iteratorr)   !plurality_checkable_task_iteratorr'   	exit_codes        r    execute_set_iam_task_iteratorr9   4   s      #==hG $ 
+	4	4	6	6 i::./779BB

!!# # # *AAGGI))')';;$22::$P)+) 
Dr"   c                    [         R                  " U 5      n[        R                  Ul        [         R
                  " UR                  R                  UR                  UU R                  U R                  U5        U" X5      R                  5       n[        R                  " UR                  [        R                   R"                  5      $ )a  Extracts new binding from args and applies to existing policy.

Args:
  args (argparse Args): Contains flags user ran command with.
  url (CloudUrl): URL of target resource, already validated for type.
  messages (object): Must contain IAM data types needed to create new policy.
  policy (object): Existing IAM policy on target to update.
  task_type (set_iam_policy_task._SetIamPolicyTask): The task instance to use
    to execute the iam binding change.

Returns:
  object: The updated IAM policy set in the cloud.
)r   ValidateAndExtractConditionr   IAM_POLICY_VERSIONversion"AddBindingToIamPolicyWithConditionPolicyBindingsValueListEntryExprmemberroler,   r   r*   r-   r   r.   r/   )argsurlr-   policy	task_type	conditiontask_outputs          r    add_iam_binding_to_resourcerJ   X   s     2248)22&.
--oo,,hmmV
kk499i) #&..0+		5	5k6J6J6:jj6O6O
Q Qr"   c                 d   [         R                  " U 5      n[        R                  Ul        [         R
                  " X R                  U R                  UU R                  5        U" X5      R                  5       n[        R                  " UR                  [        R                  R                  5      $ )a  Extracts binding from args and removes it from existing policy.

Args:
  args (argparse Args): Contains flags user ran command with.
  url (CloudUrl): URL of target resource, already validated for type.
  policy (object): Existing IAM policy on target to update.
  task_type (set_iam_policy_task._SetIamPolicyTask): The task instance to use
    to execute the iam binding change.

Returns:
  object: The updated IAM policy set in the cloud.
)r   r;   r   r<   r=   'RemoveBindingFromIamPolicyWithConditionrB   rC   allr,   r   r*   r-   r   r.   r/   )rD   rE   rF   rG   rH   rI   s         r     remove_iam_binding_from_resourcerN   r   s     2248)22&.
226;;3799i3788= #&..0+		5	5k6J6J6:jj6O6O
Q Qr"   N)__doc__
__future__r   r   r   googlecloudsdk.api_lib.storager   r   googlecloudsdk.command_lib.iamr   "googlecloudsdk.command_lib.storager	   r
   r   r   (googlecloudsdk.command_lib.storage.tasksr   r   r   r   r   r!   r9   rJ   rN    r"   r    <module>rV      sO    2 &  ' 4 7 3 5 K : @ 9 B H @ >D"!HQ4Qr"   