storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/bucket/versioning/versioning.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2020 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package versioning 18 19 import ( 20 "encoding/xml" 21 "io" 22 ) 23 24 // State - enabled/disabled/suspended states 25 // for multifactor and status of versioning. 26 type State string 27 28 // Various supported states 29 const ( 30 Enabled State = "Enabled" 31 // Disabled State = "Disabled" only used by MFA Delete not supported yet. 32 Suspended State = "Suspended" 33 ) 34 35 // Versioning - Configuration for bucket versioning. 36 type Versioning struct { 37 XMLNS string `xml:"xmlns,attr,omitempty"` 38 XMLName xml.Name `xml:"VersioningConfiguration"` 39 // MFADelete State `xml:"MFADelete,omitempty"` // not supported yet. 40 Status State `xml:"Status,omitempty"` 41 } 42 43 // Validate - validates the versioning configuration 44 func (v Versioning) Validate() error { 45 // Not supported yet 46 // switch v.MFADelete { 47 // case Enabled, Disabled: 48 // default: 49 // return Errorf("unsupported MFADelete state %s", v.MFADelete) 50 // } 51 switch v.Status { 52 case Enabled, Suspended: 53 default: 54 return Errorf("unsupported Versioning status %s", v.Status) 55 } 56 return nil 57 } 58 59 // Enabled - returns true if versioning is enabled 60 func (v Versioning) Enabled() bool { 61 return v.Status == Enabled 62 } 63 64 // Suspended - returns true if versioning is suspended 65 func (v Versioning) Suspended() bool { 66 return v.Status == Suspended 67 } 68 69 // ParseConfig - parses data in given reader to VersioningConfiguration. 70 func ParseConfig(reader io.Reader) (*Versioning, error) { 71 var v Versioning 72 if err := xml.NewDecoder(reader).Decode(&v); err != nil { 73 return nil, err 74 } 75 if err := v.Validate(); err != nil { 76 return nil, err 77 } 78 return &v, nil 79 }