Skip to content

Commit

Permalink
feat(objectnode): disable createBucket by s3
Browse files Browse the repository at this point in the history
Signed-off-by: tangdeyi <[email protected]>
  • Loading branch information
tangdeyi committed Dec 6, 2023
1 parent 0d8662c commit 9388fc0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion objectnode/api_handler_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (o *ObjectNode) createBucketHandler(w http.ResponseWriter, r *http.Request)
o.errorResponse(w, r, err, errorCode)
}()

if o.disableCreateBucketByS3 {
errorCode = DisableCreateBucketByS3
return
}
param := ParseRequestParam(r)
bucket := param.Bucket()
if bucket == "" {
Expand Down Expand Up @@ -247,10 +251,11 @@ func (o *ObjectNode) listBucketsHandler(w http.ResponseWriter, r *http.Request)

var output listBucketsOutput
authVos := userInfo.Policy.AuthorizedVols
ownVols := userInfo.Policy.OwnVols
for vol := range authVos {
ownVols = append(ownVols, vol)
}
for _, ownVol := range userInfo.Policy.OwnVols {
for _, ownVol := range ownVols {
var vol *Volume
if vol, err = o.getVol(ownVol); err != nil {
log.LogErrorf("listBucketsHandler: load volume fail: requestID(%v) volume(%v) err(%v)",
Expand Down
1 change: 1 addition & 0 deletions objectnode/result_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
EntityTooLarge = &ErrorCode{ErrorCode: "EntityTooLarge", ErrorMessage: "Your proposed upload exceeds the maximum allowed object size.", StatusCode: http.StatusBadRequest}
IncorrectNumberOfFilesInPostRequest = &ErrorCode{ErrorCode: "IncorrectNumberOfFilesInPostRequest", ErrorMessage: "POST requires exactly one file upload per request.", StatusCode: http.StatusBadRequest}
InvalidArgument = &ErrorCode{ErrorCode: "InvalidArgument", ErrorMessage: "Invalid Argument", StatusCode: http.StatusBadRequest}
DisableCreateBucketByS3 = &ErrorCode{ErrorCode: "DisableCreateBucketByS3", ErrorMessage: "DisableCreateBucketByS3.", StatusCode: http.StatusBadRequest}
InvalidBucketName = &ErrorCode{ErrorCode: "InvalidBucketName", ErrorMessage: "The specified bucket is not valid.", StatusCode: http.StatusBadRequest}
InvalidRange = &ErrorCode{ErrorCode: "InvalidRange", ErrorMessage: "The requested range cannot be satisfied.", StatusCode: http.StatusRequestedRangeNotSatisfiable}
MissingContentLength = &ErrorCode{ErrorCode: "MissingContentLength", ErrorMessage: "You must provide the Content-Length HTTP header.", StatusCode: http.StatusLengthRequired}
Expand Down
11 changes: 7 additions & 4 deletions objectnode/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const (
// {
// "strict": true
// }
configStrict = "strict"
configStrict = "strict"
disableCreateBucketByS3 = "disableCreateBucketByS3"

// The character creation array configuration item is used to configure the domain name bound to the object
// storage interface. You can bind multiple. ObjectNode uses this configuration to implement automatic
Expand Down Expand Up @@ -199,9 +200,10 @@ type ObjectNode struct {
disabledActions proto.Actions // disabled actions
stsNotAllowedActions proto.Actions // actions that are not accessible to STS users

control common.Control
rateLimit RateLimiter
limitMutex sync.RWMutex
control common.Control
rateLimit RateLimiter
limitMutex sync.RWMutex
disableCreateBucketByS3 bool
}

func (o *ObjectNode) Start(cfg *config.Config) (err error) {
Expand Down Expand Up @@ -286,6 +288,7 @@ func (o *ObjectNode) loadConfig(cfg *config.Config) (err error) {
// parse strict config
strict := cfg.GetBool(configStrict)
log.LogInfof("loadConfig: strict: %v", strict)
o.disableCreateBucketByS3 = cfg.GetBool(disableCreateBucketByS3)

o.mc = master.NewMasterClient(masters, false)
o.vm = NewVolumeManager(masters, strict)
Expand Down

0 comments on commit 9388fc0

Please sign in to comment.