diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2025-07-18 02:19:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-18 02:19:50 -0700 |
| commit | c6a22ce43a3c0318b7c6841bcbf97937fd11e27c (patch) | |
| tree | fd027c20f547e1be7f550c96c1e5935f2579c4ca /weed/admin/dash/admin_server.go | |
| parent | 69553e5ba6d46ed924b0c3adc3f8d9666550999a (diff) | |
| download | seaweedfs-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/admin_server.go')
| -rw-r--r-- | weed/admin/dash/admin_server.go | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/weed/admin/dash/admin_server.go b/weed/admin/dash/admin_server.go index 9f97677e3..75b038a26 100644 --- a/weed/admin/dash/admin_server.go +++ b/weed/admin/dash/admin_server.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "net/http" - "strconv" "time" "github.com/gin-gonic/gin" @@ -24,6 +23,8 @@ import ( "github.com/seaweedfs/seaweedfs/weed/util" "github.com/seaweedfs/seaweedfs/weed/wdclient" "google.golang.org/grpc" + + "github.com/seaweedfs/seaweedfs/weed/s3api" ) type AdminServer struct { @@ -293,20 +294,11 @@ func (s *AdminServer) GetS3Buckets() ([]S3Bucket, error) { var objectLockDuration int32 = 0 if resp.Entry.Extended != nil { - if versioningBytes, exists := resp.Entry.Extended["s3.versioning"]; exists { - versioningEnabled = string(versioningBytes) == "Enabled" - } - if objectLockBytes, exists := resp.Entry.Extended["s3.objectlock"]; exists { - objectLockEnabled = string(objectLockBytes) == "Enabled" - } - if objectLockModeBytes, exists := resp.Entry.Extended["s3.objectlock.mode"]; exists { - objectLockMode = string(objectLockModeBytes) - } - if objectLockDurationBytes, exists := resp.Entry.Extended["s3.objectlock.duration"]; exists { - if duration, err := strconv.ParseInt(string(objectLockDurationBytes), 10, 32); err == nil { - objectLockDuration = int32(duration) - } - } + // Use shared utility to extract versioning information + versioningEnabled = extractVersioningFromEntry(resp.Entry) + + // Use shared utility to extract Object Lock information + objectLockEnabled, objectLockMode, objectLockDuration = extractObjectLockInfoFromEntry(resp.Entry) } bucket := S3Bucket{ @@ -379,20 +371,11 @@ func (s *AdminServer) GetBucketDetails(bucketName string) (*BucketDetails, error var objectLockDuration int32 = 0 if bucketResp.Entry.Extended != nil { - if versioningBytes, exists := bucketResp.Entry.Extended["s3.versioning"]; exists { - versioningEnabled = string(versioningBytes) == "Enabled" - } - if objectLockBytes, exists := bucketResp.Entry.Extended["s3.objectlock"]; exists { - objectLockEnabled = string(objectLockBytes) == "Enabled" - } - if objectLockModeBytes, exists := bucketResp.Entry.Extended["s3.objectlock.mode"]; exists { - objectLockMode = string(objectLockModeBytes) - } - if objectLockDurationBytes, exists := bucketResp.Entry.Extended["s3.objectlock.duration"]; exists { - if duration, err := strconv.ParseInt(string(objectLockDurationBytes), 10, 32); err == nil { - objectLockDuration = int32(duration) - } - } + // Use shared utility to extract versioning information + versioningEnabled = extractVersioningFromEntry(bucketResp.Entry) + + // Use shared utility to extract Object Lock information + objectLockEnabled, objectLockMode, objectLockDuration = extractObjectLockInfoFromEntry(bucketResp.Entry) } details.Bucket.VersioningEnabled = versioningEnabled @@ -1502,3 +1485,19 @@ func (s *AdminServer) Shutdown() { glog.V(1).Infof("Admin server shutdown complete") } + +// Function to extract Object Lock information from bucket entry using shared utilities +func extractObjectLockInfoFromEntry(entry *filer_pb.Entry) (bool, string, int32) { + // Try to load Object Lock configuration using shared utility + if config, found := s3api.LoadObjectLockConfigurationFromExtended(entry); found { + return s3api.ExtractObjectLockInfoFromConfig(config) + } + + return false, "", 0 +} + +// Function to extract versioning information from bucket entry using shared utilities +func extractVersioningFromEntry(entry *filer_pb.Entry) bool { + enabled, _ := s3api.LoadVersioningFromExtended(entry) + return enabled +} |
