
                         V   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 e	j                   e	j                  e	j                   j"                  e	j                   j$                  e	j                   j&                         G d
 de	j(                                      Zy)z!'logging buckets create' command.    )absolute_import)division)unicode_literals)util)arg_parsers)base)log)
console_ioc                   ,    e Zd ZdZed        Zd Zd Zy)Createa  Create a bucket.

  After creating a bucket, use a log sink to route logs into the bucket.

  ## EXAMPLES

  To create a bucket 'my-bucket' in location 'global', run:

    $ {command} my-bucket --location=global --description="my custom bucket"

  To create a bucket with extended retention, run:

    $ {command} my-bucket --location=global --retention-days=365

  To create a bucket in cloud region 'us-central1', run:

    $ {command} my-bucket --location=us-central1

  To create a bucket with custom index of 'jsonPayload.foo', run:

    $ {command} my-bucket
      --index=fieldPath=jsonPayload.foo,type=INDEX_TYPE_STRING

  To create a bucket with custom CMEK, run:

    $ {command} my-bucket --location=us-central1
      --cmek-kms-key-name=CMEK_KMS_KEY_NAME

  To asynchronously create a bucket enrolled into Log Analytics, run:

    $ {command} my-bucket --location=global --async --enable-analytics
  c           	         | j                  dd       | j                  dd       | j                  ddt        j                         d	       | j                  d
t        t        j                  dd             | j                  ddt        j
                  t        t        j                  dddg      dd       | j                  dd       | j                  dddt        j                  dd             t        j                  j                  |        t        j                  | dd        t        j                         j                  |        y)!z Register flags for this command.	BUCKET_IDzID of the bucket to create.)helpz--descriptionz%A textual description for the bucket.z--restricted-fieldszComma-separated list of field paths that require permission checks in this bucket. The following fields and their children are eligible: textPayload, jsonPayload, protoPayload, httpRequest, labels, sourceLocation.RESTRICTED_FIELD)r   typemetavarz--retention-daysziThe period logs will be retained, after which logs will automatically be deleted. The default is 30 days.zThis is not available.
)defaultuniverse_help)r   r   z--indexappend)	fieldPathr   r   r   )specrequired_keyszKEY=VALUE, ...a?  Specify an index to be added to the log bucket. This flag can be repeated. The ``fieldPath'' and ``type'' attributes are required. For example:  --index=fieldPath=jsonPayload.foo,type=INDEX_TYPE_STRING. The following keys are accepted:

*fieldPath*::: The LogEntry field path to index. For example: jsonPayload.request.status. Paths are limited to 800 characters and can include only letters, digits, underscores, hyphens, and periods.

*type*::: The type of data in this index. For example: INDEX_TYPE_STRING Supported types are INDEX_TYPE_STRING and INDEX_TYPE_INTEGER. 

 )actionr   r   r   z--cmek-kms-key-namez7A valid `kms_key_name` will enable CMEK for the bucket.z--enable-analytics
store_trueNzmWhether to opt the bucket into Log Analytics. Once opted in, the bucket cannot be opted out of Log Analytics.)r   r   r   TzcLocation in which to create the bucket. Once the bucket is created, the location cannot be changed.)add_argumentr   ArgListintUniverseHelpTextArgDictstrr   IndexTypeToEnumr   
ASYNC_FLAGAddToParserAddBucketLocationArg
GetTagsArg)parsers    %lib/surface/logging/buckets/create.pyArgszCreate.ArgsB   sv    *GH
E  G
   ""   ))E 5
  
    ,, '/1 !(  *0 F  H ))D 5
	   	OO'	*+ 	OO!!&)    c                    i }|j                  d      r|j                  |d<   |j                  d      r|j                  |d<   |j                  d      r|j                  |d<   |j                  d      r|j                  |d<   |j                  d      r|j
                  |d	<   |j                  d
      rAt        j                  |t        j                         j                  j                        }||d
<   |j                  d      rJt        j                  dd       t        j                         j                  |j                        }||d<   |j                  rt        j                          j"                  j%                  t        j                         j'                  |j(                  t        j*                  t        j,                  |j.                        j1                         d|j2                         t        j                         j                  di |            }t5        j6                  |j8                  dd       |S t        j                          j"                  j;                  t        j                         j=                  |j(                  t        j*                  t        j,                  |j.                        j1                         d|j2                         t        j                         j                  di |            S )Nretention_daysretentionDaysdescriptionrestricted_fieldsrestrictedFieldsindexindexConfigsenable_analyticsanalyticsEnabledtagscmek_kms_key_namez1CMEK cannot be disabled on a bucket once enabled.T)cancel_on_no)
kmsKeyNamecmekSettings	locations)bucketIdparent	logBucketbucket)is_async )IsSpecifiedr+   r-   r.   r0   r2   r   GetTagsFromArgsGetMessages	LogBucket	TagsValuer
   PromptContinueCmekSettingsr5   async_	GetClientprojects_locations_bucketsCreateAsync1LoggingProjectsLocationsBucketsCreateAsyncRequestr   CreateResourceNameGetProjectResourceprojectRelativeNamelocationr	   CreatedResourcenamer   ,LoggingProjectsLocationsBucketsCreateRequest)selfargsbucket_datar4   cmek_settingsresults         r'   _RunzCreate._Run   s   K()%)%8%8k/"&#'#3#3k- +,(,(>(>k$% $(JJk.!*+(,(=(=k$%!!$(8(8(:(D(D(N(NOd k&+,
= &&(55++ 6 -m$1k.!{{~~::FF




N
N~~,,))$,,7DDF--
 5((*44C{C O 
f 
&++x$?m^^88??




I
I~~,,))$,,7DDF--
 5((*44C{C J 
 
r)   c                 $    | j                  |      S )zThis is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The created bucket.
    )rY   )rT   rU   s     r'   Runz
Create.Run   s     99T?r)   N)__name__
__module____qualname____doc__staticmethodr(   rY   r[   r?   r)   r'   r   r      s*    
B E* E*N3j
r)   r   N)r_   
__future__r   r   r   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   r   googlecloudsdk.corer	   googlecloudsdk.core.consoler
   UniverseCompatibleReleaseTracksReleaseTrackALPHABETAGACreateCommandr   r?   r)   r'   <module>rm      s    ( &  ' / / ( # 2 T..33T5F5F5I5IiT i ir)   