mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-20 04:54:24 +02:00
constants and fixes
✅ Return InvalidRetentionPeriod for invalid retention values (0 days, negative years) ✅ Return ObjectLockConfigurationNotFoundError when object lock configuration doesn't exist ✅ Handle all object lock validation errors consistently with proper error codes
This commit is contained in:
1 parent
1bc503530a
commit
7203c78e4d
6 files changed
+14
-8
No files matched your search
@@ -225,7 +225,7 @@ func (s3a *S3ApiServer) getBucketVersioningStatus(bucket string) (string, s3err.
|
||||
}
|
||||
|
||||
if config.Versioning == "" {
|
||||
return "Suspended", s3err.ErrNone
|
||||
return s3_constants.VersioningSuspended, s3err.ErrNone
|
||||
}
|
||||
|
||||
return config.Versioning, s3err.ErrNone
|
||||
|
||||
@@ -753,13 +753,13 @@ func (s3a *S3ApiServer) PutBucketVersioningHandler(w http.ResponseWriter, r *htt
|
||||
}
|
||||
|
||||
status := *versioningConfig.Status
|
||||
if status != "Enabled" && status != "Suspended" {
|
||||
if status != s3_constants.VersioningEnabled && status != s3_constants.VersioningSuspended {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if trying to suspend versioning on a bucket with object lock enabled
|
||||
if status == "Suspended" {
|
||||
if status == s3_constants.VersioningSuspended {
|
||||
// Get bucket configuration to check for object lock
|
||||
bucketConfig, errCode := s3a.getBucketConfig(bucket)
|
||||
if errCode == s3err.ErrNone && bucketConfig.ObjectLockConfig != nil {
|
||||
|
||||
@@ -113,7 +113,7 @@ func (s3a *S3ApiServer) GetObjectLockConfigurationHandler(w http.ResponseWriter,
|
||||
|
||||
// If no Object Lock configuration found, return error
|
||||
if len(configXML) == 0 {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchObjectLockConfiguration)
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrObjectLockConfigurationNotFoundError)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -566,9 +566,9 @@ func mapValidationErrorToS3Error(err error) s3err.ErrorCode {
|
||||
case errors.Is(err, ErrInvalidRetentionDateFormat):
|
||||
return s3err.ErrMalformedXML
|
||||
case errors.Is(err, ErrInvalidRetentionPeriod):
|
||||
// For invalid retention periods (days/years), return MalformedXML
|
||||
// This includes cases where both Days and Years are specified
|
||||
return s3err.ErrMalformedXML
|
||||
// For invalid retention periods (0 days, negative years, etc.), return InvalidRetentionPeriod
|
||||
// This includes cases where retention values are out of valid ranges
|
||||
return s3err.ErrInvalidRetentionPeriod
|
||||
case errors.Is(err, ErrInvalidRetentionMode):
|
||||
// For invalid retention modes, return MalformedXML
|
||||
// This includes cases where ObjectLockEnabled is 'Disabled'
|
||||
|
||||
@@ -102,7 +102,7 @@ func (s3a *S3ApiServer) GetObjectRetentionHandler(w http.ResponseWriter, r *http
|
||||
}
|
||||
|
||||
if errors.Is(err, ErrNoRetentionConfiguration) {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchObjectLockConfiguration)
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrObjectLockConfigurationNotFoundError)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@ const (
|
||||
ErrNoSuchObjectLockConfiguration
|
||||
ErrNoSuchObjectLegalHold
|
||||
ErrInvalidRetentionPeriod
|
||||
ErrObjectLockConfigurationNotFoundError
|
||||
)
|
||||
|
||||
// Error message constants for checksum validation
|
||||
@@ -459,6 +460,11 @@ var errorCodeResponse = map[ErrorCode]APIError{
|
||||
Description: "The bucket ownership controls were not found",
|
||||
HTTPStatusCode: http.StatusNotFound,
|
||||
},
|
||||
ErrObjectLockConfigurationNotFoundError: {
|
||||
Code: "ObjectLockConfigurationNotFoundError",
|
||||
Description: "Object Lock configuration does not exist for this bucket",
|
||||
HTTPStatusCode: http.StatusNotFound,
|
||||
},
|
||||
}
|
||||
|
||||
// GetAPIError provides API Error for input API error code.
|
||||
|
||||
Reference in new issue
Block a user