def Run(self, args): util.ValidateUpdateArgsSpecified(args, [ 'channel_content', 'channel_content_from_file', 'display_name', 'enabled', 'type', 'description', 'fields', 'update_user_labels', 'remove_user_labels', 'clear_user_labels', 'update_channel_labels', 'remove_channel_labels', 'clear_channel_labels' ], 'channel') flags.ValidateNotificationChannelUpdateArgs(args) client = channels.NotificationChannelsClient() messages = client.messages channel_ref = args.CONCEPTS.channel.Parse() passed_yaml_channel = False channel_str = args.channel_content or args.channel_content_from_file if channel_str: passed_yaml_channel = True channel = util.MessageFromString( channel_str, messages.NotificationChannel, 'NotificationChannel', field_remappings=util.CHANNELS_FIELD_REMAPPINGS) else: channel = client.Get(channel_ref) if not args.fields: enabled = args.enabled if args.IsSpecified('enabled') else None fields = [] util.ModifyNotificationChannel(channel, channel_type=args.type, display_name=args.display_name, description=args.description, enabled=enabled, field_masks=fields) new_user_labels = util.ProcessUpdateLabels( args, 'user_labels', messages.NotificationChannel.UserLabelsValue, channel.userLabels) new_channel_labels = util.ProcessUpdateLabels( args, 'channel_labels', messages.NotificationChannel.LabelsValue, channel.labels) # TODO(b/73120276): Use field masks per key for label updates. if new_user_labels: channel.userLabels = new_user_labels fields.append('user_labels') if new_channel_labels: channel.labels = new_channel_labels fields.append('labels') # For more robust concurrent updates, use update masks if we're not # trying to replace the channel using --channel-content or # --channel-content-from-file. fields = None if passed_yaml_channel else ','.join(sorted(fields)) else: fields = ','.join(args.fields) return client.Update(channel_ref, channel, fields)
def Run(self, args): client = channels.NotificationChannelsClient() messages = client.messages channel = util.GetNotificationChannelFromArgs(args, messages) if args.user_labels: channel.userLabels = util.ParseCreateLabels( args.user_labels, messages.NotificationChannel.UserLabelsValue) if args.channel_labels: channel.labels = util.ParseCreateLabels( args.channel_labels, messages.NotificationChannel.LabelsValue) project_ref = (projects_util.ParseProject( properties.VALUES.core.project.Get())) result = client.Create(project_ref, channel) log.CreatedResource(result.name, 'notification channel') return result