
    _                         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 ej                   ej                  ej                  j                          G d	 d
ej"                                      Zy)z=Implementation of update command for Insights dataset config.    )insights_api)base)flags)create_update_util)log_util)resource_args)
console_ioc                   B    e Zd ZdZdddZed        Zd Zd Zd Z	d	 Z
y
)Updatez&Updates a dataset config for Insights.z3
      Update a dataset config for Insights.
      a1  

      To update the description for a dataset config "my_config" in
      location "us-central1":

          $ {command} my_config --location=us-central1 --description="a user provided description"

      To update the same dataset config with fully specified name:

          $ {command} projects/foo/locations/us-central1/datasetConfigs/my_config

      To update the retention period days for the dataset config "my_config" in
      location "us-central1":

          $ {command} my_config --location=us-central1
          --retention-period-days=20
      )DESCRIPTIONEXAMPLESc                     | j                  dddgd       t        j                  | d       t        j                  | d       y )	Nz--auto-add-new-bucketstruefalsezbAutomatically include any new buckets created if they satisfy criteria defined in config settings.)choiceshelpz	to updateT)	is_update)add_argumentr   add_dataset_config_resource_argr   &add_dataset_config_create_update_flags)parsers    6lib/surface/storage/insights/dataset_configs/update.pyArgszUpdate.Args7   sG    
 !4	   11&+F	004H    c                     |j                   |j                   S |j                  8t        j                  |j                  t        j                  j
                        S y N)source_projectssource_projects_filer   get_source_configs_list
ConfigTypePROJECTSselfargss     r   _get_source_projects_listz Update._get_source_projects_listE   sV    '!!!		"	"	.77

#
#%7%B%B%K%K  r   c                     |j                   |j                   S |j                  8t        j                  |j                  t        j                  j
                        S y r   )source_folderssource_folders_filer   r   r    FOLDERSr"   s     r   _get_source_folders_listzUpdate._get_source_folders_listN   sV    &   		!	!	-77

"
"$6$A$A$I$I  r   c                 \    |j                    |j                   dk(  ry|j                   dk(  ryy )Nr   Tr   F)auto_add_new_bucketsr"   s     r   _get_auto_add_new_bucketsz Update._get_auto_add_new_bucketsW   s3      ,		"	"f	,$$/r   c                    t        j                         }|j                  j                  j	                         j                         }|j                  D|j                  dkD  r*dj                  |      }t        j                  |dd       nt        d      | j                  |      }| j                  |      }t        j                  |j                  ||      }|:t        j                   ||      }d| d| d| d	}t        j                  |dd       | j#                  |      }	|j%                  ||j                  |||j&                  |j(                  |j*                  |j,                  |j.                  |j0                  |	|j                  |j2                  |j4                  
      }
t7        j8                  d||
j:                         |
S )Nr   z?You are about to change retention period for dataset config: {}T)messagethrow_if_unattendedcancel_on_noz2retention-period-days value must be greater than 0z1You are about to change scope of dataset config: z from z to z`. Refer https://cloud.google.com/storage/docs/insights/datasets#dataset-config for more details.)organization_scopesource_projects_listsource_folders_listinclude_buckets_name_list!include_buckets_prefix_regex_listexclude_buckets_name_list!exclude_buckets_prefix_regex_listinclude_source_locationsexclude_source_locationsr,   retention_periodactivity_data_retention_perioddescriptionr   )r   InsightsApiCONCEPTSdataset_configParseRelativeNameretention_period_daysformatr	   PromptContinue
ValueErrorr%   r*   r   get_new_source_configenable_organization_scopeget_existing_source_configr-   update_dataset_configinclude_bucket_namesinclude_bucket_prefix_regexesexclude_bucket_namesexclude_bucket_prefix_regexesr9   r:   #activity_data_retention_period_daysr=   r   /dataset_config_operation_started_and_status_logname)r#   r$   clientdataset_config_relative_namer/   r3   r4   	new_scopeexisting_scoper,   update_dataset_config_operations              r   Runz
Update.Run_   s   %%'F$$**,99; ! !!-		#	#a	'MV01 	 	!!D	
 MNN99$?77="88&&I )DD
&n*+6.1A B[   t$  99$?&,&B&B$991/"&";";*.*L*L"&";";*.*L*L!%!>!>!%!>!>133'+'O'O$$ 'C '#" <<$',, +*r   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   r%   r*   r-   rW    r   r   r   r      sC     /

	-. I IB+r   r   N)r[   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   "googlecloudsdk.command_lib.storager   ;googlecloudsdk.command_lib.storage.insights.dataset_configsr   r   r   googlecloudsdk.core.consoler	   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHACommandr   r^   r   r   <module>ri      si     D 7 ( 4 Z P U 2 D%%++,D+T\\ D+ - D+r   