2021-04-18 21:41:13 +02:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-04-17 18:52:08 +02:00
|
|
|
|
|
|
|
package hdfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2020-07-14 18:38:05 +02:00
|
|
|
"github.com/minio/minio-go/v7/pkg/s3utils"
|
2019-04-17 18:52:08 +02:00
|
|
|
minio "github.com/minio/minio/cmd"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Minio meta bucket.
|
|
|
|
minioMetaBucket = ".minio.sys"
|
|
|
|
|
|
|
|
// Minio Tmp meta prefix.
|
|
|
|
minioMetaTmpBucket = minioMetaBucket + "/tmp"
|
|
|
|
|
|
|
|
// Minio reserved bucket name.
|
|
|
|
minioReservedBucket = "minio"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Ignores all reserved bucket names or invalid bucket names.
|
|
|
|
func isReservedOrInvalidBucket(bucketEntry string, strict bool) bool {
|
2019-08-06 21:08:58 +02:00
|
|
|
bucketEntry = strings.TrimSuffix(bucketEntry, minio.SlashSeparator)
|
2019-04-17 18:52:08 +02:00
|
|
|
if strict {
|
|
|
|
if err := s3utils.CheckValidBucketNameStrict(bucketEntry); err != nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := s3utils.CheckValidBucketName(bucketEntry); err != nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isMinioMetaBucket(bucketEntry) || isMinioReservedBucket(bucketEntry)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if input bucket is a reserved minio meta bucket '.minio.sys'.
|
|
|
|
func isMinioMetaBucket(bucketName string) bool {
|
|
|
|
return bucketName == minioMetaBucket
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if input bucket is a reserved minio bucket 'minio'.
|
|
|
|
func isMinioReservedBucket(bucketName string) bool {
|
|
|
|
return bucketName == minioReservedBucket
|
|
|
|
}
|
|
|
|
|
|
|
|
// byBucketName is a collection satisfying sort.Interface.
|
|
|
|
type byBucketName []minio.BucketInfo
|
|
|
|
|
|
|
|
func (d byBucketName) Len() int { return len(d) }
|
|
|
|
func (d byBucketName) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
|
|
|
|
func (d byBucketName) Less(i, j int) bool { return d[i].Name < d[j].Name }
|