Admin Info API (#13)

* Admin Info API

* Address comments

* Fix tests
This commit is contained in:
Daniel Valdivia
2020-04-02 20:15:39 -07:00
committed by GitHub
parent 768c7c70a3
commit 35877973a9
15 changed files with 1095 additions and 357 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) 2020 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/m3/mcs/models"
)
// AdminInfoHandlerFunc turns a function with the right signature into a admin info handler
type AdminInfoHandlerFunc func(AdminInfoParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn AdminInfoHandlerFunc) Handle(params AdminInfoParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// AdminInfoHandler interface for that can handle valid admin info params
type AdminInfoHandler interface {
Handle(AdminInfoParams, *models.Principal) middleware.Responder
}
// NewAdminInfo creates a new http.Handler for the admin info operation
func NewAdminInfo(ctx *middleware.Context, handler AdminInfoHandler) *AdminInfo {
return &AdminInfo{Context: ctx, Handler: handler}
}
/*AdminInfo swagger:route GET /api/v1/admin/info AdminAPI adminInfo
Returns information about the deployment
*/
type AdminInfo struct {
Context *middleware.Context
Handler AdminInfoHandler
}
func (o *AdminInfo) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
r = rCtx
}
var Params = NewAdminInfoParams()
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,62 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2020 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/middleware"
)
// NewAdminInfoParams creates a new AdminInfoParams object
// no default values defined in spec.
func NewAdminInfoParams() AdminInfoParams {
return AdminInfoParams{}
}
// AdminInfoParams contains all the bound params for the admin info operation
// typically these are obtained from a http.Request
//
// swagger:parameters AdminInfo
type AdminInfoParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
}
// 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 NewAdminInfoParams() beforehand.
func (o *AdminInfoParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
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) 2020 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/m3/mcs/models"
)
// AdminInfoOKCode is the HTTP code returned for type AdminInfoOK
const AdminInfoOKCode int = 200
/*AdminInfoOK A successful response.
swagger:response adminInfoOK
*/
type AdminInfoOK struct {
/*
In: Body
*/
Payload *models.AdminInfoResponse `json:"body,omitempty"`
}
// NewAdminInfoOK creates AdminInfoOK with default headers values
func NewAdminInfoOK() *AdminInfoOK {
return &AdminInfoOK{}
}
// WithPayload adds the payload to the admin info o k response
func (o *AdminInfoOK) WithPayload(payload *models.AdminInfoResponse) *AdminInfoOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the admin info o k response
func (o *AdminInfoOK) SetPayload(payload *models.AdminInfoResponse) {
o.Payload = payload
}
// WriteResponse to the client
func (o *AdminInfoOK) 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
}
}
}
/*AdminInfoDefault Generic error response.
swagger:response adminInfoDefault
*/
type AdminInfoDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewAdminInfoDefault creates AdminInfoDefault with default headers values
func NewAdminInfoDefault(code int) *AdminInfoDefault {
if code <= 0 {
code = 500
}
return &AdminInfoDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the admin info default response
func (o *AdminInfoDefault) WithStatusCode(code int) *AdminInfoDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the admin info default response
func (o *AdminInfoDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the admin info default response
func (o *AdminInfoDefault) WithPayload(payload *models.Error) *AdminInfoDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the admin info default response
func (o *AdminInfoDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *AdminInfoDefault) 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,101 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2020 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"
)
// AdminInfoURL generates an URL for the admin info operation
type AdminInfoURL struct {
_basePath string
}
// 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 *AdminInfoURL) WithBasePath(bp string) *AdminInfoURL {
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 *AdminInfoURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *AdminInfoURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/api/v1/admin/info"
_basePath := o._basePath
_result.Path = golangswaggerpaths.Join(_basePath, _path)
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *AdminInfoURL) 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 *AdminInfoURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *AdminInfoURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on AdminInfoURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on AdminInfoURL")
}
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 *AdminInfoURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -72,6 +72,9 @@ func NewMcsAPI(spec *loads.Document) *McsAPI {
AdminAPIAddUserHandler: admin_api.AddUserHandlerFunc(func(params admin_api.AddUserParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.AddUser has not yet been implemented")
}),
AdminAPIAdminInfoHandler: admin_api.AdminInfoHandlerFunc(func(params admin_api.AdminInfoParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.AdminInfo has not yet been implemented")
}),
UserAPIBucketInfoHandler: user_api.BucketInfoHandlerFunc(func(params user_api.BucketInfoParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.BucketInfo has not yet been implemented")
}),
@@ -202,6 +205,8 @@ type McsAPI struct {
AdminAPIAddPolicyHandler admin_api.AddPolicyHandler
// AdminAPIAddUserHandler sets the operation handler for the add user operation
AdminAPIAddUserHandler admin_api.AddUserHandler
// AdminAPIAdminInfoHandler sets the operation handler for the admin info operation
AdminAPIAdminInfoHandler admin_api.AdminInfoHandler
// UserAPIBucketInfoHandler sets the operation handler for the bucket info operation
UserAPIBucketInfoHandler user_api.BucketInfoHandler
// UserAPIBucketSetPolicyHandler sets the operation handler for the bucket set policy operation
@@ -334,6 +339,9 @@ func (o *McsAPI) Validate() error {
if o.AdminAPIAddUserHandler == nil {
unregistered = append(unregistered, "admin_api.AddUserHandler")
}
if o.AdminAPIAdminInfoHandler == nil {
unregistered = append(unregistered, "admin_api.AdminInfoHandler")
}
if o.UserAPIBucketInfoHandler == nil {
unregistered = append(unregistered, "user_api.BucketInfoHandler")
}
@@ -524,6 +532,10 @@ func (o *McsAPI) initHandlerCache() {
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/api/v1/admin/info"] = admin_api.NewAdminInfo(o.context, o.AdminAPIAdminInfoHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/api/v1/buckets/{name}"] = user_api.NewBucketInfo(o.context, o.UserAPIBucketInfoHandler)
if o.handlers["PUT"] == nil {
o.handlers["PUT"] = make(map[string]http.Handler)