def Run(self, args): """This 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 view. """ view_data = {} if args.IsSpecified('description'): view_data['description'] = args.description if args.IsSpecified('log_filter'): view_data['filter'] = args.log_filter return util.GetClient().projects_locations_buckets_views.Create( util.GetMessages( ).LoggingProjectsLocationsBucketsViewsCreateRequest( viewId=args.VIEW_ID, parent=util.CreateResourceName( util.CreateResourceName( util.GetProjectResource(args.project).RelativeName(), 'locations', args.location), 'buckets', args.bucket), logView=util.GetMessages().LogView(**view_data)))
def _Run(self, args, is_alpha=False): bucket_data = {} update_mask = [] parameter_names = ['--retention-days', '--description'] if args.IsSpecified('retention_days'): bucket_data['retentionDays'] = args.retention_days update_mask.append('retention_days') if args.IsSpecified('description'): bucket_data['description'] = args.description update_mask.append('description') if is_alpha: parameter_names.extend(['--locked']) if args.IsSpecified('locked'): bucket_data['locked'] = args.locked update_mask.append('locked') if args.locked: console_io.PromptContinue( 'WARNING: Locking a bucket cannot be undone.', default=False, cancel_on_no=True) if not update_mask: raise calliope_exceptions.MinimumArgumentException( parameter_names, 'Please specify at least one property to update') return util.GetClient().projects_locations_buckets.Patch( util.GetMessages().LoggingProjectsLocationsBucketsPatchRequest( name=util.CreateResourceName( util.CreateResourceName( util.GetProjectResource(args.project).RelativeName(), 'locations', args.location), 'buckets', args.BUCKET_ID), logBucket=util.GetMessages().LogBucket(**bucket_data), updateMask=','.join(update_mask)))
def Run(self, args): """This 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 updated bucket. """ bucket_data = {} update_mask = [] if args.IsSpecified('retention_days'): bucket_data['retentionDays'] = args.retention_days update_mask.append('retention_days') if args.IsSpecified('description'): bucket_data['description'] = args.description update_mask.append('description') if not update_mask: raise calliope_exceptions.MinimumArgumentException( ['--retention-days', '--description'], 'Please specify at least one property to update') return util.GetClient().projects_locations_buckets.Patch( util.GetMessages().LoggingProjectsLocationsBucketsPatchRequest( name=util.CreateResourceName( util.CreateResourceName( util.GetProjectResource(args.project).RelativeName(), 'locations', args.location), 'buckets', args.BUCKET_ID), logBucket=util.GetMessages().LogBucket(**bucket_data), updateMask=','.join(update_mask)))
def Run(self, args): """This 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 updated view. """ view_data = {} update_mask = [] parameter_names = ['--log-filter', '--description'] if args.IsSpecified('log_filter'): view_data['filter'] = args.log_filter update_mask.append('filter') if args.IsSpecified('description'): view_data['description'] = args.description update_mask.append('description') if not update_mask: raise calliope_exceptions.MinimumArgumentException( parameter_names, 'Please specify at least one property to update') return util.GetClient().projects_locations_buckets_views.Patch( util.GetMessages().LoggingProjectsLocationsBucketsViewsPatchRequest( name=util.CreateResourceName(util.CreateResourceName( util.CreateResourceName( util.GetProjectResource(args.project).RelativeName(), 'locations', args.location), 'buckets', args.bucket), 'views', args.VIEW_ID), logView=util.GetMessages().LogView(**view_data), updateMask=','.join(update_mask)))
def Run(self, args): """This 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. """ bucket_data = {} if args.IsSpecified('retention_days'): bucket_data['retentionDays'] = args.retention_days if args.IsSpecified('description'): bucket_data['description'] = args.description if args.IsSpecified('enable_analytics'): bucket_data['analyticsEnabled'] = args.enable_analytics return util.GetClient().projects_locations_buckets.Create( util.GetMessages().LoggingProjectsLocationsBucketsCreateRequest( bucketId=args.BUCKET_ID, parent=util.CreateResourceName( util.GetProjectResource(args.project).RelativeName(), 'locations', args.location), logBucket=util.GetMessages().LogBucket(**bucket_data)))
def _Run(self, args, is_alpha=False): bucket_data = {} if args.IsSpecified('retention_days'): bucket_data['retentionDays'] = args.retention_days if args.IsSpecified('description'): bucket_data['description'] = args.description if args.IsSpecified('restricted_fields'): bucket_data['restrictedFields'] = args.restricted_fields if is_alpha and args.IsSpecified('enable_analytics'): bucket_data['analyticsEnabled'] = args.enable_analytics if is_alpha and args.IsSpecified('index'): bucket_data['indexConfigs'] = args.index if is_alpha and args.IsSpecified('cmek_kms_key_name'): console_io.PromptContinue( 'CMEK cannot be disabled on a bucket once enabled.', cancel_on_no=True) cmek_settings = util.GetMessages().CmekSettings( kmsKeyName=args.cmek_kms_key_name) bucket_data['cmekSettings'] = cmek_settings return util.GetClient().projects_locations_buckets.Create( util.GetMessages().LoggingProjectsLocationsBucketsCreateRequest( bucketId=args.BUCKET_ID, parent=util.CreateResourceName( util.GetProjectResource(args.project).RelativeName(), 'locations', args.location), logBucket=util.GetMessages().LogBucket(**bucket_data)))
def GetCurrentBucket(self, args): """Returns a bucket specified by the arguments. Loads the current bucket at most once. If called multiple times, the previously-loaded bucket will be returned. Args: args: The argument set. This is not checked across GetCurrentBucket calls, and must be consistent. """ if not self._current_bucket: return util.GetClient().projects_locations_buckets.Get( util.GetMessages().LoggingProjectsLocationsBucketsGetRequest( name=util.CreateResourceName( util.CreateResourceName( util.GetProjectResource( args.project).RelativeName(), 'locations', args.location), 'buckets', args.BUCKET_ID))) return self._current_bucket
def _Run(self, args, is_alpha=False): bucket_data = {} if args.IsSpecified('retention_days'): bucket_data['retentionDays'] = args.retention_days if args.IsSpecified('description'): bucket_data['description'] = args.description if is_alpha and args.IsSpecified('enable_analytics'): bucket_data['analyticsEnabled'] = args.enable_analytics if is_alpha and args.IsSpecified('restricted_fields'): bucket_data['restrictedFields'] = args.restricted_fields return util.GetClient().projects_locations_buckets.Create( util.GetMessages().LoggingProjectsLocationsBucketsCreateRequest( bucketId=args.BUCKET_ID, parent=util.CreateResourceName( util.GetProjectResource(args.project).RelativeName(), 'locations', args.location), logBucket=util.GetMessages().LogBucket(**bucket_data)))
def _Run(self, args, is_alpha=False): bucket_data = {} update_mask = [] parameter_names = ['--retention-days', '--description', '--locked'] if args.IsSpecified('retention_days'): bucket_data['retentionDays'] = args.retention_days update_mask.append('retention_days') if args.IsSpecified('description'): bucket_data['description'] = args.description update_mask.append('description') if args.IsSpecified('locked'): bucket_data['locked'] = args.locked update_mask.append('locked') if args.locked: console_io.PromptContinue( 'WARNING: Locking a bucket cannot be undone.', default=False, cancel_on_no=True) if args.IsSpecified('restricted_fields'): bucket_data['restrictedFields'] = args.restricted_fields update_mask.append('restricted_fields') if is_alpha and args.enable_loglink is not None: bucket_data['logLink'] = {'enabled': args.enable_loglink} update_mask.append('log_link.enabled') if is_alpha and (args.IsSpecified('clear_indexes') or args.IsSpecified('remove_indexes') or args.IsSpecified('add_index') or args.IsSpecified('update_index')): bucket = self.GetCurrentBucket(args) bucket_data['indexConfigs'] = [] update_mask.append('index_configs') indexes_to_remove = (args.remove_indexes if args.IsSpecified('remove_indexes') else []) indexes_to_update = (args.update_index if args.IsSpecified('update_index') else []) for index in bucket.indexConfigs: if index.fieldPath in indexes_to_remove: indexes_to_remove.remove(index.fieldPath) else: for i in range(len(indexes_to_update)): if index.fieldPath == indexes_to_update[i][ 'fieldPath']: for key, value in indexes_to_update[i].items(): if key == 'type': index.type = value indexes_to_update.pop(i) break bucket_data['indexConfigs'].append(index) if indexes_to_remove: raise calliope_exceptions.InvalidArgumentException( '--remove-indexes', 'Indexes {0} do not exist'.format( ','.join(indexes_to_remove))) if indexes_to_update: raise calliope_exceptions.InvalidArgumentException( '--update-index', 'Indexes {0} do not exist'.format(','.join( [index['fieldPath'] for index in indexes_to_update]))) if args.IsSpecified('clear_indexes'): bucket_data['indexConfigs'] = [] if args.IsSpecified('add_index'): bucket_data['indexConfigs'] += args.add_index if is_alpha and args.IsSpecified('cmek_kms_key_name'): bucket = self.GetCurrentBucket(args) if not bucket.cmekSettings: # This is the first time CMEK settings are being applied. Warn the user # that this is irreversible. console_io.PromptContinue( 'CMEK cannot be disabled on a bucket once enabled.', cancel_on_no=True) cmek_settings = util.GetMessages().CmekSettings( kmsKeyName=args.cmek_kms_key_name) bucket_data['cmekSettings'] = cmek_settings update_mask.append('cmek_settings') if not update_mask: raise calliope_exceptions.MinimumArgumentException( parameter_names, 'Please specify at least one property to update') return util.GetClient().projects_locations_buckets.Patch( util.GetMessages().LoggingProjectsLocationsBucketsPatchRequest( name=util.CreateResourceName( util.CreateResourceName( util.GetProjectResource(args.project).RelativeName(), 'locations', args.location), 'buckets', args.BUCKET_ID), logBucket=util.GetMessages().LogBucket(**bucket_data), updateMask=','.join(update_mask)))