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.
This commit is contained in:
@@ -18,30 +18,24 @@ func (h *S3TablesHandler) extractResourceOwnerAndBucket(
|
|||||||
resourcePath string,
|
resourcePath string,
|
||||||
rType ResourceType,
|
rType ResourceType,
|
||||||
) (ownerAccountID, bucketName string, err error) {
|
) (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 {
|
if rType == ResourceTypeTable {
|
||||||
var meta tableMetadataInternal
|
var meta tableMetadataInternal
|
||||||
if err := json.Unmarshal(data, &meta); err != nil {
|
if err := json.Unmarshal(data, &meta); err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
ownerAccountID = meta.OwnerAccountID
|
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 {
|
} else {
|
||||||
var meta tableBucketMetadata
|
var meta tableBucketMetadata
|
||||||
if err := json.Unmarshal(data, &meta); err != nil {
|
if err := json.Unmarshal(data, &meta); err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
ownerAccountID = meta.OwnerAccountID
|
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
|
return ownerAccountID, bucketName, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user