access rule delete bug fix (#978)

Co-authored-by: Adam Stafford <adamstafford@Adams-MacBook-Pro.local>
This commit is contained in:
adfost
2021-08-24 16:22:47 -07:00
committed by GitHub
parent 597855364c
commit 1f1537fd60
9 changed files with 147 additions and 49 deletions

View File

@@ -146,9 +146,9 @@ func getSetAccessRuleWithBucketResponse(session *models.Principal, bucket string
return true, nil
}
func getDeleteAccessRuleWithBucketResponse(session *models.Principal, bucket string, prefix string) (bool, *models.Error) {
func getDeleteAccessRuleWithBucketResponse(session *models.Principal, bucket string, prefix *models.PrefixWrapper) (bool, *models.Error) {
ctx := context.Background()
client, err := newS3BucketClient(session, bucket, prefix)
client, err := newS3BucketClient(session, bucket, prefix.Prefix)
if err != nil {
return false, prepareError(err)
}

View File

@@ -570,9 +570,7 @@ func init() {
}
}
}
}
},
"/bucket/{bucket}/access-rules/{prefix}": {
},
"delete": {
"tags": [
"AdminAPI"
@@ -587,10 +585,12 @@ func init() {
"required": true
},
{
"type": "string",
"name": "prefix",
"in": "path",
"required": true
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/prefixWrapper"
}
}
],
"responses": {
@@ -4655,6 +4655,14 @@ func init() {
}
}
},
"prefixWrapper": {
"type": "object",
"properties": {
"prefix": {
"type": "string"
}
}
},
"principal": {
"type": "object",
"properties": {
@@ -5963,9 +5971,7 @@ func init() {
}
}
}
}
},
"/bucket/{bucket}/access-rules/{prefix}": {
},
"delete": {
"tags": [
"AdminAPI"
@@ -5980,10 +5986,12 @@ func init() {
"required": true
},
{
"type": "string",
"name": "prefix",
"in": "path",
"required": true
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/prefixWrapper"
}
}
],
"responses": {
@@ -10102,6 +10110,14 @@ func init() {
}
}
},
"prefixWrapper": {
"type": "object",
"properties": {
"prefix": {
"type": "string"
}
}
},
"principal": {
"type": "object",
"properties": {

View File

@@ -48,7 +48,7 @@ func NewDeleteAccessRuleWithBucket(ctx *middleware.Context, handler DeleteAccess
return &DeleteAccessRuleWithBucket{Context: ctx, Handler: handler}
}
/* DeleteAccessRuleWithBucket swagger:route DELETE /bucket/{bucket}/access-rules/{prefix} AdminAPI deleteAccessRuleWithBucket
/* DeleteAccessRuleWithBucket swagger:route DELETE /bucket/{bucket}/access-rules AdminAPI deleteAccessRuleWithBucket
Delete Access Rule From Given Bucket

View File

@@ -23,11 +23,17 @@ package admin_api
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"io"
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/validate"
"github.com/minio/console/models"
)
// NewDeleteAccessRuleWithBucketParams creates a new DeleteAccessRuleWithBucketParams object
@@ -54,9 +60,9 @@ type DeleteAccessRuleWithBucketParams struct {
Bucket string
/*
Required: true
In: path
In: body
*/
Prefix string
Prefix *models.PrefixWrapper
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
@@ -73,9 +79,32 @@ func (o *DeleteAccessRuleWithBucketParams) BindRequest(r *http.Request, route *m
res = append(res, err)
}
rPrefix, rhkPrefix, _ := route.Params.GetOK("prefix")
if err := o.bindPrefix(rPrefix, rhkPrefix, route.Formats); err != nil {
res = append(res, err)
if runtime.HasBody(r) {
defer r.Body.Close()
var body models.PrefixWrapper
if err := route.Consumer.Consume(r.Body, &body); err != nil {
if err == io.EOF {
res = append(res, errors.Required("prefix", "body", ""))
} else {
res = append(res, errors.NewParseError("prefix", "body", "", err))
}
} else {
// validate body object
if err := body.Validate(route.Formats); err != nil {
res = append(res, err)
}
ctx := validate.WithOperationRequest(context.Background())
if err := body.ContextValidate(ctx, route.Formats); err != nil {
res = append(res, err)
}
if len(res) == 0 {
o.Prefix = &body
}
}
} else {
res = append(res, errors.Required("prefix", "body", ""))
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
@@ -96,17 +125,3 @@ func (o *DeleteAccessRuleWithBucketParams) bindBucket(rawData []string, hasKey b
return nil
}
// bindPrefix binds and validates parameter Prefix from path.
func (o *DeleteAccessRuleWithBucketParams) bindPrefix(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// Parameter is provided by construction from the route
o.Prefix = raw
return nil
}

View File

@@ -32,7 +32,6 @@ import (
// DeleteAccessRuleWithBucketURL generates an URL for the delete access rule with bucket operation
type DeleteAccessRuleWithBucketURL struct {
Bucket string
Prefix string
_basePath string
// avoid unkeyed usage
@@ -58,7 +57,7 @@ func (o *DeleteAccessRuleWithBucketURL) SetBasePath(bp string) {
func (o *DeleteAccessRuleWithBucketURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/bucket/{bucket}/access-rules/{prefix}"
var _path = "/bucket/{bucket}/access-rules"
bucket := o.Bucket
if bucket != "" {
@@ -67,13 +66,6 @@ func (o *DeleteAccessRuleWithBucketURL) Build() (*url.URL, error) {
return nil, errors.New("bucket is required on DeleteAccessRuleWithBucketURL")
}
prefix := o.Prefix
if prefix != "" {
_path = strings.Replace(_path, "{prefix}", prefix, -1)
} else {
return nil, errors.New("prefix is required on DeleteAccessRuleWithBucketURL")
}
_basePath := o._basePath
if _basePath == "" {
_basePath = "/api/v1"

View File

@@ -1156,7 +1156,7 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = make(map[string]http.Handler)
}
o.handlers["DELETE"]["/bucket/{bucket}/access-rules/{prefix}"] = admin_api.NewDeleteAccessRuleWithBucket(o.context, o.AdminAPIDeleteAccessRuleWithBucketHandler)
o.handlers["DELETE"]["/bucket/{bucket}/access-rules"] = admin_api.NewDeleteAccessRuleWithBucket(o.context, o.AdminAPIDeleteAccessRuleWithBucketHandler)
if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = make(map[string]http.Handler)
}