
    !                        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dlmZ ddlmZ dZdZeej=                  d      z   ZdZ dZ!de z   e!z   Z" eee"      Z# eee!      Z$ eee       Z%d ejL                         z   dz   dz   Z' G d de	      Z(y)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                      e Zd ZdZ ej
                  dededdddej                  gej                   e
dddg	       e
j                         g e
j                         gd
      Z ej                  dg ddeeed      Z e edddegi d       e eg di        eg di       di       di       Zd Zd Zd Zd Zy)RequesterPaysCommandz/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)r/   r0   updatez--requester-pays)r2   r3   )r/   r0   r5   z--no-requester-paysr   r   c                 ~    | j                   s| j                          | j                   d   j                         dk(  ryy)Nr   r   r      )args$RaiseWrongNumberOfArgumentsExceptionlower)selfs    /platform/gsutil/gslib/commands/requesterpays.py_CalculateUrlsStartArgz+RequesterPaysCommand._CalculateUrlsStartArg   s4    99
//1yy|u$    c                    | j                   d   j                         }|dvrt        d| j                  z        | j                   dd }|s| j	                          d}|D ]  }| j                  |dg      }|D ]  }|j                  }d	}t        j                  t        j                  j                         
      }|dk(  r.| j                  j                  d|       d	|j                  _        n-| j                  j                  d|       d|j                  _        | j                  j                  |j                   ||j"                  dg         |st        t$        t'        |      z        y)z.Gets requesterpays configuration for a bucket.r   r6   z,Argument to "%s set" must be either <on|off>r8   NFidbucket_fieldsT)billingr   z!Enabling requester pays for %s...z"Disabling requester pays for %s...)providerfields)r9   r;   r   command_namer:   GetBucketUrlIterFromArgstorage_urlapitools_messagesBucketBillingValueloggerinforD   requesterPays
gsutil_apiPatchBucketbucket_nameschemer   r1   )	r<   requesterpays_argurl_argssome_matchedurl_strbucket_iterblrurlbucket_metadatas	            r=   _SetRequesterPaysz&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 r?   c                    | j                   }d}|D ]  }| j                  |dg      }|D ]  }d}|j                  j                  rH|j                  j                  j                  r(t        d|j                  j                  d      z         ct        d|j                  j                  d      z           |st        t        t        |      z        y)	z9Gets requesterpays configuration for one or more buckets.FrD   rB   Tz%s: Enabled/z%s: DisabledN)r9   rH   root_objectrD   rO   print
url_stringrstripr   r   r1   )r<   rU   rV   rW   rX   rY   s         r=   _GetRequesterPaysz&RequesterPaysCommand._GetRequesterPays   s    yyH L00@I{ 1 Lk#??""s'>'>'L'L
 5 5c ::
;
!6!6s!;;
<   3d8nDEE r?   c           	         | j                   j                  d      }|dk(  r$| j                  }t        j                  |g       nt|dk(  rF| j
                  }| j                   d   j                         }|dv rBt        j                  ||g       n)t        d|d| j                  d| j                  d	       |        y)
z2Command entry point for the requesterpays command.r   r   )subcommandsr   r6   zInvalid subcommand "z
" for the z command.
See "gsutil help z".)	r9   poprc   r   LogCommandParamsr\   r;   r   rG   )r<   action_subcommandfuncrT   s       r=   
RunCommandzRequesterPaysCommand.RunCommand   s    		a(E!##d,=+>?	e	###d))A,,,.	m	+  *,=>	@  d//1B1BDE E 	Fr?   N)__name__
__module____qualname____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\   rc   rj    r?   r=   r   r   M   sD   7 +** 

 !%% ftUm<CoCCE H/GGIK,. g
D#) ( F4I" .2  +.  (* +.  (*"( +!D G$LFBF&r?   r   N))rn   
__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   rJ   gslib.utils.constantsr   gslib.utils.shim_utilr   gslib.utilsr   _SET_SYNOPSIS_GET_SYNOPSISlstriprp   _SET_DESCRIPTION_GET_DESCRIPTION_DESCRIPTIONru   rv   rw   get_format_flag_caretry   r   r{   r?   r=   <module>r      s    I & %  '  ! 2 ( , 2 . W ( 2 ! M0066	    ** %Y= /?@/?@I888:;=KLGH 
\7 \r?   