
    x'                     d   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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\\RA                  S5      -   r!Sr"Sr#S\"-   \#-   r$\" \!\$5      r%\" \\#5      r&\" \\"5      r' " S S\5      r(g)z<Implementation of website configuration command for buckets.    )absolute_import)print_function)division)unicode_literalsN)encoding)metrics)Command)CommandArgument)ApiSelector)CommandException)NO_URLS_MATCHED_TARGET)CreateHelpText)storage_v1_messages)NO_MAX)GcloudStorageFlag)GcloudStorageMapzR
  gsutil web set [-m <main_page_suffix>] [-e <error_page>] gs://<bucket_name>...
z%
  gsutil web get gs://<bucket_name>

a  
<B>SET</B>
  The ``gsutil web set`` command allows you to configure or disable the website
  configuration on your buckets. The ``set`` sub-command has the following
  options (omit both options to unset the configuration):

<B>SET OPTIONS</B>
  -m <index.html>      Specifies the object name to serve when a bucket
                       listing is requested via a custom domain.

  -e <404.html>        Specifies the error page to serve when a request is made
                       for a non-existent object via a custom domain

a4  
<B>GET</B>
  The ``gsutil web get`` command retrieves the web semantics configuration for
  a bucket and displays a JSON representation of the configuration.

  In Google Cloud Storage, this would look like the following:

    {
      "notFoundPage": "404.html",
      "mainPageSuffix": "index.html"
    }

ay  
  Cloud Storage allows you to configure a bucket to behave like a static
  website when the bucket is accessed through a `custom domain
  <https://cloud.google.com/storage/docs/request-endpoints#custom-domains>`_.
  For example, if you set a ``main_page_suffix``, a subsequent GET bucket
  request through a custom domain serves the specified "main" page instead of
  performing the usual bucket listing. Similarly, if you set an ``error_page``,
  a subsequent GET object request through a custom domain for a non-existent
  object serves the specified error page instead of the standard Cloud Storage
  error.

  Requests to a bucket through other `endpoints
  <https://cloud.google.com/storage/docs/request-endpoints>`_ are unaffected
  by the bucket's website configuration.

  See `Static website examples and tips
  <https://cloud.google.com/storage/docs/static-website>`_ for additional
  examples and information.

  Notes:

  1. Because the main page is only served when a bucket listing request is made
     via a custom domain endpoint, you can continue to use ``gsutil ls`` as you
     normally would for bucket listing.

  2. The main_page_suffix applies to each subdirectory of the bucket. For
     example, with the main_page_suffix configured to be index.html, a GET
     request for ``http://www.example.com`` retrieves
     ``http://www.example.com/index.html`` but shows ``http://www.example.com`` as
     the URL to the requester, and a GET request for
     ``http://www.example.com/photos`` retrieves
     ``http://www.example.com/photos/index.html`` but shows ``http://www.example.com/photos``
     as the URL to the requester.

  3. There is just one 404.html page. For example, a GET request for
     ``http://www.example.com/photos/missing`` retrieves
     ``http://www.example.com/404.html``, not
     ``http://www.example.com/photos/404.html``.

  The web command has two sub-commands:
c                   V  ^  \ rS rSrSr\R                  " SSS/\S\SSSS	\	R                  \	R                  /\	R                  \R                  " 5       /\R                  " S	5      /S
.S9r\R                   " SSS/SS\\\S.S9r\" S\" / SQ0 SS900 S9rU 4S jrS rS rS rSrU =r$ )
WebCommand}   z%Implementation of gsutil web command.web	setwebcfg	getwebcfg   zm:e:F   )setget)command_name_aliases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_helpz(Set a website configuration for a bucket)r   r   )	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_textr   )storagebucketsdescribezk--format=gsutiljson[key=website_config,empty=' has no website configuration.',empty_prefix_key=storage_url]T)gcloud_commandflag_mapsupports_output_translationr3   r4   c           
      L  > U R                   S   S:X  ar  [        S[        / SQ[        S5      [        S5      S.S900 S9nSU R                   ;   d4  S	U R                   ;   d$  UR                  S   =R                  S
S/-  sl        UnO[        R
                  n[        TU ]  U5      $ )Nr   r   )r0   r1   updatez--web-error-pagez--web-main-page-suffix)-e-mr6   r9   r:   z--clear-web-error-pagez--clear-web-main-page-suffix)argsr   r   r3   r   gcloud_storage_mapsuperget_gcloud_storage_args)selfset_command_mapr<   	__class__s      %platform/gsutil/gslib/commands/web.pyr>   "WebCommand.get_gcloud_storage_args   s    yy|u("& !22D E 12J K 	 o  dii4499#4&&u-<<$&DA
 	
< +%887*+=>>    c                 N   U R                  U R                  S   S/S9u  pUR                  S:X  aB  [        R                  R                  U R                  R                  UUR                  S95        gUR                  (       a  UR                  R                  (       d  UR                  R                  (       aJ  [        R                  R                  [        [        R                  " UR                  5      5      S-   5        g[        R                  R                  SU-  5        g)z(Gets website configuration for a bucket.r   websitebucket_fieldss3)providerr   z!%s has no website configuration.
)GetSingleBucketUrlFromArgr;   schemesysstdoutwrite
gsutil_apiXmlPassThroughGetWebsiterF   mainPageSuffixnotFoundPagestrr   MessageToJson)r?   
bucket_urlbucket_metadatas      rB   _GetWebWebCommand._GetWeb   s    "&"@"@		!YK #A #1J D 	jj
//
2
2:<F<M<M 3 OP  
	 	 o&=&=&L&L&5&=&=&J&J

&&'>'>?@4G	I
  	

=
JKrD   c           	      >   SnSnU R                   (       a)  U R                    H  u  p4US:X  a  UnM  US:X  d  M  UnM     U R                  n[        R                  R	                  XS9nSnU H  nU R                  US/S9n	U	 Hr  n
U
R                  nSnU R                  R                  S	U
5        [        R                  " US
9nU R                  R                  UR                  UUR                  S/S9  Mt     M     U(       d  [        [        [        U5      -  5      eg)z(Sets website configuration for a bucket.Nr:   r9   )rR   rS   FidrG   Tz&Setting website configuration on %s...)rF   )rJ   fieldsr   )sub_optsr;   apitools_messagesBucketWebsiteValueGetBucketUrlIterFromArgstorage_urlloggerinforP   PatchBucketbucket_namerL   r   r   list)r?   main_page_suffix
error_pageoaurl_argsrF   some_matchedurl_strbucket_iterblrurlrW   s                rB   _SetWebWebCommand._SetWeb   s   J}}--$!9
$Y*	   yyH&&33' 4 BG
 L000Ok#ooA3G+227C##COO$3-0ZZ,06 	$ 	3   3d8nDEErD   c                 ,   U R                   R                  S5      nU R                  SS9  US:X  a  U R                  nO1US:X  a  U R                  nO[        SU< SU R                  < S35      e[        R                  " U/U R                  S	9  U" 5       $ )
z(Command entry point for the web command.r   T)
check_argsr   r   zInvalid subcommand "z
" for the z  command.
See "gsutil help web".)subcommandsr]   )
r;   popParseSubOptsrX   rr   r   command_namer   LogCommandParamsr]   )r?   action_subcommandfuncs      rB   
RunCommandWebCommand.RunCommand  s    		a(&E!\\d	e	#\\d(94;L;LNO O *;)<&*mm56MrD    )__name__
__module____qualname____firstlineno____doc__r	   CreateCommandSpec	_SYNOPSISr   r   XMLJSONr
   %MakeZeroOrMoreCloudBucketURLsArgumentMakeNCloudBucketURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT_get_help_text_set_help_text	help_specr   r<   r>   rX   rr   r}   __static_attributes____classcell__)rA   s   @rB   r   r   }   s    - **'5!oo{'7'78 %%!GGIJ!>>qAB,$ $k2G#
) (
" .2	 $?:& D rD   r   ))r   
__future__r   r   r   r   rM   apitools.base.pyr   gslibr   gslib.commandr	   gslib.command_argumentr
   gslib.cs_api_mapr   gslib.exceptionr   r   gslib.help_providerr   "gslib.third_party.storage_apitoolsr   r^   gslib.utils.constantsr   gslib.utils.shim_utilr   r   _SET_SYNOPSIS_GET_SYNOPSISlstripr   _SET_DESCRIPTION_GET_DESCRIPTION_DESCRIPTIONr   r   r   r   r   rD   rB   <module>r      s    C & %  ' 
 %  ! 2 ( , 2 . W ( 3 2 M0066	  (P Q(P *Q(*T %Y= /?@/?@W WrD   