
                            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 ddlmZ ddlmZ ddlmZ ddlmZ d Ze
j,                  e
j.                   G d de
j0                                      Zy)z1Implementation of objects set-iam-policy command.    )absolute_import)division)unicode_literals)	cloud_api)metadata_field_converters)base)iam_util)errors_util)flags)iam_command_util)name_expansion)storage_url)set_iam_policy_taskc              #   >  K   |rt         j                  j                  }nt         j                  j                  }t        j                  | t
        j                  j                  ||      D ].  }t        j                  |j                  j                  |       0 yw)z+Generates SetIamPolicyTask's for execution.)fields_scopeobject_staterecursion_requestedN)r   RecursionSettingYESNO_WITH_WARNINGNameExpansionIteratorr   FieldsScopeSHORTr   SetObjectIamPolicyTaskresourcer   )url_stringsrecurser   policyr   name_expansion_results         -lib/surface/storage/objects/set_iam_policy.py_set_iam_policy_task_iteratorr!   !   s     (99==(99II-CC((..-	  
4
4&&22F  s   BBc                   0    e Zd ZdZdddZed        Zd Zy)SetIamPolicyz Set access policy for an object.z
      *{command}* behaves similarly to *{parent_command} set-object-acl*, but
      uses the IAM policy binding syntax.
      a/  
      To set the access policy for OBJECT on BUCKET to the policy defined in
      POLICY-FILE run:

        $ {command} gs://BUCKET/OBJECT POLICY-FILE

      To set the IAM policy in POLICY-FILE on all objects in all buckets
      beginning with "b":

        $ {command} -r gs://b* POLICY-FILE
      )DESCRIPTIONEXAMPLESc                     | j                  ddd       t        j                  |        | j                  ddd       | j                  d	d
d       | j                  ddddd       t        j                  |        y )Nurls+z;The URLs for objects whose access policy is being replaced.)nargshelpz--all-versions
store_truezKUpdate the IAM policies of all versions of an object in a versioned bucket.)actionr*   z-ez--etagzCustom etag to set on IAM policy. API will reject etags that do not match this value, making it useful as a precondition during concurrent operations.)r*   z-Rz-rz--recursivezjRecursively set the IAM policies of the contents of any directories that match the source path expression.)add_argumentr	   AddArgForPolicyFiler   add_continue_on_error_flag)parsers    r    ArgszSetIamPolicy.ArgsL   s    
J  L   (
  
 "  # >  ? 
$$V,    c           	         |j                   D ]c  }t        j                  |      }|j                  s t	        j
                  |j                  |       t	        j                  |j                  |       e t        j                  |j                  |j                        }t        j                  t        |j                   |j                  t        j                   |      |      |j"                        \  }}|| _        |S )N)custom_etag)r'   r   storage_url_from_string	recursiver
   raise_error_if_not_cloud_objectcommand_pathraise_error_if_not_gcsr   process_iam_filepolicy_fileetagr   execute_set_iam_task_iteratorr!   r   get_object_state_from_flagscontinue_on_error	exit_code)selfargs
url_stringurlr   r@   outputs          r    RunzSetIamPolicy.Rung   s    ii
//
;c^^33D4E4EsK(():):C@	   '77dii1F(FF%IINN--d3		
 	Iv DNMr2   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr1   rF    r2   r    r#   r#   3   s1     )



-( - -4r2   r#   N)rJ   
__future__r   r   r   googlecloudsdk.api_lib.storager   'googlecloudsdk.api_lib.storage.gcs_jsonr   googlecloudsdk.callioper   googlecloudsdk.command_lib.iamr	   "googlecloudsdk.command_lib.storager
   r   r   r   r   (googlecloudsdk.command_lib.storage.tasksr   r!   HiddenUniverseCompatibleCommandr#   rM   r2   r    <module>rX      sj    8 &  ' 4 M ( 3 : 4 ? = : H$ F4<< F  Fr2   