
    ,"                        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SKJr  SSKJ r   Sr!Sr"Sr#Sr$\"\!RK                  S5      -   S-   r&SSRO                  \#\$/5      -   S-   r(\" \&\(5      r)\" \!\#5      r*\" \"\$5      r+ " S S\
5      r,g)z=Implementation of cors configuration command for GCS buckets.    )absolute_import)print_function)division)unicode_literalsN)metrics)Command)CommandArgument)ApiSelector)CommandException)NO_URLS_MATCHED_TARGET)CreateHelpText)StorageUrlFromString)UrlsAreForSingleProvider)storage_v1_messages)NO_MAX)GcloudStorageMap)CorsTranslation)REMOVE_CORS_CONFIGz&
  gsutil cors get gs://<bucket_name>
z:
  gsutil cors set <cors-json-file> gs://<bucket_name>...
z
<B>GET</B>
  Gets the CORS configuration for a single bucket. The output from
  ``cors get`` can be redirected into a file, edited and then updated using
  ``cors set``.
z
<B>SET</B>
  Sets the CORS configuration for one or more buckets. The ``cors-json-file``
  specified on the command line should be a path to a local file containing
  a JSON-formatted CORS configuration, such as the example described above.

z

a  
  Gets or sets the Cross-Origin Resource Sharing (CORS) configuration on one or
  more buckets. This command is supported for buckets only, not objects. An
  example CORS JSON file looks like the following:

    [
      {
        "origin": ["http://origin1.example.com"],
        "responseHeader": ["Content-Type"],
        "method": ["GET"],
        "maxAgeSeconds": 3600
      }
    ]

  The above CORS configuration explicitly allows cross-origin GET requests from
  http://origin1.example.com and may include the Content-Type response header.
  The preflight request may be cached for 1 hour.

  Note that requests to the authenticated browser download endpoint ``storage.cloud.google.com``
  do not allow CORS requests. For more information about supported endpoints for CORS, see
  `Cloud Storage CORS support <https://cloud.google.com/storage/docs/cross-origin#server-side-support>`_.

  The following (empty) CORS JSON file removes any CORS configuration for a
  bucket:

    []

  The cors command has two sub-commands:
z
For more info about CORS generally, see https://www.w3.org/TR/cors/.
For more info about CORS in Cloud Storage, see the
`CORS concept page <https://cloud.google.com/storage/docs/cross-origin>`_.
c                   x   \ rS rSrSr\R                  " SSS/\S\SSSS	\	R                  \	R                  /\	R                  \R                  " S	5      \R                  " 5       /\R                  " S	5      /S
.S9r\R"                  " S/ SQSS\\\S.S9r\" \" / SQ0 S9\" / SQ0 S9S.0 S9rS rS rS rS rSrg)CorsCommandg   z&Implementation of gsutil cors command.corsgetcorssetcors    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)r   r   zcross-origincommand_helpz7Get or set a CORS configuration 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describeze--format=gsutiljson[key=cors_config,empty=' has no CORS configuration.',empty_prefix_key=storage_url])gcloud_commandflag_map)r3   r4   updatez--cors-filec                     U R                   (       d  U R                  5         U R                   S   R                  5       S:X  a  gg)Nr   r   r   r   )args$RaiseWrongNumberOfArgumentsExceptionlower)selfs    &platform/gsutil/gslib/commands/cors.py_CalculateUrlsStartArg"CorsCommand._CalculateUrlsStartArg   s4    99
//1yy|u$    c           	      t   U R                   S   nU R                   SS n[        U5      (       d  [        SU R                  -  5      e[	        US5      nUR                  5       nUR                  5         U R                  R                  [        US   5      R                  5      U l        SnU H  nU R                  US/S9nU H  nUR                  n	S	nU R                  R                  S
U5        U	R                  S:X  a'  U R                  R!                  UU	U	R                  S9  Md  ["        R$                  " U5      n
U
(       d  [&        n
[(        R*                  " U
S9nU R                  R-                  U	R.                  UU	R                  S/S9  M     M     U(       d  [        [0        [3        U5      -  5      eg)z9Sets CORS configuration on a Google Cloud Storage bucket.r   r   Nz,"%s" command spanning providers not allowed.rFidbucket_fieldsTzSetting CORS on %s...s3provider)r   )rI   fields)r:   r   r   command_nameopenreadclose
gsutil_apiGetApiSelectorr   schemeapiGetBucketUrlIterFromArgstorage_urlloggerinfoXmlPassThroughSetCorsr   JsonCorsToMessageEntriesr   apitools_messagesBucketPatchBucketbucket_namer   list)r=   cors_argurl_args	cors_filecors_txtsome_matchedurl_strbucket_iterblrurlr   bucket_metadatas               r>   _SetCorsCorsCommand._SetCors   s   yy|Hyy}H#H--K!../ 0 0 Xs#I~~HOO--Xa[)002DH L000Ok#oo0#6::
//
/
/039< 0 E !99(C$%D-44$?/
//
%
%coo&5/2zz.2V & 5  & 3d8nDEErA   c                    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>  [        R                  R                  [        R                  " UR                  5      5        g[        R                  R                  SU-  5        g)z:Gets CORS configuration for a Google Cloud Storage bucket.r   r   rE   rG   rH   z%s has no CORS configuration.
)GetSingleBucketUrlFromArgr:   rQ   sysstdoutwriterO   XmlPassThroughGetCorsr   r   MessageEntriesToJson)r=   
bucket_urlrg   s      r>   _GetCorsCorsCommand._GetCors   s    "&"@"@		!VH #A #.J D 	jj
//
/
/
9C9J9J 0 LM  
		

001E1EF	H  	

:ZGHrA   c                     U R                   R                  S5      n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/S9  U" 5       $ )z)Command entry point for the cors command.r   r    r   zInvalid subcommand "z
" for the z! command.
See "gsutil help cors".)subcommands)r:   poprr   rh   r   rK   r   LogCommandParams)r=   action_subcommandfuncs      r>   
RunCommandCorsCommand.RunCommand   sr    		a(E!]]d	e	#]]d):D<M<MOP P *;)<=6MrA   )rR   N)__name__
__module____qualname____firstlineno____doc__r   CreateCommandSpec	_SYNOPSISr   r
   XMLJSONr	   MakeNFileURLsArgument%MakeZeroOrMoreCloudBucketURLsArgumentMakeNCloudBucketURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT_get_help_text_set_help_text	help_specr   gcloud_storage_mapr?   rh   rr   rz   __static_attributes__ rA   r>   r   r   g   s   . **%y1!oo{'7'78 %% 33A6CCE ">>qAC	,( 
 
C#)" ( "
  " 	$ ',(T"rA   r   )-r   
__future__r   r   r   r   rl   gslibr   gslib.commandr   gslib.command_argumentr	   gslib.cs_api_mapr
   gslib.exceptionr   r   gslib.help_providerr   gslib.storage_urlr   r   "gslib.third_party.storage_apitoolsr   rY   gslib.utils.constantsr   gslib.utils.shim_utilr   gslib.utils.translation_helperr   r   _GET_SYNOPSIS_SET_SYNOPSIS_GET_DESCRIPTION_SET_DESCRIPTIONlstripr   join_DESCRIPTIONr   r   r   r   r   rA   r>   <module>r      s    D & %  ' 
  ! 2 ( , 2 . 2 6 W ( 2 : =   M0066?	8 ii!#34596899 D %Y= /?@/?@N' NrA   