aboutsummaryrefslogtreecommitdiff
path: root/weed/admin/dash/bucket_management.go
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2025-07-18 02:19:50 -0700
committerGitHub <noreply@github.com>2025-07-18 02:19:50 -0700
commitc6a22ce43a3c0318b7c6841bcbf97937fd11e27c (patch)
treefd027c20f547e1be7f550c96c1e5935f2579c4ca /weed/admin/dash/bucket_management.go
parent69553e5ba6d46ed924b0c3adc3f8d9666550999a (diff)
downloadseaweedfs-c6a22ce43a3c0318b7c6841bcbf97937fd11e27c.tar.xz
seaweedfs-c6a22ce43a3c0318b7c6841bcbf97937fd11e27c.zip
Fix get object lock configuration handler (#6996)
* fix GetObjectLockConfigurationHandler * cache and use bucket object lock config * subscribe to bucket configuration changes * increase bucket config cache TTL * refactor * Update weed/s3api/s3api_server.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * avoid duplidated work * rename variable * Update s3api_object_handlers_put.go * fix routing * admin ui and api handler are consistent now * use fields instead of xml * fix test * address comments * Update weed/s3api/s3api_object_handlers_put.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/s3/retention/s3_retention_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update weed/s3api/object_lock_utils.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * change error style * errorf --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Diffstat (limited to 'weed/admin/dash/bucket_management.go')
-rw-r--r--weed/admin/dash/bucket_management.go46
1 files changed, 29 insertions, 17 deletions
diff --git a/weed/admin/dash/bucket_management.go b/weed/admin/dash/bucket_management.go
index faa19ec99..bd488dc90 100644
--- a/weed/admin/dash/bucket_management.go
+++ b/weed/admin/dash/bucket_management.go
@@ -10,6 +10,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
+ "github.com/seaweedfs/seaweedfs/weed/s3api"
)
// S3 Bucket management data structures for templates
@@ -340,32 +341,43 @@ func (s *AdminServer) CreateS3BucketWithObjectLock(bucketName string, quotaBytes
TtlSec: 0,
}
- // Create extended attributes map for versioning and object lock
+ // Create extended attributes map for versioning
extended := make(map[string][]byte)
- if versioningEnabled {
- extended["s3.versioning"] = []byte("Enabled")
- } else {
- extended["s3.versioning"] = []byte("Suspended")
+
+ // Create bucket entry
+ bucketEntry := &filer_pb.Entry{
+ Name: bucketName,
+ IsDirectory: true,
+ Attributes: attributes,
+ Extended: extended,
+ Quota: quota,
}
+ // Handle versioning using shared utilities
+ if err := s3api.StoreVersioningInExtended(bucketEntry, versioningEnabled); err != nil {
+ return fmt.Errorf("failed to store versioning configuration: %w", err)
+ }
+
+ // Handle Object Lock configuration using shared utilities
if objectLockEnabled {
- extended["s3.objectlock"] = []byte("Enabled")
- extended["s3.objectlock.mode"] = []byte(objectLockMode)
- extended["s3.objectlock.duration"] = []byte(fmt.Sprintf("%d", objectLockDuration))
- } else {
- extended["s3.objectlock"] = []byte("Disabled")
+ // Validate Object Lock parameters
+ if err := s3api.ValidateObjectLockParameters(objectLockEnabled, objectLockMode, objectLockDuration); err != nil {
+ return fmt.Errorf("invalid Object Lock parameters: %w", err)
+ }
+
+ // Create Object Lock configuration using shared utility
+ objectLockConfig := s3api.CreateObjectLockConfigurationFromParams(objectLockEnabled, objectLockMode, objectLockDuration)
+
+ // Store Object Lock configuration in extended attributes using shared utility
+ if err := s3api.StoreObjectLockConfigurationInExtended(bucketEntry, objectLockConfig); err != nil {
+ return fmt.Errorf("failed to store Object Lock configuration: %w", err)
+ }
}
// Create bucket directory under /buckets
_, err = client.CreateEntry(context.Background(), &filer_pb.CreateEntryRequest{
Directory: "/buckets",
- Entry: &filer_pb.Entry{
- Name: bucketName,
- IsDirectory: true,
- Attributes: attributes,
- Extended: extended,
- Quota: quota,
- },
+ Entry: bucketEntry,
})
if err != nil {
return fmt.Errorf("failed to create bucket directory: %w", err)