move location constraint validation to s3api/utils
This commit is contained in:
1 parent
87a4aee115
commit
d5ed12db2b
2 files changed
+27
-27
No files matched your search
@@ -546,32 +546,6 @@ func (c S3ApiController) PutBucketAcl(ctx fiber.Ctx) (*Response, error) {
|
||||
}, err
|
||||
}
|
||||
|
||||
// validateLocationConstraint checks a CreateBucket location constraint. The
|
||||
// global endpoint serves defaultRegion and takes no constraint; any other
|
||||
// region is a region specific endpoint and requires the constraint to name it.
|
||||
func validateLocationConstraint(constraint *string, region string) error {
|
||||
if region == defaultRegion {
|
||||
if constraint != nil {
|
||||
debuglogger.Logf("invalid location constraint: %s", *constraint)
|
||||
return s3err.GetInvalidLocationConstraintErr(*constraint)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if constraint == nil {
|
||||
debuglogger.Logf("missing location constraint for region %s", region)
|
||||
return s3err.GetIllegalLocationConstraintErr("")
|
||||
}
|
||||
|
||||
if *constraint != region {
|
||||
debuglogger.Logf("illegal location constraint %s for region %s", *constraint, region)
|
||||
return s3err.GetIllegalLocationConstraintErr(*constraint)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c S3ApiController) CreateBucket(ctx fiber.Ctx) (*Response, error) {
|
||||
bucket := ctx.Params("bucket")
|
||||
acl := types.BucketCannedACL(c.getAclHeaderValue(ctx, "X-Amz-Acl"))
|
||||
@@ -691,7 +665,7 @@ func (c S3ApiController) CreateBucket(ctx fiber.Ctx) (*Response, error) {
|
||||
region = defaultRegion
|
||||
}
|
||||
|
||||
if err := validateLocationConstraint(body.LocationConstraint, region); err != nil {
|
||||
if err := utils.ValidateLocationConstraint(body.LocationConstraint, region); err != nil {
|
||||
return &Response{
|
||||
MetaOpts: &MetaOptions{
|
||||
BucketOwner: bucketOwner.Access,
|
||||
|
||||
@@ -1086,3 +1086,29 @@ func DetectResourceType(ctx fiber.Ctx) s3err.ResourceType {
|
||||
|
||||
return s3err.ResourceTypeObject
|
||||
}
|
||||
|
||||
// ValidateLocationConstraint checks a CreateBucket location constraint. The
|
||||
// global endpoint serves us-east-1 and takes no constraint; any other
|
||||
// region is a region specific endpoint and requires the constraint to name it.
|
||||
func ValidateLocationConstraint(constraint *string, region string) error {
|
||||
if region == "us-east-1" {
|
||||
if constraint != nil {
|
||||
debuglogger.Logf("invalid location constraint: %s", *constraint)
|
||||
return s3err.GetInvalidLocationConstraintErr(*constraint)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if constraint == nil {
|
||||
debuglogger.Logf("missing location constraint for region %s", region)
|
||||
return s3err.GetIllegalLocationConstraintErr("")
|
||||
}
|
||||
|
||||
if *constraint != region {
|
||||
debuglogger.Logf("illegal location constraint %s for region %s", *constraint, region)
|
||||
return s3err.GetIllegalLocationConstraintErr(*constraint)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user