github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/bucket-versioning.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 cmd
    19  
    20  import (
    21  	"strings"
    22  
    23  	"github.com/minio/minio/internal/bucket/versioning"
    24  	"github.com/minio/minio/internal/logger"
    25  )
    26  
    27  // BucketVersioningSys - policy subsystem.
    28  type BucketVersioningSys struct{}
    29  
    30  // Enabled enabled versioning?
    31  func (sys *BucketVersioningSys) Enabled(bucket string) bool {
    32  	vc, err := sys.Get(bucket)
    33  	if err != nil {
    34  		logger.CriticalIf(GlobalContext, err)
    35  	}
    36  	return vc.Enabled()
    37  }
    38  
    39  // PrefixEnabled returns true is versioning is enabled at bucket level and if
    40  // the given prefix doesn't match any excluded prefixes pattern. This is
    41  // part of a MinIO versioning configuration extension.
    42  func (sys *BucketVersioningSys) PrefixEnabled(bucket, prefix string) bool {
    43  	vc, err := sys.Get(bucket)
    44  	if err != nil {
    45  		logger.CriticalIf(GlobalContext, err)
    46  	}
    47  	return vc.PrefixEnabled(prefix)
    48  }
    49  
    50  // Suspended suspended versioning?
    51  func (sys *BucketVersioningSys) Suspended(bucket string) bool {
    52  	vc, err := sys.Get(bucket)
    53  	if err != nil {
    54  		logger.CriticalIf(GlobalContext, err)
    55  	}
    56  	return vc.Suspended()
    57  }
    58  
    59  // PrefixSuspended returns true if the given prefix matches an excluded prefix
    60  // pattern. This is part of a MinIO versioning configuration extension.
    61  func (sys *BucketVersioningSys) PrefixSuspended(bucket, prefix string) bool {
    62  	vc, err := sys.Get(bucket)
    63  	if err != nil {
    64  		logger.CriticalIf(GlobalContext, err)
    65  	}
    66  
    67  	return vc.PrefixSuspended(prefix)
    68  }
    69  
    70  // Get returns stored bucket policy
    71  func (sys *BucketVersioningSys) Get(bucket string) (*versioning.Versioning, error) {
    72  	if bucket == minioMetaBucket || strings.HasPrefix(bucket, minioMetaBucket) {
    73  		return &versioning.Versioning{XMLNS: "http://s3.amazonaws.com/doc/2006-03-01/"}, nil
    74  	}
    75  
    76  	vcfg, _, err := globalBucketMetadataSys.GetVersioningConfig(bucket)
    77  	return vcfg, err
    78  }
    79  
    80  // NewBucketVersioningSys - creates new versioning system.
    81  func NewBucketVersioningSys() *BucketVersioningSys {
    82  	return &BucketVersioningSys{}
    83  }