github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/bucket/replication/sourceselectioncriteria.go (about) 1 // Copyright (c) 2015-2021 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package replication 19 20 import ( 21 "encoding/xml" 22 ) 23 24 // ReplicaModifications specifies if replica modification sync is enabled 25 type ReplicaModifications struct { 26 Status Status `xml:"Status" json:"Status"` 27 } 28 29 // SourceSelectionCriteria - specifies additional source selection criteria in ReplicationConfiguration. 30 type SourceSelectionCriteria struct { 31 ReplicaModifications ReplicaModifications `xml:"ReplicaModifications" json:"ReplicaModifications"` 32 } 33 34 // IsValid - checks whether SourceSelectionCriteria is valid or not. 35 func (s SourceSelectionCriteria) IsValid() bool { 36 return s.ReplicaModifications.Status == Enabled || s.ReplicaModifications.Status == Disabled 37 } 38 39 // Validate source selection criteria 40 func (s SourceSelectionCriteria) Validate() error { 41 if (s == SourceSelectionCriteria{}) { 42 return nil 43 } 44 if !s.IsValid() { 45 return errInvalidSourceSelectionCriteria 46 } 47 return nil 48 } 49 50 // UnmarshalXML - decodes XML data. 51 func (s *SourceSelectionCriteria) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) (err error) { 52 // Make subtype to avoid recursive UnmarshalXML(). 53 type sourceSelectionCriteria SourceSelectionCriteria 54 ssc := sourceSelectionCriteria{} 55 if err := dec.DecodeElement(&ssc, &start); err != nil { 56 return err 57 } 58 if len(ssc.ReplicaModifications.Status) == 0 { 59 ssc.ReplicaModifications.Status = Enabled 60 } 61 *s = SourceSelectionCriteria(ssc) 62 return nil 63 } 64 65 // MarshalXML - encodes to XML data. 66 func (s SourceSelectionCriteria) MarshalXML(e *xml.Encoder, start xml.StartElement) error { 67 if err := e.EncodeToken(start); err != nil { 68 return err 69 } 70 if s.IsValid() { 71 if err := e.EncodeElement(s.ReplicaModifications, xml.StartElement{Name: xml.Name{Local: "ReplicaModifications"}}); err != nil { 72 return err 73 } 74 } 75 return e.EncodeToken(xml.EndElement{Name: start.Name}) 76 }