
    G                         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,                   G d de
j.                               Zy)z1Implementation of buckets set-iam-policy command.    )absolute_import)division)unicode_literals)	cloud_api)metadata_field_converters)base)iam_util)errors_util)flags)iam_command_util)storage_url)wildcard_iterator)set_iam_policy_taskc              #      K   | D ]X  }t        j                  |t        j                  j                        D ]$  }t        j                  |j                  |       & Z yw)z+Generates SetIamPolicyTask's for execution.)fields_scopeN)r   get_wildcard_iteratorr   FieldsScopeSHORTr   SetBucketIamPolicyTaskr   )url_stringspolicy
url_stringresources       -lib/surface/storage/buckets/set_iam_policy.py_set_iam_policy_task_iteratorr   !   sT     j%;;!6!6!<!<>66


 >  s   AA!c                   0    e Zd ZdZdddZed        Zd Zy)SetIamPolicyz Set the IAM policy for a bucket.z
      Set the IAM policy for a bucket. For more information, see [Cloud
      Identity and Access
      Management](https://cloud.google.com/storage/docs/access-control/iam).
      z
      To set the IAM policy in POLICY-FILE on BUCKET:

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

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

        $ {command} gs://b* POLICY-FILE
      )DESCRIPTIONEXAMPLESc                     | j                  ddd       | j                  ddd       t        j                  |        t        j                  |        y )	Nurls+zCURLs for buckets to apply the IAM policy to. Can include wildcards.)nargshelpz-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$   )add_argumentr	   AddArgForPolicyFiler   add_continue_on_error_flag)parsers    r   ArgszSetIamPolicy.ArgsB   s^    
"  #
 "  #   (	$$V,    c                 d   |j                   D ]7  }t        j                  |      }t        j                  |j
                  |       9 t        j                  |j                  |j                        }t        j                  t        |j                   |      |j                        \  }}|| _        |S )N)custom_etag)r!   r   storage_url_from_stringr
   raise_error_if_not_gcs_bucketcommand_pathr   process_iam_filepolicy_fileetagr   execute_set_iam_task_iteratorr   continue_on_error	exit_code)selfargsr   urlr   r5   outputs          r   RunzSetIamPolicy.RunR   s    ii
//
;c//0A0A3G   '77dii1F(FF%dii8 Iv DNMr*   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr)   r:    r*   r   r   r   +   s/    (

-& - -r*   r   N)r>   
__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   UniverseCompatibleCommandr   rA   r*   r   <module>rK      s[    8 &  ' 4 M ( 3 : 4 ? : @ H 24<< 2 2r*   