storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/gateway/hdfs/gateway-hdfs-utils.go (about)

     1  /*
     2   * Minio Cloud Storage, (C) 2019 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 hdfs
    18  
    19  import (
    20  	"strings"
    21  
    22  	"github.com/minio/minio-go/v7/pkg/s3utils"
    23  
    24  	minio "storj.io/minio/cmd"
    25  )
    26  
    27  const (
    28  	// Minio meta bucket.
    29  	minioMetaBucket = ".minio.sys"
    30  
    31  	// Minio Tmp meta prefix.
    32  	minioMetaTmpBucket = minioMetaBucket + "/tmp"
    33  
    34  	// Minio reserved bucket name.
    35  	minioReservedBucket = "minio"
    36  )
    37  
    38  // Ignores all reserved bucket names or invalid bucket names.
    39  func isReservedOrInvalidBucket(bucketEntry string, strict bool) bool {
    40  	bucketEntry = strings.TrimSuffix(bucketEntry, minio.SlashSeparator)
    41  	if strict {
    42  		if err := s3utils.CheckValidBucketNameStrict(bucketEntry); err != nil {
    43  			return true
    44  		}
    45  	} else {
    46  		if err := s3utils.CheckValidBucketName(bucketEntry); err != nil {
    47  			return true
    48  		}
    49  	}
    50  	return isMinioMetaBucket(bucketEntry) || isMinioReservedBucket(bucketEntry)
    51  }
    52  
    53  // Returns true if input bucket is a reserved minio meta bucket '.minio.sys'.
    54  func isMinioMetaBucket(bucketName string) bool {
    55  	return bucketName == minioMetaBucket
    56  }
    57  
    58  // Returns true if input bucket is a reserved minio bucket 'minio'.
    59  func isMinioReservedBucket(bucketName string) bool {
    60  	return bucketName == minioReservedBucket
    61  }
    62  
    63  // byBucketName is a collection satisfying sort.Interface.
    64  type byBucketName []minio.BucketInfo
    65  
    66  func (d byBucketName) Len() int           { return len(d) }
    67  func (d byBucketName) Swap(i, j int)      { d[i], d[j] = d[j], d[i] }
    68  func (d byBucketName) Less(i, j int) bool { return d[i].Name < d[j].Name }