
                             d Z ddlmZ ddlmZ ddlmZ ddl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                    G d de	j"                               Zy)z7Implementation of create command for inventory reports.    )absolute_import)division)unicode_literalsN)insights_api)base)errors)flags)storage_url)logc                   0    e Zd ZdZdddZed        Zd Zy)Createz%Create a new inventory report config.a  
       Create an inventory report config that defines how often
       inventory reports are generated, the metadata fields you want the reports
       to include, and a bucket/prefix in which to store the reports, also known
       as the destination.
      z
       To create an inventory report about "my-bucket" that will store report
       details in "report-bucket" with the prefix "save-path/".

         $ {command} gs://my-bucket --destination=gs://report-bucket/save-path/
      )DESCRIPTIONEXAMPLESc                 b    | j                  dt        d       t        j                  | d       y )Nsource_bucket_urlzNURL of the source bucket that will contain the inventory report configuration.)typehelpT)require_create_flags)add_argumentstrr	   add_inventory_reports_flags)parsers    8lib/surface/storage/insights/inventory_reports/create.pyArgszCreate.Args2   s2    
/  0
 
%%f4H    c                    t        j                  t        j                  |j                              }t	        |t         j
                        r|j                         s.t        j                  dj                  |j                              |j                  3t        j                  t        j                  |j                              }n,t        j
                  |j                  |j                  d      }|j                  |j                  }n\t        j                  j                  t        j                   j"                        t        j$                  d      z   j'                         }|j(                  |j(                  }n|t        j$                  d      z   }t+        j,                         j/                  |j                  |t1        |j2                        |||j4                  |j6                  |j8                  |j:                  |j<                  |j>                        }t@        jB                  jE                  dj                  |jF                               y )	NzcInvalid bucket URL: {}. Only bucket URLs are accepted for SOURCE_BUCKET_URL. Example: "gs://bucket"zinventory_reports/)schemebucket_nameresource_name   )daysim  )source_bucketdestination_urlmetadata_fields
start_dateend_date	frequencycsv_delimitercsv_separator
csv_headerparquetdisplay_namez Created report configuration: {})$r
   storage_url_from_stringadd_gcs_scheme_if_missingr   
isinstanceCloudUrl	is_bucketr   InvalidUrlErrorformatdestinationr   r   schedule_startsdatetimenowtimezoneutc	timedeltadateschedule_repeats_untilr   InsightsApicreate_inventory_reportlistr$   schedule_repeatsr(   r)   r*   r+   r,   r   statusPrintname)selfargsr"   r4   r%   r&   report_configs          r   Runz
Create.Run;   s   77--d.D.DEGM}k&:&:;##%"";;A6$$<&' '
 #77

/
/0@0@
ACk  ((%%#//,.k
 '''j%%))(*;*;*?*?@&&A./04  "".,,hh00c::h ,,.FF#//#T112''((((??&& G M JJ*11-2D2DEGr   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   rG    r   r   r   r      s2    -

- I I,Gr   r   )rK   
__future__r   r   r   r6   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   "googlecloudsdk.command_lib.storager   r	   r
   googlecloudsdk.corer   DefaultUniverseOnlyCommandr   rN   r   r   <module>rV      sS    > &  '  7 ( 5 4 : # GGT\\ GG GGr   