
    !                        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\\R=                  S5      -   rSr Sr!S\ -   \!-   r"\" \\"5      r#\" \\!5      r$\" \\ 5      r%S\RL                  " 5       -   S-   S-   r' " S S\	5      r(g)zBImplementation of requesterpays configuration command for buckets.    )absolute_import)print_function)division)unicode_literals)metrics)Command)CommandArgument)ApiSelector)CommandException)NO_URLS_MATCHED_TARGET)CreateHelpText)storage_v1_messages)NO_MAX)GcloudStorageMap)	shim_utilz;
  gsutil requesterpays set (on|off) gs://<bucket_name>...
z2
  gsutil requesterpays get gs://<bucket_name>...

z
<B>SET</B>
  The "set" sub-command requires an additional sub-command, either "on" or
  "off", which, respectively, will enable or disable Requester Pays for the
  specified bucket.

z
<B>GET</B>
  The "get" sub-command gets the Requester Pays configuration for a
  bucket and displays whether or not it is enabled.
a%  
  The `Requester Pays
  <https://cloud.google.com/storage/docs/requester-pays>`_ feature enables you
  to configure a Google Cloud Storage bucket so that the requester
  pays all costs related to accessing the bucket and its objects.

  The gsutil requesterpays command has two sub-commands:
z)--format=value[separator=": "](name.sub("z", "gs://"),z,requester_pays.yesno("Enabled", "Disabled"))c                   h   \ rS rSrSr\R                  " S\S\SSSS\	R                  /\	R                  \" SSS	/S
9\R                  " 5       /\R                  " 5       /S.S9r\R                  " S/ SS\\\S.S9r\" \" SSS\/0 SS9\" \" / SQ0 S9\" / SQ0 S9S.0 S9S.0 S9rS rS rS rS rSrg) RequesterPaysCommandM   z/Implementation of gsutil requesterpays command.requesterpays    Fmodeonoff)choices)setget)
usage_synopsismin_argsmax_argssupported_sub_argsfile_url_okprovider_url_okurls_start_arggs_api_supportgs_default_apiargparse_argumentscommand_helpz8Enable or disable requester pays for one or more buckets)r   r   )	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_textstoragebucketslistT)gcloud_commandflag_mapsupports_output_translation)r0   r1   updatez--requester-pays)r3   r4   )r0   r1   r6   z--no-requester-paysr   r   c                     U R                   (       d  U R                  5         U R                   S   R                  5       S:X  a  gg)Nr   r   r      )args$RaiseWrongNumberOfArgumentsExceptionlower)selfs    /platform/gsutil/gslib/commands/requesterpays.py_CalculateUrlsStartArg+RequesterPaysCommand._CalculateUrlsStartArg   s4    99
//1yy|u$    c           	         U R                   S   R                  5       nUS;  a  [        SU R                  -  5      eU R                   SS nU(       d  U R	                  5         SnU H  nU R                  US/S9nU H  nUR                  nS	n[        R                  " [        R                  R                  5       S
9nUS:X  a.  U R                  R                  SU5        S	UR                  l        O-U R                  R                  SU5        SUR                  l        U R                  R                  UR                   UUR"                  S/S9  M     M     U(       d  [        [$        ['        U5      -  5      eg)z.Gets requesterpays configuration for a bucket.r   r7   z,Argument to "%s set" must be either <on|off>r9   NFidbucket_fieldsT)billingr   z!Enabling requester pays for %s...z"Disabling requester pays for %s...)providerfields)r:   r<   r   command_namer;   GetBucketUrlIterFromArgstorage_urlapitools_messagesBucketBillingValueloggerinforF   requesterPays
gsutil_apiPatchBucketbucket_nameschemer   r2   )	r=   requesterpays_argurl_argssome_matchedurl_strbucket_iterblrurlbucket_metadatas	            r>   _SetRequesterPays&RequesterPaysCommand._SetRequesterPays   sX   		!**,-K"//1 2 2yy}H
//1 L000Ok#oo+22%,,99;=$
++

>
D26/
!
!
/
++

?
E27/
!
!
/##COO$3-0ZZ,06 	$ 	3  " 3d8nDEE rA   c                    U R                   nSnU H  nU R                  US/S9nU H  nSnUR                  R                  (       aN  UR                  R                  R                  (       a)  [        SUR                  R                  S5      -  5        Mn  [        SUR                  R                  S5      -  5        M     M     U(       d  [        [        [        U5      -  5      eg)	z9Gets requesterpays configuration for one or more buckets.FrF   rD   Tz%s: Enabled/z%s: DisabledN)r:   rJ   root_objectrF   rQ   print
url_stringrstripr   r   r2   )r=   rW   rX   rY   rZ   r[   s         r>   _GetRequesterPays&RequesterPaysCommand._GetRequesterPays   s    yyH L00@I{ 1 Lk#??""s'>'>'L'L
 5 5c ::
;
!6!6s!;;
<   3d8nDEE rA   c           	         U R                   R                  S5      nUS:X  a"  U R                  n[        R                  " U/S9  OwUS:X  aE  U R
                  nU R                   S   R                  5       nUS;   a  [        R                  " X/S9  O,[        SU< SU R                  < SU R                  < S	35      eU" 5         g)
z2Command entry point for the requesterpays command.r   r   )subcommandsr   r7   zInvalid subcommand "z
" for the z command.
See "gsutil help z".)	r:   poprf   r   LogCommandParamsr^   r<   r   rI   )r=   action_subcommandfuncrV   s       r>   
RunCommandRequesterPaysCommand.RunCommand   s    		a(E!##d,=+>?	e	###d))A,,,.	m	+  *>	@  d//1B1BDE E 	FrA    N)__name__
__module____qualname____firstlineno____doc__r   CreateCommandSpec	_SYNOPSISr   r
   JSONr	   %MakeZeroOrMoreCloudBucketURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT_get_help_text_set_help_text	help_specr   _GCLOUD_FORMAT_STRINGgcloud_storage_mapr?   r^   rf   rn   __static_attributes__rp   rA   r>   r   r   M   s;   7 ** 

 !%% ftUm<CCE "GGIK,. 
D#) ( F4I" .2  +.  (* +.  (*"( +!D G$LFBF&rA   r   N))ru   
__future__r   r   r   r   gslibr   gslib.commandr   gslib.command_argumentr	   gslib.cs_api_mapr
   gslib.exceptionr   r   gslib.help_providerr   "gslib.third_party.storage_apitoolsr   rL   gslib.utils.constantsr   gslib.utils.shim_utilr   gslib.utilsr   _SET_SYNOPSIS_GET_SYNOPSISlstriprw   _SET_DESCRIPTION_GET_DESCRIPTION_DESCRIPTIONr|   r}   r~   get_format_flag_caretr   r   rp   rA   r>   <module>r      s    I & %  '  ! 2 ( , 2 . W ( 2 ! M0066	    ** %Y= /?@/?@I"88:;=KLGH 
\7 \rA   