Use Console as proxy for share object logic (#3284)
This commit is contained in:
@@ -49,6 +49,7 @@ import (
|
||||
"github.com/minio/console/api/operations/object"
|
||||
"github.com/minio/console/api/operations/policy"
|
||||
"github.com/minio/console/api/operations/profile"
|
||||
"github.com/minio/console/api/operations/public"
|
||||
"github.com/minio/console/api/operations/release"
|
||||
"github.com/minio/console/api/operations/service"
|
||||
"github.com/minio/console/api/operations/service_account"
|
||||
@@ -211,6 +212,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
|
||||
ObjectDownloadMultipleObjectsHandler: object.DownloadMultipleObjectsHandlerFunc(func(params object.DownloadMultipleObjectsParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation object.DownloadMultipleObjects has not yet been implemented")
|
||||
}),
|
||||
PublicDownloadSharedObjectHandler: public.DownloadSharedObjectHandlerFunc(func(params public.DownloadSharedObjectParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation public.DownloadSharedObject has not yet been implemented")
|
||||
}),
|
||||
TieringEditTierCredentialsHandler: tiering.EditTierCredentialsHandlerFunc(func(params tiering.EditTierCredentialsParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation tiering.EditTierCredentials has not yet been implemented")
|
||||
}),
|
||||
@@ -704,6 +708,8 @@ type ConsoleAPI struct {
|
||||
ObjectDownloadObjectHandler object.DownloadObjectHandler
|
||||
// ObjectDownloadMultipleObjectsHandler sets the operation handler for the download multiple objects operation
|
||||
ObjectDownloadMultipleObjectsHandler object.DownloadMultipleObjectsHandler
|
||||
// PublicDownloadSharedObjectHandler sets the operation handler for the download shared object operation
|
||||
PublicDownloadSharedObjectHandler public.DownloadSharedObjectHandler
|
||||
// TieringEditTierCredentialsHandler sets the operation handler for the edit tier credentials operation
|
||||
TieringEditTierCredentialsHandler tiering.EditTierCredentialsHandler
|
||||
// BucketEnableBucketEncryptionHandler sets the operation handler for the enable bucket encryption operation
|
||||
@@ -1150,6 +1156,9 @@ func (o *ConsoleAPI) Validate() error {
|
||||
if o.ObjectDownloadMultipleObjectsHandler == nil {
|
||||
unregistered = append(unregistered, "object.DownloadMultipleObjectsHandler")
|
||||
}
|
||||
if o.PublicDownloadSharedObjectHandler == nil {
|
||||
unregistered = append(unregistered, "public.DownloadSharedObjectHandler")
|
||||
}
|
||||
if o.TieringEditTierCredentialsHandler == nil {
|
||||
unregistered = append(unregistered, "tiering.EditTierCredentialsHandler")
|
||||
}
|
||||
@@ -1769,6 +1778,10 @@ func (o *ConsoleAPI) initHandlerCache() {
|
||||
o.handlers["POST"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["POST"]["/buckets/{bucket_name}/objects/download-multiple"] = object.NewDownloadMultipleObjects(o.context, o.ObjectDownloadMultipleObjectsHandler)
|
||||
if o.handlers["GET"] == nil {
|
||||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["GET"]["/download-shared-object/{url}"] = public.NewDownloadSharedObject(o.context, o.PublicDownloadSharedObjectHandler)
|
||||
if o.handlers["PUT"] == nil {
|
||||
o.handlers["PUT"] = make(map[string]http.Handler)
|
||||
}
|
||||
|
||||
73
api/operations/public/download_shared_object.go
Normal file
73
api/operations/public/download_shared_object.go
Normal file
@@ -0,0 +1,73 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2023 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 public
|
||||
|
||||
// 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"
|
||||
)
|
||||
|
||||
// DownloadSharedObjectHandlerFunc turns a function with the right signature into a download shared object handler
|
||||
type DownloadSharedObjectHandlerFunc func(DownloadSharedObjectParams) middleware.Responder
|
||||
|
||||
// Handle executing the request and returning a response
|
||||
func (fn DownloadSharedObjectHandlerFunc) Handle(params DownloadSharedObjectParams) middleware.Responder {
|
||||
return fn(params)
|
||||
}
|
||||
|
||||
// DownloadSharedObjectHandler interface for that can handle valid download shared object params
|
||||
type DownloadSharedObjectHandler interface {
|
||||
Handle(DownloadSharedObjectParams) middleware.Responder
|
||||
}
|
||||
|
||||
// NewDownloadSharedObject creates a new http.Handler for the download shared object operation
|
||||
func NewDownloadSharedObject(ctx *middleware.Context, handler DownloadSharedObjectHandler) *DownloadSharedObject {
|
||||
return &DownloadSharedObject{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/*
|
||||
DownloadSharedObject swagger:route GET /download-shared-object/{url} Public downloadSharedObject
|
||||
|
||||
Downloads an object from a presigned url
|
||||
*/
|
||||
type DownloadSharedObject struct {
|
||||
Context *middleware.Context
|
||||
Handler DownloadSharedObjectHandler
|
||||
}
|
||||
|
||||
func (o *DownloadSharedObject) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
route, rCtx, _ := o.Context.RouteInfo(r)
|
||||
if rCtx != nil {
|
||||
*r = *rCtx
|
||||
}
|
||||
var Params = NewDownloadSharedObjectParams()
|
||||
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) // actually handle the request
|
||||
o.Context.Respond(rw, r, route.Produces, route, res)
|
||||
|
||||
}
|
||||
88
api/operations/public/download_shared_object_parameters.go
Normal file
88
api/operations/public/download_shared_object_parameters.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2023 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 public
|
||||
|
||||
// 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"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// NewDownloadSharedObjectParams creates a new DownloadSharedObjectParams object
|
||||
//
|
||||
// There are no default values defined in the spec.
|
||||
func NewDownloadSharedObjectParams() DownloadSharedObjectParams {
|
||||
|
||||
return DownloadSharedObjectParams{}
|
||||
}
|
||||
|
||||
// DownloadSharedObjectParams contains all the bound params for the download shared object operation
|
||||
// typically these are obtained from a http.Request
|
||||
//
|
||||
// swagger:parameters DownloadSharedObject
|
||||
type DownloadSharedObjectParams struct {
|
||||
|
||||
// HTTP Request Object
|
||||
HTTPRequest *http.Request `json:"-"`
|
||||
|
||||
/*
|
||||
Required: true
|
||||
In: path
|
||||
*/
|
||||
URL 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 NewDownloadSharedObjectParams() beforehand.
|
||||
func (o *DownloadSharedObjectParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
var res []error
|
||||
|
||||
o.HTTPRequest = r
|
||||
|
||||
rURL, rhkURL, _ := route.Params.GetOK("url")
|
||||
if err := o.bindURL(rURL, rhkURL, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindURL binds and validates parameter URL from path.
|
||||
func (o *DownloadSharedObjectParams) bindURL(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.URL = raw
|
||||
|
||||
return nil
|
||||
}
|
||||
134
api/operations/public/download_shared_object_responses.go
Normal file
134
api/operations/public/download_shared_object_responses.go
Normal file
@@ -0,0 +1,134 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2023 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 public
|
||||
|
||||
// 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"
|
||||
)
|
||||
|
||||
// DownloadSharedObjectOKCode is the HTTP code returned for type DownloadSharedObjectOK
|
||||
const DownloadSharedObjectOKCode int = 200
|
||||
|
||||
/*
|
||||
DownloadSharedObjectOK A successful response.
|
||||
|
||||
swagger:response downloadSharedObjectOK
|
||||
*/
|
||||
type DownloadSharedObjectOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload io.ReadCloser `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewDownloadSharedObjectOK creates DownloadSharedObjectOK with default headers values
|
||||
func NewDownloadSharedObjectOK() *DownloadSharedObjectOK {
|
||||
|
||||
return &DownloadSharedObjectOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the download shared object o k response
|
||||
func (o *DownloadSharedObjectOK) WithPayload(payload io.ReadCloser) *DownloadSharedObjectOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the download shared object o k response
|
||||
func (o *DownloadSharedObjectOK) SetPayload(payload io.ReadCloser) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *DownloadSharedObjectOK) 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
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
DownloadSharedObjectDefault Generic error response.
|
||||
|
||||
swagger:response downloadSharedObjectDefault
|
||||
*/
|
||||
type DownloadSharedObjectDefault struct {
|
||||
_statusCode int
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.APIError `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewDownloadSharedObjectDefault creates DownloadSharedObjectDefault with default headers values
|
||||
func NewDownloadSharedObjectDefault(code int) *DownloadSharedObjectDefault {
|
||||
if code <= 0 {
|
||||
code = 500
|
||||
}
|
||||
|
||||
return &DownloadSharedObjectDefault{
|
||||
_statusCode: code,
|
||||
}
|
||||
}
|
||||
|
||||
// WithStatusCode adds the status to the download shared object default response
|
||||
func (o *DownloadSharedObjectDefault) WithStatusCode(code int) *DownloadSharedObjectDefault {
|
||||
o._statusCode = code
|
||||
return o
|
||||
}
|
||||
|
||||
// SetStatusCode sets the status to the download shared object default response
|
||||
func (o *DownloadSharedObjectDefault) SetStatusCode(code int) {
|
||||
o._statusCode = code
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the download shared object default response
|
||||
func (o *DownloadSharedObjectDefault) WithPayload(payload *models.APIError) *DownloadSharedObjectDefault {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the download shared object default response
|
||||
func (o *DownloadSharedObjectDefault) SetPayload(payload *models.APIError) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *DownloadSharedObjectDefault) 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
|
||||
}
|
||||
}
|
||||
}
|
||||
116
api/operations/public/download_shared_object_urlbuilder.go
Normal file
116
api/operations/public/download_shared_object_urlbuilder.go
Normal file
@@ -0,0 +1,116 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2023 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 public
|
||||
|
||||
// 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"
|
||||
)
|
||||
|
||||
// DownloadSharedObjectURL generates an URL for the download shared object operation
|
||||
type DownloadSharedObjectURL struct {
|
||||
URL 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 *DownloadSharedObjectURL) WithBasePath(bp string) *DownloadSharedObjectURL {
|
||||
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 *DownloadSharedObjectURL) SetBasePath(bp string) {
|
||||
o._basePath = bp
|
||||
}
|
||||
|
||||
// Build a url path and query string
|
||||
func (o *DownloadSharedObjectURL) Build() (*url.URL, error) {
|
||||
var _result url.URL
|
||||
|
||||
var _path = "/download-shared-object/{url}"
|
||||
|
||||
url := o.URL
|
||||
if url != "" {
|
||||
_path = strings.Replace(_path, "{url}", url, -1)
|
||||
} else {
|
||||
return nil, errors.New("url is required on DownloadSharedObjectURL")
|
||||
}
|
||||
|
||||
_basePath := o._basePath
|
||||
if _basePath == "" {
|
||||
_basePath = "/api/v1"
|
||||
}
|
||||
_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 *DownloadSharedObjectURL) 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 *DownloadSharedObjectURL) String() string {
|
||||
return o.Must(o.Build()).String()
|
||||
}
|
||||
|
||||
// BuildFull builds a full url with scheme, host, path and query string
|
||||
func (o *DownloadSharedObjectURL) BuildFull(scheme, host string) (*url.URL, error) {
|
||||
if scheme == "" {
|
||||
return nil, errors.New("scheme is required for a full url on DownloadSharedObjectURL")
|
||||
}
|
||||
if host == "" {
|
||||
return nil, errors.New("host is required for a full url on DownloadSharedObjectURL")
|
||||
}
|
||||
|
||||
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 *DownloadSharedObjectURL) StringFull(scheme, host string) string {
|
||||
return o.Must(o.BuildFull(scheme, host)).String()
|
||||
}
|
||||
Reference in New Issue
Block a user