MCPcopy
hub / github.com/minio/minio-go / CheckValidBucketNameS3Express

Function CheckValidBucketNameS3Express

pkg/s3utils/utils.go:408–450  ·  view source on GitHub ↗

CheckValidBucketNameS3Express - checks if we have a valid input bucket name for S3 Express.

(bucketName string)

Source from the content-addressed store, hash-verified

406
407// CheckValidBucketNameS3Express - checks if we have a valid input bucket name for S3 Express.
408func CheckValidBucketNameS3Express(bucketName string) (err error) {
409 if strings.TrimSpace(bucketName) == "" {
410 return errors.New("Bucket name cannot be empty for S3 Express")
411 }
412
413 if len(bucketName) < 3 {
414 return errors.New("Bucket name cannot be shorter than 3 characters for S3 Express")
415 }
416
417 if len(bucketName) > 63 {
418 return errors.New("Bucket name cannot be longer than 63 characters for S3 Express")
419 }
420
421 // Check if the bucket matches the regex
422 if !validBucketNameS3Express.MatchString(bucketName) {
423 return errors.New("Bucket name contains invalid characters")
424 }
425
426 // Extract bucket name (before --<az-id>--x-s3)
427 parts := strings.Split(bucketName, "--")
428 if len(parts) != 3 || parts[2] != "x-s3" {
429 return errors.New("Bucket name pattern is wrong 'x-s3'")
430 }
431 bucketName = parts[0]
432
433 // Additional validation for bucket name
434 // 1. No consecutive periods or hyphens
435 if strings.Contains(bucketName, "..") || strings.Contains(bucketName, "--") {
436 return errors.New("Bucket name contains invalid characters")
437 }
438
439 // 2. No period-hyphen or hyphen-period
440 if strings.Contains(bucketName, ".-") || strings.Contains(bucketName, "-.") {
441 return errors.New("Bucket name has unexpected format or contains invalid characters")
442 }
443
444 // 3. No IP address format (e.g., 192.168.0.1)
445 if ipAddress.MatchString(bucketName) {
446 return errors.New("Bucket name cannot be an ip address")
447 }
448
449 return nil
450}
451
452// CheckValidBucketNameStrict - checks if we have a valid input bucket name.
453// This is a stricter version.

Callers 2

CreateSessionMethod · 0.92
IsS3ExpressBucketFunction · 0.85

Calls 1

ContainsMethod · 0.45

Tested by

no test coverage detected