
    C                        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rSSKJ	r	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SK#J%r%  SSK#J&r&  SSK'J(r(  SRS                  \5      r*S\*-   SRS                  \S9-   r+\RX                  " S5      r-\RX                  " S5      r.Sr/\R`                  Rb                  r1\1Rd                  r2 " S  S!\5      r3g)"z@Implementation of mb command for creating cloud storage buckets.    )absolute_import)print_function)division)unicode_literalsN)AccessDeniedExceptionBadRequestException)Command)CommandArgument)VALID_RPO_VALUES)VALID_RPO_VALUES_STRING)ApiSelector)CommandException)InvalidUrlError)StorageUrlFromString)storage_v1_messages)NO_MAX)RetentionInSeconds)GcloudStorageFlag)GcloudStorageMap)InsistAscii)InsistOnOrOff)NormalizeStorageClass)ValidateCMEKz
  gsutil mb [-b (on|off)] [-c <class>] [-k <key>] [-l <location>] [-p <project>]
            [--autoclass] [--retention <time>] [--pap <setting>]
            [--placement <region1>,<region2>]
            [--rpo {}] gs://<bucket_name>...
z
<B>SYNOPSIS</B>
a  


<B>DESCRIPTION</B>
  Create one or more new buckets. Google Cloud Storage has a single namespace,
  so you are not allowed to create a bucket with a name already in use by
  another user. You can, however, carve out parts of the bucket name space
  corresponding to your company's domain name (see "gsutil help naming").

  If you don't specify a project ID or project number using the -p option, the
  buckets are created using the default project ID specified in your `gsutil
  configuration file <https://cloud.google.com/storage/docs/boto-gsutil>`_.

  The -l option specifies the location for the buckets. Once a bucket is created
  in a given location, it cannot be moved to a different location. Instead, you
  need to create a new bucket, move the data over, and then delete the original
  bucket.

<B>BUCKET STORAGE CLASSES</B>
  You can specify one of the `storage classes
  <https://cloud.google.com/storage/docs/storage-classes>`_ for a bucket
  with the -c option.

  Example:

    gsutil mb -c nearline gs://some-bucket

  See online documentation for
  `pricing <https://cloud.google.com/storage/pricing>`_ and
  `SLA <https://cloud.google.com/storage/sla>`_ details.

  If you don't specify a -c option, the bucket is created with the
  default storage class Standard Storage.

<B>BUCKET LOCATIONS</B>
  You can specify one of the `available locations
  <https://cloud.google.com/storage/docs/locations>`_ for a bucket
  with the -l option.

  Examples:

    gsutil mb -l asia gs://some-bucket

    gsutil mb -c standard -l us-east1 gs://some-bucket

  If you don't specify a -l option, the bucket is created in the default
  location (US).

<B>Retention Policy</B>
  You can specify retention period in one of the following formats:

  --retention <number>s
      Specifies retention period of <number> seconds for objects in this bucket.

  --retention <number>d
      Specifies retention period of <number> days for objects in this bucket.

  --retention <number>m
      Specifies retention period of <number> months for objects in this bucket.

  --retention <number>y
      Specifies retention period of <number> years for objects in this bucket.

  Examples:

    gsutil mb --retention 1y gs://some-bucket

    gsutil mb --retention 36m gs://some-bucket

  If you don't specify a --retention option, the bucket is created with no
  retention policy.

<B>OPTIONS</B>
  --autoclass            Enables the Autoclass feature that automatically
                         sets object storage classes.

  -b <on|off>            Specifies the uniform bucket-level access setting.
                         When "on", ACLs assigned to objects in the bucket are
                         not evaluated. Consequently, only IAM policies grant
                         access to objects in these buckets. Default is "off".

  -c class               Specifies the default storage class. Default is
                         ``Standard``. See `Available storage classes
                         <https://cloud.google.com/storage/docs/storage-classes#classes>`_
                         for a list of possible values.

  -k <key>               Set the default KMS key using the full path to the key,
                         which has the following form:
                         ``projects/[project-id]/locations/[location]/keyRings/[key-ring]/cryptoKeys/[my-key]``

  -l location            Can be any supported location. See
                         https://cloud.google.com/storage/docs/locations
                         for a discussion of this distinction. Default is US.
                         Locations are case insensitive.

  -p project             Specifies the project ID or project number to create
                         the bucket under.

  -s class               Same as -c.

  --retention time       Specifies the retention policy. Default is no retention
                         policy. This can only be set on gs:// buckets and
                         requires using the JSON API. For more details about
                         retention policy see "gsutil help retention"

  --pap setting          Specifies the public access prevention setting. Valid
                         values are "enforced" or "inherited". When
                         "enforced", objects in this bucket cannot be made
                         publicly accessible. Default is "inherited".

  --placement reg1,reg2  Two regions that form the custom dual-region.
                         Only regions within the same continent are or will ever
                         be valid. Invalid location pairs (such as
                         mixed-continent, or with unsupported regions)
                         will return an error.

  --rpo setting          Specifies the `replication setting
                         <https://cloud.google.com/storage/docs/availability-durability#cross-region-redundancy>`_.
                         This flag is not valid for single-region buckets,
                         and multi-region buckets only accept a value of
                         DEFAULT. Valid values for dual region buckets
                         are {rpo_values}. If unspecified, DEFAULT is applied
                         for dual-region and multi-region buckets.

)
rpo_valuesz.^[a-zA-Z0-9][a-zA-Z0-9\._-]{1,253}[a-zA-Z0-9]$z[-_a-z0-9]{64}z--retentionc                     ^  \ rS rSrSr\R                  " S/ SQ\S\S/ SQSSS	\	R                  \	R                  /\	R                  \R                  " 5       /S
9r\R                  " S/ SQSS\0 S9r\" / SQS\" S5      S\" SSS.5      S\" S5      S\" S5      S\" S5      S\" S5      S\" S5      S\" S SS!.5      S"\" S"5      \\" S#5      S$\" S%5      0S&9rU 4S' jrS( rS)rU =r$ )*	MbCommand   z$Implementation of gsutil mb command.mb)
makebucketcreatebucketmdmkdir   zb:c:l:p:s:k:)	autoclassz
retention=zpap=z
placement=zrpo=Fr   )command_name_aliasesusage_synopsismin_argsmax_argssupported_sub_argssupported_private_argsfile_url_okprovider_url_okurls_start_arggs_api_supportgs_default_apiargparse_arguments)r    r   r!   r"   locationdradrasreduced_availabilitydurable_reduced_availabilityrrreduced_redundancystandardzstorage classnearlinenlcommand_helpzMake buckets)	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_text)storagebucketscreate--autoclassz--enable-autoclass-bz--uniform-bucket-level-accessN)onoff-cz--default-storage-class-s-kz--default-encryption-key-lz
--location-pz	--project--papz--public-access-prevention)enforced	inherited--placementz--retention-period--rpoz--recovery-point-objective)gcloud_commandflag_mapc                   > SnU[        U R                  5      :  a;  U R                  U   S   [        :X  a  O US-  nU[        U R                  5      :  a  M;  U[        U R                  5      :  a:  [        [        [	        U R                  U   S   5      5      S-   4U R                  U'   [
        TU ]  [        R                  5      $ )Nr   r#   s)	lensub_opts_RETENTION_FLAGstrr   superget_gcloud_storage_argsr   gcloud_storage_map)selfretention_arg_idx	__class__s     $platform/gsutil/gslib/commands/mb.pyr\   !MbCommand.get_gcloud_storage_args  s    
c$--0
0	(	)!	,	?1 c$--0
0 3t}}-- 
 /@!A!!DE
F
L*Ndmm%& 7*9+G+GHH    c                 
   SnSnSnSnSnSnSnSnSn	/ n
U R                   (       Ga  U R                    GH  u  pUS:X  a  SnU
R                  U5        M!  US:X  a   Un[        U5        U
R                  U5        MG  US:X  a  UnMQ  US:X  a  [        US5        Xl        Mk  US	:X  d  US
:X  a  [        U5      nM  U[        :X  a  [        U5      nM  US:X  aL  UR                  5       n	U	[        ;  a  [        SR                  [        U5      5      eU
R                  U5        M  US:X  a%  [        US5        US:H  nU
R                  U5        GM  US:X  a  UnU
R                  U5        GM4  US:X  d  GM=  UR                  S5      n[        U5      S:w  a  [        SR                  U5      5      eU
R                  U5        GM     [         R"                  " UU	US9nU(       a"  [         R"                  R%                  US9Ul        U(       d  U(       aN  [)        5       Ul        UR*                  nU(       a  [-        5       Ul        X.R.                  l        U(       a  Xl        U(       a*  [         R"                  R5                  5       nX?l        Xl        U(       a,  [         R"                  R;                  5       nUUl        UUl        U R@                   GH  n[C        U5      nUb?  URD                  S:w  a  [        S5      e[         R"                  RG                  US9nUUl$        U
(       a`  U RJ                  RM                  URD                  5      [N        RP                  :w  a)  [        SR                  SRS                  U
5      5      5      eURU                  5       (       d  [        SU-  5      e[V        RY                  URZ                  5      (       a$  [\        R_                  URZ                  5      (       a  [a        SURZ                  -  5      eU Rb                  Re                  SU5         U RJ                  Rg                  URZ                  U R                  UURD                  S9  GM     g,! [h         aS  nURj                  nS U;   a;  US!-  nUS"U-  -  nU R                  (       a  US#U R                  -  -  n[        U5      ee SnAf[l         a  nURn                  S$:X  az  URj                  S%:X  aj  URD                  S:X  aZ  URZ                  nUURq                  S&5      S'-   S n[        S(RS                  [r        Rt                  " S)U< S*U< S+35      5      5      ee SnAff = f)-z'Command entry point for the mb command.FNrE   TrK   rL   rM   z/Invalid non-ASCII character found in project IDrI   rJ   rR   z9Invalid value for --rpo. Must be one of: {}, provided: {}rF   z,Only on and off values allowed for -b optionrG   rN   rQ   ,   zJPlease specify two regions separated by comma without space. Specified: {})r1   rpostorageClass)enabledgsz7Retention policy can only be specified for GCS buckets.)retentionPeriodzCThe {} option(s) can only be used for GCS Buckets with the JSON APIz, zIThe mb command requires a URL that specifies a bucket.
"%s" is not valid.zInvalid bucket name in URL "%s"zCreating %s...)
project_idmetadataproviderkeyz* To authorize, run:
  gsutil kms authorizez \
    -k %sz \
    -p %si  DotfulBucketNameNotUnderTld.r#   
z_Buckets with "." in the name must be valid DNS names. The bucket you are attempting to create (z8) is not a valid DNS name, because the final component (z:) is not currently a valid part of the top-level DNS tree.r   );rX   appendr   r   rl   r   rY   r   stripr   r   formatr   r   splitrW   apitools_messagesBucketAutoclassValuer$   IamConfigurationValueiamConfigurationBucketPolicyOnlyValuebucketPolicyOnlyri   publicAccessPreventionEncryptionValuedefaultKmsKeyName
encryptionCustomPlacementConfigValuedataLocationscustomPlacementConfigargsr   schemeRetentionPolicyValueretentionPolicy
gsutil_apiGetApiSelectorr   JSONjoinIsBucketBUCKET_NAME_REmatchbucket_nameTOO_LONG_DNS_NAME_COMPsearchr   loggerinfoCreateBucketr   reasonr   statusrfindtextwrapwrap)r^   r$   bucket_policy_onlykms_keyr1   storage_classseconds
placementspublic_access_preventionrg   json_only_flags_in_commandoabucket_metadata
iam_configr   placement_configbucket_url_str
bucket_urlretention_policyemessager   
final_comps                           ra   
RunCommandMbCommand.RunCommand  s   IGHMGJ#
C!#}}}--$!)
$
+
+A
.$Y'
w

$
+
+A
.$Y($Y
aJ
K/$Y!t)/2-/!&q)''\	#(("  &'> BD D %
+
+A
.$Y
I
J !T	

$
+
+A
.'\%&
"
$
+
+A
.-wws|*_!"!!', , %
+
+A
.M  P (..36<IKO "3":":"I"I #J #o5)>)@o&"33j	&;&=
#.@##+	!,D)$++;;=j%,"#- *11LLN'1$.>o+))'7j		$  "0 1 1-44II# J %*:'	#(F(F


) + 0 0)1  <<BF#'99-G#H=JK 	K   ""  =?I J K 	K"":#9#9::
 
'
'
(>(>
?
??(445 6 	6 kk'4#$$Z%;%;04.=.8.?.? 	% 	A9 $@ A # ((G B
B'
%/
/'oo'$//99G )
)
  HHO,I I%"..+";#4#4S#9A#=#>?* mm 4?
LM"N O O s&   #:Q##
U-AR;;UBUU)rl   )__name__
__module____qualname____firstlineno____doc__r	   CreateCommandSpec	_SYNOPSISr   r   XMLr   r
   %MakeZeroOrMoreCloudBucketURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT	help_specr   r   rY   r]   r\   r   __static_attributes____classcell__)r`   s   @ra   r   r      sO   , **
H' !oo{'7'78 %%

?
?
A,( " *#-)2 (5
 45
7!   9:
 9:
 :;
-
,
:#!  .
 45
 <=9 DIN Nrc   r   )4r   
__future__r   r   r   r   rer   gslib.cloud_apir   r   gslib.commandr	   gslib.command_argumentr
   gslib.commands.rpor   r   gslib.cs_api_mapr   gslib.exceptionr   r   gslib.storage_urlr   "gslib.third_party.storage_apitoolsr   rw   gslib.utils.constantsr   gslib.utils.retention_utilr   gslib.utils.shim_utilr   r   gslib.utils.text_utilr   r   r   gslib.utils.encryption_helperr   ru   r   r   compiler   r   rY   rx   rz   r|   r    rc   ra   <module>r      s    G & %  ' 	  F ! 2 / 6 ( , + 2 W ( 9 3 2 - / 7 6
 F"# 
|x F-F.}~/ B MN$56 )00FF -CC n nrc   