api for listing policies attatched to a bucket (#660)

api for listing policies attatched to a bucket
This commit is contained in:
adfost
2021-03-19 16:00:56 -07:00
committed by GitHub
parent 934e8c9f4c
commit 26f7982323
9 changed files with 829 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package admin_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"net/http"
"github.com/go-openapi/runtime/middleware"
"github.com/minio/console/models"
)
// ListPoliciesWithBucketHandlerFunc turns a function with the right signature into a list policies with bucket handler
type ListPoliciesWithBucketHandlerFunc func(ListPoliciesWithBucketParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn ListPoliciesWithBucketHandlerFunc) Handle(params ListPoliciesWithBucketParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// ListPoliciesWithBucketHandler interface for that can handle valid list policies with bucket params
type ListPoliciesWithBucketHandler interface {
Handle(ListPoliciesWithBucketParams, *models.Principal) middleware.Responder
}
// NewListPoliciesWithBucket creates a new http.Handler for the list policies with bucket operation
func NewListPoliciesWithBucket(ctx *middleware.Context, handler ListPoliciesWithBucketHandler) *ListPoliciesWithBucket {
return &ListPoliciesWithBucket{Context: ctx, Handler: handler}
}
/*ListPoliciesWithBucket swagger:route GET /bucket-policy/{bucket} AdminAPI listPoliciesWithBucket
List Policies With Given Bucket
*/
type ListPoliciesWithBucket struct {
Context *middleware.Context
Handler ListPoliciesWithBucketHandler
}
func (o *ListPoliciesWithBucket) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
r = rCtx
}
var Params = NewListPoliciesWithBucketParams()
uprinc, aCtx, err := o.Context.Authorize(r, route)
if err != nil {
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
if aCtx != nil {
r = aCtx
}
var principal *models.Principal
if uprinc != nil {
principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise
}
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
res := o.Handler.Handle(Params, principal) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}

View File

@@ -0,0 +1,155 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package admin_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"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/swag"
)
// NewListPoliciesWithBucketParams creates a new ListPoliciesWithBucketParams object
// no default values defined in spec.
func NewListPoliciesWithBucketParams() ListPoliciesWithBucketParams {
return ListPoliciesWithBucketParams{}
}
// ListPoliciesWithBucketParams contains all the bound params for the list policies with bucket operation
// typically these are obtained from a http.Request
//
// swagger:parameters ListPoliciesWithBucket
type ListPoliciesWithBucketParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
Required: true
In: path
*/
Bucket string
/*
In: query
*/
Limit *int32
/*
In: query
*/
Offset *int32
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewListPoliciesWithBucketParams() beforehand.
func (o *ListPoliciesWithBucketParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
qs := runtime.Values(r.URL.Query())
rBucket, rhkBucket, _ := route.Params.GetOK("bucket")
if err := o.bindBucket(rBucket, rhkBucket, route.Formats); err != nil {
res = append(res, err)
}
qLimit, qhkLimit, _ := qs.GetOK("limit")
if err := o.bindLimit(qLimit, qhkLimit, route.Formats); err != nil {
res = append(res, err)
}
qOffset, qhkOffset, _ := qs.GetOK("offset")
if err := o.bindOffset(qOffset, qhkOffset, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindBucket binds and validates parameter Bucket from path.
func (o *ListPoliciesWithBucketParams) bindBucket(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.Bucket = raw
return nil
}
// bindLimit binds and validates parameter Limit from query.
func (o *ListPoliciesWithBucketParams) bindLimit(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: false
// AllowEmptyValue: false
if raw == "" { // empty values pass all other validations
return nil
}
value, err := swag.ConvertInt32(raw)
if err != nil {
return errors.InvalidType("limit", "query", "int32", raw)
}
o.Limit = &value
return nil
}
// bindOffset binds and validates parameter Offset from query.
func (o *ListPoliciesWithBucketParams) bindOffset(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: false
// AllowEmptyValue: false
if raw == "" { // empty values pass all other validations
return nil
}
value, err := swag.ConvertInt32(raw)
if err != nil {
return errors.InvalidType("offset", "query", "int32", raw)
}
o.Offset = &value
return nil
}

View File

@@ -0,0 +1,133 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package admin_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/minio/console/models"
)
// ListPoliciesWithBucketOKCode is the HTTP code returned for type ListPoliciesWithBucketOK
const ListPoliciesWithBucketOKCode int = 200
/*ListPoliciesWithBucketOK A successful response.
swagger:response listPoliciesWithBucketOK
*/
type ListPoliciesWithBucketOK struct {
/*
In: Body
*/
Payload *models.ListPoliciesResponse `json:"body,omitempty"`
}
// NewListPoliciesWithBucketOK creates ListPoliciesWithBucketOK with default headers values
func NewListPoliciesWithBucketOK() *ListPoliciesWithBucketOK {
return &ListPoliciesWithBucketOK{}
}
// WithPayload adds the payload to the list policies with bucket o k response
func (o *ListPoliciesWithBucketOK) WithPayload(payload *models.ListPoliciesResponse) *ListPoliciesWithBucketOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the list policies with bucket o k response
func (o *ListPoliciesWithBucketOK) SetPayload(payload *models.ListPoliciesResponse) {
o.Payload = payload
}
// WriteResponse to the client
func (o *ListPoliciesWithBucketOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}
/*ListPoliciesWithBucketDefault Generic error response.
swagger:response listPoliciesWithBucketDefault
*/
type ListPoliciesWithBucketDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewListPoliciesWithBucketDefault creates ListPoliciesWithBucketDefault with default headers values
func NewListPoliciesWithBucketDefault(code int) *ListPoliciesWithBucketDefault {
if code <= 0 {
code = 500
}
return &ListPoliciesWithBucketDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the list policies with bucket default response
func (o *ListPoliciesWithBucketDefault) WithStatusCode(code int) *ListPoliciesWithBucketDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the list policies with bucket default response
func (o *ListPoliciesWithBucketDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the list policies with bucket default response
func (o *ListPoliciesWithBucketDefault) WithPayload(payload *models.Error) *ListPoliciesWithBucketDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the list policies with bucket default response
func (o *ListPoliciesWithBucketDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *ListPoliciesWithBucketDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(o._statusCode)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}

View File

@@ -0,0 +1,141 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package admin_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"errors"
"net/url"
golangswaggerpaths "path"
"strings"
"github.com/go-openapi/swag"
)
// ListPoliciesWithBucketURL generates an URL for the list policies with bucket operation
type ListPoliciesWithBucketURL struct {
Bucket string
Limit *int32
Offset *int32
_basePath string
// avoid unkeyed usage
_ struct{}
}
// WithBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *ListPoliciesWithBucketURL) WithBasePath(bp string) *ListPoliciesWithBucketURL {
o.SetBasePath(bp)
return o
}
// SetBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *ListPoliciesWithBucketURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *ListPoliciesWithBucketURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/bucket-policy/{bucket}"
bucket := o.Bucket
if bucket != "" {
_path = strings.Replace(_path, "{bucket}", bucket, -1)
} else {
return nil, errors.New("bucket is required on ListPoliciesWithBucketURL")
}
_basePath := o._basePath
if _basePath == "" {
_basePath = "/api/v1"
}
_result.Path = golangswaggerpaths.Join(_basePath, _path)
qs := make(url.Values)
var limitQ string
if o.Limit != nil {
limitQ = swag.FormatInt32(*o.Limit)
}
if limitQ != "" {
qs.Set("limit", limitQ)
}
var offsetQ string
if o.Offset != nil {
offsetQ = swag.FormatInt32(*o.Offset)
}
if offsetQ != "" {
qs.Set("offset", offsetQ)
}
_result.RawQuery = qs.Encode()
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *ListPoliciesWithBucketURL) Must(u *url.URL, err error) *url.URL {
if err != nil {
panic(err)
}
if u == nil {
panic("url can't be nil")
}
return u
}
// String returns the string representation of the path with query string
func (o *ListPoliciesWithBucketURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *ListPoliciesWithBucketURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on ListPoliciesWithBucketURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on ListPoliciesWithBucketURL")
}
base, err := o.Build()
if err != nil {
return nil, err
}
base.Scheme = scheme
base.Host = host
return base, nil
}
// StringFull returns the string representation of a complete url
func (o *ListPoliciesWithBucketURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -202,6 +202,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
AdminAPIListPoliciesHandler: admin_api.ListPoliciesHandlerFunc(func(params admin_api.ListPoliciesParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.ListPolicies has not yet been implemented")
}),
AdminAPIListPoliciesWithBucketHandler: admin_api.ListPoliciesWithBucketHandlerFunc(func(params admin_api.ListPoliciesWithBucketParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.ListPoliciesWithBucket has not yet been implemented")
}),
UserAPIListRemoteBucketsHandler: user_api.ListRemoteBucketsHandlerFunc(func(params user_api.ListRemoteBucketsParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.ListRemoteBuckets has not yet been implemented")
}),
@@ -478,6 +481,8 @@ type ConsoleAPI struct {
UserAPIListObjectsHandler user_api.ListObjectsHandler
// AdminAPIListPoliciesHandler sets the operation handler for the list policies operation
AdminAPIListPoliciesHandler admin_api.ListPoliciesHandler
// AdminAPIListPoliciesWithBucketHandler sets the operation handler for the list policies with bucket operation
AdminAPIListPoliciesWithBucketHandler admin_api.ListPoliciesWithBucketHandler
// UserAPIListRemoteBucketsHandler sets the operation handler for the list remote buckets operation
UserAPIListRemoteBucketsHandler user_api.ListRemoteBucketsHandler
// AdminAPIListTenantsHandler sets the operation handler for the list tenants operation
@@ -780,6 +785,9 @@ func (o *ConsoleAPI) Validate() error {
if o.AdminAPIListPoliciesHandler == nil {
unregistered = append(unregistered, "admin_api.ListPoliciesHandler")
}
if o.AdminAPIListPoliciesWithBucketHandler == nil {
unregistered = append(unregistered, "admin_api.ListPoliciesWithBucketHandler")
}
if o.UserAPIListRemoteBucketsHandler == nil {
unregistered = append(unregistered, "user_api.ListRemoteBucketsHandler")
}
@@ -1201,6 +1209,10 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/bucket-policy/{bucket}"] = admin_api.NewListPoliciesWithBucket(o.context, o.AdminAPIListPoliciesWithBucketHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/remote-buckets"] = user_api.NewListRemoteBuckets(o.context, o.UserAPIListRemoteBucketsHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)