From c99e8d41525b14e282a0f6cb6d7bb67e5dea12d8 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 28 Jan 2026 17:47:14 -0800 Subject: [PATCH] s3tables: Remove duplicate bucket extraction logic in helper Move bucket name extraction outside the if/else block in extractResourceOwnerAndBucket since the logic is identical for both ResourceTypeTable and ResourceTypeBucket cases. This reduces code duplication and improves maintainability. The extraction pattern (parts[1] from /tables/{bucket}/...) works for both resource types, so it's now performed once before the type-specific metadata unmarshaling. --- weed/s3api/s3tables/handler_policy.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/weed/s3api/s3tables/handler_policy.go b/weed/s3api/s3tables/handler_policy.go index 93fb3673f..fd2537d74 100644 --- a/weed/s3api/s3tables/handler_policy.go +++ b/weed/s3api/s3tables/handler_policy.go @@ -18,30 +18,24 @@ func (h *S3TablesHandler) extractResourceOwnerAndBucket( resourcePath string, rType ResourceType, ) (ownerAccountID, bucketName string, err error) { + // Extract bucket name from resource path (format: /tables/{bucket}/... for both tables and buckets) + parts := strings.Split(strings.Trim(resourcePath, "/"), "/") + if len(parts) >= 2 { + bucketName = parts[1] + } + if rType == ResourceTypeTable { var meta tableMetadataInternal if err := json.Unmarshal(data, &meta); err != nil { return "", "", err } ownerAccountID = meta.OwnerAccountID - // Extract bucket name from resource path for tables - // resourcePath format: /tables/{bucket}/{namespace}/{table} - parts := strings.Split(strings.Trim(resourcePath, "/"), "/") - if len(parts) >= 2 { - bucketName = parts[1] - } } else { var meta tableBucketMetadata if err := json.Unmarshal(data, &meta); err != nil { return "", "", err } ownerAccountID = meta.OwnerAccountID - // Extract bucket name from resource path for buckets - // resourcePath format: /tables/{bucket} - parts := strings.Split(strings.Trim(resourcePath, "/"), "/") - if len(parts) >= 2 { - bucketName = parts[1] - } } return ownerAccountID, bucketName, nil }