/* * MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System.Diagnostics.CodeAnalysis; using System.Xml.Serialization; namespace Minio.DataModel.Notification; /// /// NotificationConfig - represents one single notification configuration /// such as topic, queue or lambda configuration /// public class NotificationConfiguration { public NotificationConfiguration() { Arn = null; Events = new List(); } public NotificationConfiguration(string arn) { Arn = new Arn(arn); } public NotificationConfiguration(Arn arn) { Arn = arn; } [XmlElement] public string Id { get; set; } [XmlElement("Event")] [SuppressMessage("Design", "CA1002:Do not expose generic lists", Justification = "Using Range functions in code")] public List Events { get; set; } [XmlElement("Filter")] public Filter Filter { get; set; } private Arn Arn { get; } public void AddEvents(IList evnt) { Events ??= new List(); Events.AddRange(evnt); } /// /// AddFilterSuffix sets the suffix configuration to the current notification config /// /// public void AddFilterSuffix(string suffix) { Filter ??= new Filter(); var newFilterRule = new FilterRule("suffix", suffix); // Replace any suffix rule if existing and add to the list otherwise for (var i = 0; i < Filter.S3Key.FilterRules.Count; i++) if (Filter.S3Key.FilterRules[i].Equals("suffix")) { Filter.S3Key.FilterRules[i] = newFilterRule; return; } Filter.S3Key.FilterRules.Add(newFilterRule); } /// /// AddFilterPrefix sets the prefix configuration to the current notification config /// /// public void AddFilterPrefix(string prefix) { Filter ??= new Filter(); var newFilterRule = new FilterRule("prefix", prefix); // Replace any prefix rule if existing and add to the list otherwise for (var i = 0; i < Filter.S3Key.FilterRules.Count; i++) if (Filter.S3Key.FilterRules[i].Equals("prefix")) { Filter.S3Key.FilterRules[i] = newFilterRule; return; } Filter.S3Key.FilterRules.Add(newFilterRule); } public bool ShouldSerializeFilter() { return Filter is not null; } public bool ShouldSerializeId() { return Id is not null; } public bool ShouldSerializeEvents() { return Events?.Count > 0; } internal bool IsIdSet() { return Id is not null; } }