SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
refactor
Chris Lu549b65785d60
diff --git a/weed/s3api/s3tables/handler_bucket_create.go b/weed/s3api/s3tables/handler_bucket_create.goindex c2a58aae45..2bbbcefcaa 100644--- a/weed/s3api/s3tables/handler_bucket_create.go+++ b/weed/s3api/s3tables/handler_bucket_create.go@@ -26,21 +26,10 @@ func (h *S3TablesHandler) handleCreateTableBucket(w http.ResponseWriter, r *httpreturn err}- if req.Name == "" {- h.writeError(w, http.StatusBadRequest, ErrCodeInvalidRequest, "name is required")- return fmt.Errorf("name is required")- }-- // Validate bucket name length- if len(req.Name) < 3 || len(req.Name) > 63 {- h.writeError(w, http.StatusBadRequest, ErrCodeInvalidRequest, "bucket name must be between 3 and 63 characters")- return fmt.Errorf("invalid bucket name length")- }-// Validate bucket name- if !isValidBucketName(req.Name) {- h.writeError(w, http.StatusBadRequest, ErrCodeInvalidRequest, "invalid bucket name")- return fmt.Errorf("invalid bucket name")+ if err := validateBucketName(req.Name); err != nil {+ h.writeError(w, http.StatusBadRequest, ErrCodeInvalidRequest, err.Error())+ return err}bucketPath := getTableBucketPath(req.Name)diff --git a/weed/s3api/s3tables/utils.go b/weed/s3api/s3tables/utils.goindex cf009641eb..d5c2ee9687 100644--- a/weed/s3api/s3tables/utils.go+++ b/weed/s3api/s3tables/utils.go@@ -112,24 +112,28 @@ type tableMetadataInternal struct {// Utility functions-// isValidBucketName validates bucket name characters+// validateBucketName validates bucket name and returns an error if invalid.// Bucket names must contain only lowercase letters, numbers, and hyphens.// Length must be between 3 and 63 characters.// Must start and end with a letter or digit.// Reserved prefixes/suffixes are rejected.-func isValidBucketName(name string) bool {+func validateBucketName(name string) error {+ if name == "" {+ return fmt.Errorf("bucket name is required")+ }+if len(name) < 3 || len(name) > 63 {- return false+ return fmt.Errorf("bucket name must be between 3 and 63 characters")}// Must start and end with a letter or digitstart := name[0]end := name[len(name)-1]if !((start >= 'a' && start <= 'z') || (start >= '0' && start <= '9')) {- return false+ return fmt.Errorf("bucket name must start with a letter or digit")}if !((end >= 'a' && end <= 'z') || (end >= '0' && end <= '9')) {- return false+ return fmt.Errorf("bucket name must end with a letter or digit")}// Allowed characters: a-z, 0-9, -@@ -138,14 +142,14 @@ func isValidBucketName(name string) bool {if (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '-' {continue}- return false+ return fmt.Errorf("bucket name can only contain lowercase letters, numbers, and hyphens")}// Reserved prefixesreservedPrefixes := []string{"xn--", "sthree-", "amzn-s3-demo-", "aws"}for _, p := range reservedPrefixes {if strings.HasPrefix(name, p) {- return false+ return fmt.Errorf("bucket name cannot start with reserved prefix: %s", p)}}@@ -153,11 +157,17 @@ func isValidBucketName(name string) bool {reservedSuffixes := []string{"-s3alias", "--ol-s3", "--x-s3", "--table-s3"}for _, s := range reservedSuffixes {if strings.HasSuffix(name, s) {- return false+ return fmt.Errorf("bucket name cannot end with reserved suffix: %s", s)}}- return true+ return nil+}++// isValidBucketName validates bucket name characters (kept for compatibility)+// Deprecated: use validateBucketName instead+func isValidBucketName(name string) bool {+ return validateBucketName(name) == nil}// generateVersionToken generates a unique, unpredictable version token