Allow set policy to none (#1039)
* policy bug fix * rename button Co-authored-by: Adam Stafford <adamstafford@Adams-MacBook-Pro.local>
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/minio/console/models"
|
||||
@@ -63,14 +64,14 @@ func registersPoliciesHandler(api *operations.ConsoleAPI) {
|
||||
})
|
||||
// Set Policy
|
||||
api.AdminAPISetPolicyHandler = admin_api.SetPolicyHandlerFunc(func(params admin_api.SetPolicyParams, session *models.Principal) middleware.Responder {
|
||||
if err := getSetPolicyResponse(session, params.Name, params.Body); err != nil {
|
||||
if err := getSetPolicyResponse(session, params.Body); err != nil {
|
||||
return admin_api.NewSetPolicyDefault(int(err.Code)).WithPayload(err)
|
||||
}
|
||||
return admin_api.NewSetPolicyNoContent()
|
||||
})
|
||||
// Set Policy Multiple User/Groups
|
||||
api.AdminAPISetPolicyMultipleHandler = admin_api.SetPolicyMultipleHandlerFunc(func(params admin_api.SetPolicyMultipleParams, session *models.Principal) middleware.Responder {
|
||||
if err := getSetPolicyMultipleResponse(session, params.Name, params.Body); err != nil {
|
||||
if err := getSetPolicyMultipleResponse(session, params.Body); err != nil {
|
||||
return admin_api.NewSetPolicyMultipleDefault(int(err.Code)).WithPayload(err)
|
||||
}
|
||||
return admin_api.NewSetPolicyMultipleNoContent()
|
||||
@@ -429,11 +430,12 @@ func setPolicy(ctx context.Context, client MinioAdmin, name, entityName string,
|
||||
}
|
||||
|
||||
// getSetPolicyResponse() performs setPolicy() and serializes it to the handler's output
|
||||
func getSetPolicyResponse(session *models.Principal, name string, params *models.SetPolicyRequest) *models.Error {
|
||||
func getSetPolicyResponse(session *models.Principal, params *models.SetPolicyNameRequest) *models.Error {
|
||||
ctx := context.Background()
|
||||
if name == "" {
|
||||
return prepareError(errPolicyNameNotInRequest)
|
||||
}
|
||||
// if len(params.Name) == 0 {
|
||||
// return prepareError(errPolicyNameNotInRequest)
|
||||
// }
|
||||
// Removing this section
|
||||
mAdmin, err := NewMinioAdminClient(session)
|
||||
if err != nil {
|
||||
return prepareError(err)
|
||||
@@ -442,13 +444,13 @@ func getSetPolicyResponse(session *models.Principal, name string, params *models
|
||||
// defining the client to be used
|
||||
adminClient := AdminClient{Client: mAdmin}
|
||||
|
||||
if err := setPolicy(ctx, adminClient, name, *params.EntityName, *params.EntityType); err != nil {
|
||||
if err := setPolicy(ctx, adminClient, strings.Join(params.Name, ","), *params.EntityName, *params.EntityType); err != nil {
|
||||
return prepareError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getSetPolicyMultipleResponse(session *models.Principal, name string, params *models.SetPolicyMultipleRequest) *models.Error {
|
||||
func getSetPolicyMultipleResponse(session *models.Principal, params *models.SetPolicyMultipleNameRequest) *models.Error {
|
||||
ctx := context.Background()
|
||||
mAdmin, err := NewMinioAdminClient(session)
|
||||
if err != nil {
|
||||
@@ -458,7 +460,7 @@ func getSetPolicyMultipleResponse(session *models.Principal, name string, params
|
||||
// defining the client to be used
|
||||
adminClient := AdminClient{Client: mAdmin}
|
||||
|
||||
if err := setPolicyMultipleEntities(ctx, adminClient, name, params.Users, params.Groups); err != nil {
|
||||
if err := setPolicyMultipleEntities(ctx, adminClient, strings.Join(params.Name, ","), params.Users, params.Groups); err != nil {
|
||||
return prepareError(err)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -2991,26 +2991,20 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/set-policy-multi/{name}": {
|
||||
"/set-policy": {
|
||||
"put": {
|
||||
"tags": [
|
||||
"AdminAPI"
|
||||
],
|
||||
"summary": "Set policy to multiple users/groups",
|
||||
"operationId": "SetPolicyMultiple",
|
||||
"summary": "Set policy",
|
||||
"operationId": "SetPolicy",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/setPolicyMultipleRequest"
|
||||
"$ref": "#/definitions/setPolicyNameRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -3027,26 +3021,20 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/set-policy/{name}": {
|
||||
"/set-policy-multi": {
|
||||
"put": {
|
||||
"tags": [
|
||||
"AdminAPI"
|
||||
],
|
||||
"summary": "Set policy",
|
||||
"operationId": "SetPolicy",
|
||||
"summary": "Set policy to multiple users/groups",
|
||||
"operationId": "SetPolicyMultiple",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/setPolicyRequest"
|
||||
"$ref": "#/definitions/setPolicyMultipleNameRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -5180,7 +5168,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"setPolicyMultipleRequest": {
|
||||
"setPolicyMultipleNameRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"groups": {
|
||||
@@ -5189,6 +5177,12 @@ func init() {
|
||||
"$ref": "#/definitions/iamEntity"
|
||||
}
|
||||
},
|
||||
"name": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"users": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -5197,6 +5191,28 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"setPolicyNameRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"entityType",
|
||||
"entityName"
|
||||
],
|
||||
"properties": {
|
||||
"entityName": {
|
||||
"type": "string"
|
||||
},
|
||||
"entityType": {
|
||||
"$ref": "#/definitions/policyEntity"
|
||||
},
|
||||
"name": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"setPolicyRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -8535,26 +8551,20 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/set-policy-multi/{name}": {
|
||||
"/set-policy": {
|
||||
"put": {
|
||||
"tags": [
|
||||
"AdminAPI"
|
||||
],
|
||||
"summary": "Set policy to multiple users/groups",
|
||||
"operationId": "SetPolicyMultiple",
|
||||
"summary": "Set policy",
|
||||
"operationId": "SetPolicy",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/setPolicyMultipleRequest"
|
||||
"$ref": "#/definitions/setPolicyNameRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -8571,26 +8581,20 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/set-policy/{name}": {
|
||||
"/set-policy-multi": {
|
||||
"put": {
|
||||
"tags": [
|
||||
"AdminAPI"
|
||||
],
|
||||
"summary": "Set policy",
|
||||
"operationId": "SetPolicy",
|
||||
"summary": "Set policy to multiple users/groups",
|
||||
"operationId": "SetPolicyMultiple",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "name",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/setPolicyRequest"
|
||||
"$ref": "#/definitions/setPolicyMultipleNameRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -10778,7 +10782,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"setPolicyMultipleRequest": {
|
||||
"setPolicyMultipleNameRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"groups": {
|
||||
@@ -10787,6 +10791,12 @@ func init() {
|
||||
"$ref": "#/definitions/iamEntity"
|
||||
}
|
||||
},
|
||||
"name": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"users": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -10795,6 +10805,28 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"setPolicyNameRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"entityType",
|
||||
"entityName"
|
||||
],
|
||||
"properties": {
|
||||
"entityName": {
|
||||
"type": "string"
|
||||
},
|
||||
"entityType": {
|
||||
"$ref": "#/definitions/policyEntity"
|
||||
},
|
||||
"name": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"setPolicyRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
||||
@@ -48,7 +48,7 @@ func NewSetPolicy(ctx *middleware.Context, handler SetPolicyHandler) *SetPolicy
|
||||
return &SetPolicy{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/* SetPolicy swagger:route PUT /set-policy/{name} AdminAPI setPolicy
|
||||
/* SetPolicy swagger:route PUT /set-policy AdminAPI setPolicy
|
||||
|
||||
Set policy
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func NewSetPolicyMultiple(ctx *middleware.Context, handler SetPolicyMultipleHand
|
||||
return &SetPolicyMultiple{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/* SetPolicyMultiple swagger:route PUT /set-policy-multi/{name} AdminAPI setPolicyMultiple
|
||||
/* SetPolicyMultiple swagger:route PUT /set-policy-multi AdminAPI setPolicyMultiple
|
||||
|
||||
Set policy to multiple users/groups
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"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"
|
||||
@@ -57,12 +56,7 @@ type SetPolicyMultipleParams struct {
|
||||
Required: true
|
||||
In: body
|
||||
*/
|
||||
Body *models.SetPolicyMultipleRequest
|
||||
/*
|
||||
Required: true
|
||||
In: path
|
||||
*/
|
||||
Name string
|
||||
Body *models.SetPolicyMultipleNameRequest
|
||||
}
|
||||
|
||||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
@@ -76,7 +70,7 @@ func (o *SetPolicyMultipleParams) BindRequest(r *http.Request, route *middleware
|
||||
|
||||
if runtime.HasBody(r) {
|
||||
defer r.Body.Close()
|
||||
var body models.SetPolicyMultipleRequest
|
||||
var body models.SetPolicyMultipleNameRequest
|
||||
if err := route.Consumer.Consume(r.Body, &body); err != nil {
|
||||
if err == io.EOF {
|
||||
res = append(res, errors.Required("body", "body", ""))
|
||||
@@ -101,27 +95,8 @@ func (o *SetPolicyMultipleParams) BindRequest(r *http.Request, route *middleware
|
||||
} else {
|
||||
res = append(res, errors.Required("body", "body", ""))
|
||||
}
|
||||
|
||||
rName, rhkName, _ := route.Params.GetOK("name")
|
||||
if err := o.bindName(rName, rhkName, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindName binds and validates parameter Name from path.
|
||||
func (o *SetPolicyMultipleParams) bindName(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.Name = raw
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,16 +26,11 @@ import (
|
||||
"errors"
|
||||
"net/url"
|
||||
golangswaggerpaths "path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SetPolicyMultipleURL generates an URL for the set policy multiple operation
|
||||
type SetPolicyMultipleURL struct {
|
||||
Name string
|
||||
|
||||
_basePath string
|
||||
// avoid unkeyed usage
|
||||
_ struct{}
|
||||
}
|
||||
|
||||
// WithBasePath sets the base path for this url builder, only required when it's different from the
|
||||
@@ -57,14 +52,7 @@ func (o *SetPolicyMultipleURL) SetBasePath(bp string) {
|
||||
func (o *SetPolicyMultipleURL) Build() (*url.URL, error) {
|
||||
var _result url.URL
|
||||
|
||||
var _path = "/set-policy-multi/{name}"
|
||||
|
||||
name := o.Name
|
||||
if name != "" {
|
||||
_path = strings.Replace(_path, "{name}", name, -1)
|
||||
} else {
|
||||
return nil, errors.New("name is required on SetPolicyMultipleURL")
|
||||
}
|
||||
var _path = "/set-policy-multi"
|
||||
|
||||
_basePath := o._basePath
|
||||
if _basePath == "" {
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"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"
|
||||
@@ -57,12 +56,7 @@ type SetPolicyParams struct {
|
||||
Required: true
|
||||
In: body
|
||||
*/
|
||||
Body *models.SetPolicyRequest
|
||||
/*
|
||||
Required: true
|
||||
In: path
|
||||
*/
|
||||
Name string
|
||||
Body *models.SetPolicyNameRequest
|
||||
}
|
||||
|
||||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
@@ -76,7 +70,7 @@ func (o *SetPolicyParams) BindRequest(r *http.Request, route *middleware.Matched
|
||||
|
||||
if runtime.HasBody(r) {
|
||||
defer r.Body.Close()
|
||||
var body models.SetPolicyRequest
|
||||
var body models.SetPolicyNameRequest
|
||||
if err := route.Consumer.Consume(r.Body, &body); err != nil {
|
||||
if err == io.EOF {
|
||||
res = append(res, errors.Required("body", "body", ""))
|
||||
@@ -101,27 +95,8 @@ func (o *SetPolicyParams) BindRequest(r *http.Request, route *middleware.Matched
|
||||
} else {
|
||||
res = append(res, errors.Required("body", "body", ""))
|
||||
}
|
||||
|
||||
rName, rhkName, _ := route.Params.GetOK("name")
|
||||
if err := o.bindName(rName, rhkName, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindName binds and validates parameter Name from path.
|
||||
func (o *SetPolicyParams) bindName(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.Name = raw
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,16 +26,11 @@ import (
|
||||
"errors"
|
||||
"net/url"
|
||||
golangswaggerpaths "path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// SetPolicyURL generates an URL for the set policy operation
|
||||
type SetPolicyURL struct {
|
||||
Name string
|
||||
|
||||
_basePath string
|
||||
// avoid unkeyed usage
|
||||
_ struct{}
|
||||
}
|
||||
|
||||
// WithBasePath sets the base path for this url builder, only required when it's different from the
|
||||
@@ -57,14 +52,7 @@ func (o *SetPolicyURL) SetBasePath(bp string) {
|
||||
func (o *SetPolicyURL) Build() (*url.URL, error) {
|
||||
var _result url.URL
|
||||
|
||||
var _path = "/set-policy/{name}"
|
||||
|
||||
name := o.Name
|
||||
if name != "" {
|
||||
_path = strings.Replace(_path, "{name}", name, -1)
|
||||
} else {
|
||||
return nil, errors.New("name is required on SetPolicyURL")
|
||||
}
|
||||
var _path = "/set-policy"
|
||||
|
||||
_basePath := o._basePath
|
||||
if _basePath == "" {
|
||||
|
||||
@@ -1452,11 +1452,11 @@ func (o *ConsoleAPI) initHandlerCache() {
|
||||
if o.handlers["PUT"] == nil {
|
||||
o.handlers["PUT"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["PUT"]["/set-policy/{name}"] = admin_api.NewSetPolicy(o.context, o.AdminAPISetPolicyHandler)
|
||||
o.handlers["PUT"]["/set-policy"] = admin_api.NewSetPolicy(o.context, o.AdminAPISetPolicyHandler)
|
||||
if o.handlers["PUT"] == nil {
|
||||
o.handlers["PUT"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["PUT"]["/set-policy-multi/{name}"] = admin_api.NewSetPolicyMultiple(o.context, o.AdminAPISetPolicyMultipleHandler)
|
||||
o.handlers["PUT"]["/set-policy-multi"] = admin_api.NewSetPolicyMultiple(o.context, o.AdminAPISetPolicyMultipleHandler)
|
||||
if o.handlers["GET"] == nil {
|
||||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user