
    P                        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&                         G d
 dej(                                      Zy)z=Implementation of create command for Insights dataset config.    )
exceptions)insights_api)base)flags)create_update_util)log_util)log)
propertiesc                   0    e Zd ZdZdddZed        Zd Zy)Createz)Create a new dataset config for Insights.z8
       Create a new dataset config for Insights.
      aY  
      To create a dataset config with config name as "my_config" in location
      "us-central1" and project numbers "123456" and "456789" belonging to
      organization number "54321":

         $ {command} my_config --location=us-central1
         --source-projects=123456,456789 --organization=54321 --retention-period-days=1

      To create a dataset config that automatically adds new buckets into
      config:

         $ {command} my_config --location=us-central1
         --source-projects=123456,456789 --organization=54321
         --auto-add-new-buckets --retention-period-days=1
      )DESCRIPTIONEXAMPLESc                    | j                  dt        d       | j                  dt        ddd       | j                  d	t        d
ddgdd       | j                  ddd       t        j                  |        t        j
                  |        y )NDATASET_CONFIG_NAMEz#Provide human readable config name.)typehelpz--organizationTSOURCE_ORG_NUMBERz'Provide the source organization number.)r   requiredmetavarr   z
--identityIDENTITY_TYPEIDENTITY_TYPE_PER_CONFIGIDENTITY_TYPE_PER_PROJECTz7The type of service account used in the dataset config.)r   r   choicesdefaultr   z--auto-add-new-buckets
store_truezbAutomatically include any new buckets created if they satisfy criteria defined in config settings.)actionr   )add_argumentstrintr    add_dataset_config_location_flag&add_dataset_config_create_update_flags)parsers    6lib/surface/storage/insights/dataset_configs/create.pyArgszCreate.Args6   s    
2  
 #6   +-HI*F    4	   
**62	008    c                 @   d }|j                   |j                   }nD|j                  8t        j                  |j                  t        j                  j
                        }d }|j                  |j                  }nD|j                  8t        j                  |j                  t        j                  j                        }t        j                         }	 |j                  |j                  |j                  t        j                  j                   j"                  j%                         |j&                  |||j(                  |j*                  |j,                  |j.                  |j0                  |j2                  |j4                  |j6                  |j8                  |j:                  |j<                  |j>                        }tA        jB                  d|j                  |jD                         y # tF        jH                  $ r! tJ        jL                  jO                  d        w xY w)N)dataset_config_namelocationdestination_projectorganization_scopesource_projects_listsource_folders_listorganization_numberinclude_buckets_name_list!include_buckets_prefix_regex_listexclude_buckets_name_list!exclude_buckets_prefix_regex_listinclude_source_locationsexclude_source_locationsauto_add_new_bucketsretention_periodactivity_data_retention_periodidentity_typedescriptionr   zWe caught an exception while trying to create the dataset-configuration.
Please check that the flags are set with valid values. For example, config name must start with an alphanumeric value and only contain '_' as a special character)(source_projectssource_projects_filer   get_source_configs_list
ConfigTypePROJECTSsource_folderssource_folders_fileFOLDERSr   InsightsApicreate_dataset_configr   r(   r
   VALUEScoreprojectGetenable_organization_scopeorganizationinclude_bucket_namesinclude_bucket_prefix_regexesexclude_bucket_namesexclude_bucket_prefix_regexesr2   r3   r4   retention_period_days#activity_data_retention_period_daysidentityr8   r   /dataset_config_operation_started_and_status_lognameapitools_exceptionsHttpBadRequestErrorr	   statusPrint)selfargsr+   r,   
api_clientdataset_config_operations         r#   Runz
Create.RunY   s   '!11		"	"	./GG

#
#%7%B%B%K%K & //		!	!	-.FF

"
"$6$A$A$I$I ))+J!+!A!A"66==(//44<<@@B!;;31"//$($=$=,0,N,N$($=$=,0,N,N#'#@#@#'#@#@#8855)-)Q)Q&&% "B "( >>
D,,.F.K.K 22 	jjL s   DG) )4HN)__name__
__module____qualname____doc__detailed_helpstaticmethodr$   rZ    r%   r#   r   r      s2     2

	-*  9  9D3r%   r   N)r^   apitools.base.pyr   rR   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   "googlecloudsdk.command_lib.storager   ;googlecloudsdk.command_lib.storage.insights.dataset_configsr   r   googlecloudsdk.corer	   r
   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHACommandr   ra   r%   r#   <module>rm      sl     D > 7 ( 4 Z P # * D%%++,nT\\ n - nr%   