Inspect API (#1540)

* Inspect API

* Address review comments

Co-authored-by: Alex <33497058+bexsoft@users.noreply.github.com>
Co-authored-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
This commit is contained in:
Prakash Senthil Vel
2022-02-16 00:14:51 +00:00
committed by GitHub
parent 3ae8e14156
commit 951d3bf6dc
10 changed files with 777 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
// 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"
)
// InspectHandlerFunc turns a function with the right signature into a inspect handler
type InspectHandlerFunc func(InspectParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn InspectHandlerFunc) Handle(params InspectParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// InspectHandler interface for that can handle valid inspect params
type InspectHandler interface {
Handle(InspectParams, *models.Principal) middleware.Responder
}
// NewInspect creates a new http.Handler for the inspect operation
func NewInspect(ctx *middleware.Context, handler InspectHandler) *Inspect {
return &Inspect{Context: ctx, Handler: handler}
}
/* Inspect swagger:route GET /admin/inspect AdminAPI inspect
Inspect Files on Drive
*/
type Inspect struct {
Context *middleware.Context
Handler InspectHandler
}
func (o *Inspect) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewInspectParams()
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,163 @@
// 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"
"github.com/go-openapi/validate"
)
// NewInspectParams creates a new InspectParams object
//
// There are no default values defined in the spec.
func NewInspectParams() InspectParams {
return InspectParams{}
}
// InspectParams contains all the bound params for the inspect operation
// typically these are obtained from a http.Request
//
// swagger:parameters Inspect
type InspectParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
In: query
*/
Encrypt *bool
/*
Required: true
In: query
*/
File string
/*
Required: true
In: query
*/
Volume string
}
// 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 NewInspectParams() beforehand.
func (o *InspectParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
qs := runtime.Values(r.URL.Query())
qEncrypt, qhkEncrypt, _ := qs.GetOK("encrypt")
if err := o.bindEncrypt(qEncrypt, qhkEncrypt, route.Formats); err != nil {
res = append(res, err)
}
qFile, qhkFile, _ := qs.GetOK("file")
if err := o.bindFile(qFile, qhkFile, route.Formats); err != nil {
res = append(res, err)
}
qVolume, qhkVolume, _ := qs.GetOK("volume")
if err := o.bindVolume(qVolume, qhkVolume, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindEncrypt binds and validates parameter Encrypt from query.
func (o *InspectParams) bindEncrypt(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.ConvertBool(raw)
if err != nil {
return errors.InvalidType("encrypt", "query", "bool", raw)
}
o.Encrypt = &value
return nil
}
// bindFile binds and validates parameter File from query.
func (o *InspectParams) bindFile(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("file", "query", rawData)
}
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// AllowEmptyValue: false
if err := validate.RequiredString("file", "query", raw); err != nil {
return err
}
o.File = raw
return nil
}
// bindVolume binds and validates parameter Volume from query.
func (o *InspectParams) bindVolume(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("volume", "query", rawData)
}
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// AllowEmptyValue: false
if err := validate.RequiredString("volume", "query", raw); err != nil {
return err
}
o.Volume = raw
return nil
}

View File

@@ -0,0 +1,132 @@
// 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 (
"io"
"net/http"
"github.com/go-openapi/runtime"
"github.com/minio/console/models"
)
// InspectOKCode is the HTTP code returned for type InspectOK
const InspectOKCode int = 200
/*InspectOK A successful response.
swagger:response inspectOK
*/
type InspectOK struct {
/*
In: Body
*/
Payload io.ReadCloser `json:"body,omitempty"`
}
// NewInspectOK creates InspectOK with default headers values
func NewInspectOK() *InspectOK {
return &InspectOK{}
}
// WithPayload adds the payload to the inspect o k response
func (o *InspectOK) WithPayload(payload io.ReadCloser) *InspectOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the inspect o k response
func (o *InspectOK) SetPayload(payload io.ReadCloser) {
o.Payload = payload
}
// WriteResponse to the client
func (o *InspectOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
/*InspectDefault Generic error response.
swagger:response inspectDefault
*/
type InspectDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewInspectDefault creates InspectDefault with default headers values
func NewInspectDefault(code int) *InspectDefault {
if code <= 0 {
code = 500
}
return &InspectDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the inspect default response
func (o *InspectDefault) WithStatusCode(code int) *InspectDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the inspect default response
func (o *InspectDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the inspect default response
func (o *InspectDefault) WithPayload(payload *models.Error) *InspectDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the inspect default response
func (o *InspectDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *InspectDefault) 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,134 @@
// 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"
"github.com/go-openapi/swag"
)
// InspectURL generates an URL for the inspect operation
type InspectURL struct {
Encrypt *bool
File string
Volume string
_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 *InspectURL) WithBasePath(bp string) *InspectURL {
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 *InspectURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *InspectURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/admin/inspect"
_basePath := o._basePath
if _basePath == "" {
_basePath = "/api/v1"
}
_result.Path = golangswaggerpaths.Join(_basePath, _path)
qs := make(url.Values)
var encryptQ string
if o.Encrypt != nil {
encryptQ = swag.FormatBool(*o.Encrypt)
}
if encryptQ != "" {
qs.Set("encrypt", encryptQ)
}
fileQ := o.File
if fileQ != "" {
qs.Set("file", fileQ)
}
volumeQ := o.Volume
if volumeQ != "" {
qs.Set("volume", volumeQ)
}
_result.RawQuery = qs.Encode()
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *InspectURL) 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 *InspectURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *InspectURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on InspectURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on InspectURL")
}
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 *InspectURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -218,6 +218,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
AdminAPIGroupInfoHandler: admin_api.GroupInfoHandlerFunc(func(params admin_api.GroupInfoParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.GroupInfo has not yet been implemented")
}),
AdminAPIInspectHandler: admin_api.InspectHandlerFunc(func(params admin_api.InspectParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.Inspect has not yet been implemented")
}),
AdminAPIListAUserServiceAccountsHandler: admin_api.ListAUserServiceAccountsHandlerFunc(func(params admin_api.ListAUserServiceAccountsParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.ListAUserServiceAccounts has not yet been implemented")
}),
@@ -555,6 +558,8 @@ type ConsoleAPI struct {
AdminAPIGetUserInfoHandler admin_api.GetUserInfoHandler
// AdminAPIGroupInfoHandler sets the operation handler for the group info operation
AdminAPIGroupInfoHandler admin_api.GroupInfoHandler
// AdminAPIInspectHandler sets the operation handler for the inspect operation
AdminAPIInspectHandler admin_api.InspectHandler
// AdminAPIListAUserServiceAccountsHandler sets the operation handler for the list a user service accounts operation
AdminAPIListAUserServiceAccountsHandler admin_api.ListAUserServiceAccountsHandler
// AdminAPIListAccessRulesWithBucketHandler sets the operation handler for the list access rules with bucket operation
@@ -915,6 +920,9 @@ func (o *ConsoleAPI) Validate() error {
if o.AdminAPIGroupInfoHandler == nil {
unregistered = append(unregistered, "admin_api.GroupInfoHandler")
}
if o.AdminAPIInspectHandler == nil {
unregistered = append(unregistered, "admin_api.InspectHandler")
}
if o.AdminAPIListAUserServiceAccountsHandler == nil {
unregistered = append(unregistered, "admin_api.ListAUserServiceAccountsHandler")
}
@@ -1404,6 +1412,10 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/admin/inspect"] = admin_api.NewInspect(o.context, o.AdminAPIInspectHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/user/{name}/service-accounts"] = admin_api.NewListAUserServiceAccounts(o.context, o.AdminAPIListAUserServiceAccountsHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)