Created a new API exclusive for metadata information (#1321)

Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
Alex
2021-12-15 10:50:34 -06:00
committed by GitHub
parent 3b2c740fe0
commit dd488e4f7a
13 changed files with 806 additions and 8 deletions

67
models/metadata.go Normal file
View File

@@ -0,0 +1,67 @@
// 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 models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// Metadata metadata
//
// swagger:model metadata
type Metadata struct {
// object metadata
ObjectMetadata interface{} `json:"objectMetadata,omitempty"`
}
// Validate validates this metadata
func (m *Metadata) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this metadata based on context it is used
func (m *Metadata) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *Metadata) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Metadata) UnmarshalBinary(b []byte) error {
var res Metadata
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -46,7 +46,7 @@ import {
hrClass,
searchField,
} from "../../../../Common/FormComponents/common/styleLibrary";
import { FileInfoResponse, IFileInfo } from "./types";
import { IFileInfo, MetadataResponse } from "./types";
import { download, extensionPreview } from "../utils";
import history from "../../../../../../history";
import api from "../../../../../../common/api";
@@ -232,7 +232,7 @@ const ObjectDetails = ({
}
useEffect(() => {
if (loadObjectData) {
if (loadObjectData && internalPaths !== "") {
api
.invoke(
"GET",
@@ -268,15 +268,14 @@ const ObjectDetails = ({
]);
useEffect(() => {
if (metadataLoad) {
if (metadataLoad && internalPaths !== "") {
api
.invoke(
"GET",
`/api/v1/buckets/${bucketName}/objects?prefix=${internalPaths}&with_metadata=true`
`/api/v1/buckets/${bucketName}/objects/metadata?prefix=${internalPaths}`
)
.then((res: FileInfoResponse) => {
const fileData = res.objects[0];
let metadata = get(fileData, "user_metadata", {});
.then((res: MetadataResponse) => {
let metadata = get(res, "objectMetadata", {});
setMetadata(metadata);
setMetadataLoad(false);
@@ -776,6 +775,14 @@ const ObjectDetails = ({
>
<TableBody>
{Object.keys(metadata).map((element, index) => {
const renderItem = Array.isArray(
metadata[element]
)
? metadata[element]
.map(decodeURIComponent)
.join(", ")
: decodeURIComponent(metadata[element]);
return (
<TableRow key={`tRow-${index.toString()}`}>
<TableCell
@@ -786,7 +793,7 @@ const ObjectDetails = ({
{element}
</TableCell>
<TableCell align="right">
{metadata[element]}
{renderItem}
</TableCell>
</TableRow>
);

View File

@@ -32,3 +32,7 @@ export interface FileInfoResponse {
objects: IFileInfo[];
total: number;
}
export interface MetadataResponse {
objectMetadata: object;
}

View File

@@ -66,6 +66,7 @@ type MinioClient interface {
putObject(ctx context.Context, bucketName, objectName string, reader io.Reader, objectSize int64, opts minio.PutObjectOptions) (info minio.UploadInfo, err error)
putObjectLegalHold(ctx context.Context, bucketName, objectName string, opts minio.PutObjectLegalHoldOptions) error
putObjectRetention(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error
statObject(ctx context.Context, bucketName, prefix string, opts minio.GetObjectOptions) (objectInfo minio.ObjectInfo, err error)
setBucketEncryption(ctx context.Context, bucketName string, config *sse.Configuration) error
removeBucketEncryption(ctx context.Context, bucketName string) error
getBucketEncryption(ctx context.Context, bucketName string) (*sse.Configuration, error)
@@ -170,6 +171,10 @@ func (c minioClient) putObjectRetention(ctx context.Context, bucketName, objectN
return c.client.PutObjectRetention(ctx, bucketName, objectName, opts)
}
func (c minioClient) statObject(ctx context.Context, bucketName, prefix string, opts minio.GetObjectOptions) (objectInfo minio.ObjectInfo, err error) {
return c.client.StatObject(ctx, bucketName, prefix, opts)
}
// implements minio.SetBucketEncryption(ctx, bucketName, config)
func (c minioClient) setBucketEncryption(ctx context.Context, bucketName string, config *sse.Configuration) error {
return c.client.SetBucketEncryption(ctx, bucketName, config)

View File

@@ -1300,6 +1300,43 @@ func init() {
}
}
},
"/buckets/{bucket_name}/objects/metadata": {
"get": {
"tags": [
"UserAPI"
],
"summary": "Gets the metadata of an object",
"operationId": "GetObjectMetadata",
"parameters": [
{
"type": "string",
"name": "bucket_name",
"in": "path",
"required": true
},
{
"type": "string",
"name": "prefix",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/metadata"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/buckets/{bucket_name}/objects/restore": {
"put": {
"tags": [
@@ -4554,6 +4591,15 @@ func init() {
}
}
},
"metadata": {
"type": "object",
"properties": {
"objectMetadata": {
"type": "object",
"additionalProperties": true
}
}
},
"multiBucketReplication": {
"required": [
"accessKey",
@@ -7025,6 +7071,43 @@ func init() {
}
}
},
"/buckets/{bucket_name}/objects/metadata": {
"get": {
"tags": [
"UserAPI"
],
"summary": "Gets the metadata of an object",
"operationId": "GetObjectMetadata",
"parameters": [
{
"type": "string",
"name": "bucket_name",
"in": "path",
"required": true
},
{
"type": "string",
"name": "prefix",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/metadata"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/buckets/{bucket_name}/objects/restore": {
"put": {
"tags": [
@@ -10399,6 +10482,15 @@ func init() {
}
}
},
"metadata": {
"type": "object",
"properties": {
"objectMetadata": {
"type": "object",
"additionalProperties": true
}
}
},
"multiBucketReplication": {
"required": [
"accessKey",

View File

@@ -191,6 +191,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
UserAPIGetBucketVersioningHandler: user_api.GetBucketVersioningHandlerFunc(func(params user_api.GetBucketVersioningParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.GetBucketVersioning has not yet been implemented")
}),
UserAPIGetObjectMetadataHandler: user_api.GetObjectMetadataHandlerFunc(func(params user_api.GetObjectMetadataParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation user_api.GetObjectMetadata has not yet been implemented")
}),
AdminAPIGetTierHandler: admin_api.GetTierHandlerFunc(func(params admin_api.GetTierParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.GetTier has not yet been implemented")
}),
@@ -504,6 +507,8 @@ type ConsoleAPI struct {
UserAPIGetBucketRewindHandler user_api.GetBucketRewindHandler
// UserAPIGetBucketVersioningHandler sets the operation handler for the get bucket versioning operation
UserAPIGetBucketVersioningHandler user_api.GetBucketVersioningHandler
// UserAPIGetObjectMetadataHandler sets the operation handler for the get object metadata operation
UserAPIGetObjectMetadataHandler user_api.GetObjectMetadataHandler
// AdminAPIGetTierHandler sets the operation handler for the get tier operation
AdminAPIGetTierHandler admin_api.GetTierHandler
// AdminAPIGetUserInfoHandler sets the operation handler for the get user info operation
@@ -833,6 +838,9 @@ func (o *ConsoleAPI) Validate() error {
if o.UserAPIGetBucketVersioningHandler == nil {
unregistered = append(unregistered, "user_api.GetBucketVersioningHandler")
}
if o.UserAPIGetObjectMetadataHandler == nil {
unregistered = append(unregistered, "user_api.GetObjectMetadataHandler")
}
if o.AdminAPIGetTierHandler == nil {
unregistered = append(unregistered, "admin_api.GetTierHandler")
}
@@ -1280,6 +1288,10 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/buckets/{bucket_name}/objects/metadata"] = user_api.NewGetObjectMetadata(o.context, o.UserAPIGetObjectMetadataHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/admin/tiers/{type}/{name}"] = admin_api.NewGetTier(o.context, o.AdminAPIGetTierHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)

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 user_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"
)
// GetObjectMetadataHandlerFunc turns a function with the right signature into a get object metadata handler
type GetObjectMetadataHandlerFunc func(GetObjectMetadataParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn GetObjectMetadataHandlerFunc) Handle(params GetObjectMetadataParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// GetObjectMetadataHandler interface for that can handle valid get object metadata params
type GetObjectMetadataHandler interface {
Handle(GetObjectMetadataParams, *models.Principal) middleware.Responder
}
// NewGetObjectMetadata creates a new http.Handler for the get object metadata operation
func NewGetObjectMetadata(ctx *middleware.Context, handler GetObjectMetadataHandler) *GetObjectMetadata {
return &GetObjectMetadata{Context: ctx, Handler: handler}
}
/* GetObjectMetadata swagger:route GET /buckets/{bucket_name}/objects/metadata UserAPI getObjectMetadata
Gets the metadata of an object
*/
type GetObjectMetadata struct {
Context *middleware.Context
Handler GetObjectMetadataHandler
}
func (o *GetObjectMetadata) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewGetObjectMetadataParams()
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,123 @@
// 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 user_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/validate"
)
// NewGetObjectMetadataParams creates a new GetObjectMetadataParams object
//
// There are no default values defined in the spec.
func NewGetObjectMetadataParams() GetObjectMetadataParams {
return GetObjectMetadataParams{}
}
// GetObjectMetadataParams contains all the bound params for the get object metadata operation
// typically these are obtained from a http.Request
//
// swagger:parameters GetObjectMetadata
type GetObjectMetadataParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
Required: true
In: path
*/
BucketName string
/*
Required: true
In: query
*/
Prefix 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 NewGetObjectMetadataParams() beforehand.
func (o *GetObjectMetadataParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
qs := runtime.Values(r.URL.Query())
rBucketName, rhkBucketName, _ := route.Params.GetOK("bucket_name")
if err := o.bindBucketName(rBucketName, rhkBucketName, route.Formats); err != nil {
res = append(res, err)
}
qPrefix, qhkPrefix, _ := qs.GetOK("prefix")
if err := o.bindPrefix(qPrefix, qhkPrefix, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindBucketName binds and validates parameter BucketName from path.
func (o *GetObjectMetadataParams) bindBucketName(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.BucketName = raw
return nil
}
// bindPrefix binds and validates parameter Prefix from query.
func (o *GetObjectMetadataParams) bindPrefix(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("prefix", "query", rawData)
}
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// AllowEmptyValue: false
if err := validate.RequiredString("prefix", "query", raw); err != nil {
return err
}
o.Prefix = raw
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 user_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"
)
// GetObjectMetadataOKCode is the HTTP code returned for type GetObjectMetadataOK
const GetObjectMetadataOKCode int = 200
/*GetObjectMetadataOK A successful response.
swagger:response getObjectMetadataOK
*/
type GetObjectMetadataOK struct {
/*
In: Body
*/
Payload *models.Metadata `json:"body,omitempty"`
}
// NewGetObjectMetadataOK creates GetObjectMetadataOK with default headers values
func NewGetObjectMetadataOK() *GetObjectMetadataOK {
return &GetObjectMetadataOK{}
}
// WithPayload adds the payload to the get object metadata o k response
func (o *GetObjectMetadataOK) WithPayload(payload *models.Metadata) *GetObjectMetadataOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get object metadata o k response
func (o *GetObjectMetadataOK) SetPayload(payload *models.Metadata) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetObjectMetadataOK) 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
}
}
}
/*GetObjectMetadataDefault Generic error response.
swagger:response getObjectMetadataDefault
*/
type GetObjectMetadataDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewGetObjectMetadataDefault creates GetObjectMetadataDefault with default headers values
func NewGetObjectMetadataDefault(code int) *GetObjectMetadataDefault {
if code <= 0 {
code = 500
}
return &GetObjectMetadataDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the get object metadata default response
func (o *GetObjectMetadataDefault) WithStatusCode(code int) *GetObjectMetadataDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the get object metadata default response
func (o *GetObjectMetadataDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the get object metadata default response
func (o *GetObjectMetadataDefault) WithPayload(payload *models.Error) *GetObjectMetadataDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get object metadata default response
func (o *GetObjectMetadataDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetObjectMetadataDefault) 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,127 @@
// 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 user_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"
)
// GetObjectMetadataURL generates an URL for the get object metadata operation
type GetObjectMetadataURL struct {
BucketName string
Prefix 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 *GetObjectMetadataURL) WithBasePath(bp string) *GetObjectMetadataURL {
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 *GetObjectMetadataURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *GetObjectMetadataURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/buckets/{bucket_name}/objects/metadata"
bucketName := o.BucketName
if bucketName != "" {
_path = strings.Replace(_path, "{bucket_name}", bucketName, -1)
} else {
return nil, errors.New("bucketName is required on GetObjectMetadataURL")
}
_basePath := o._basePath
if _basePath == "" {
_basePath = "/api/v1"
}
_result.Path = golangswaggerpaths.Join(_basePath, _path)
qs := make(url.Values)
prefixQ := o.Prefix
if prefixQ != "" {
qs.Set("prefix", prefixQ)
}
_result.RawQuery = qs.Encode()
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *GetObjectMetadataURL) 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 *GetObjectMetadataURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *GetObjectMetadataURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on GetObjectMetadataURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on GetObjectMetadataURL")
}
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 *GetObjectMetadataURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -156,6 +156,14 @@ func registerObjectsHandlers(api *operations.ConsoleAPI) {
}
return user_api.NewPutObjectRestoreOK()
})
// Metadata in object
api.UserAPIGetObjectMetadataHandler = user_api.GetObjectMetadataHandlerFunc(func(params user_api.GetObjectMetadataParams, session *models.Principal) middleware.Responder {
resp, err := getObjectMetadataResponse(session, params)
if err != nil {
return user_api.NewGetObjectMetadataDefault(int(err.Code)).WithPayload(err)
}
return user_api.NewGetObjectMetadataOK().WithPayload(resp)
})
}
// getListObjectsResponse returns a list of objects
@@ -1012,6 +1020,49 @@ func restoreObject(ctx context.Context, client MinioClient, bucketName, prefix,
return nil
}
// Metadata Response from minio-go API
func getObjectMetadataResponse(session *models.Principal, params user_api.GetObjectMetadataParams) (*models.Metadata, *models.Error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
defer cancel()
mClient, err := newMinioClient(session)
if err != nil {
return nil, prepareError(err)
}
// create a minioClient interface implementation
// defining the client to be used
minioClient := minioClient{client: mClient}
var prefix string
if params.Prefix != "" {
encodedPrefix := SanitizeEncodedPrefix(params.Prefix)
decodedPrefix, err := base64.StdEncoding.DecodeString(encodedPrefix)
if err != nil {
return nil, prepareError(err)
}
prefix = string(decodedPrefix)
}
objectInfo, err := getObjectInfo(ctx, minioClient, params.BucketName, prefix)
if err != nil {
return nil, prepareError(err)
}
metadata := &models.Metadata{ObjectMetadata: objectInfo.Metadata}
return metadata, nil
}
func getObjectInfo(ctx context.Context, client MinioClient, bucketName, prefix string) (minio.ObjectInfo, error) {
objectData, err := client.statObject(ctx, bucketName, prefix, minio.GetObjectOptions{})
if err != nil {
return minio.ObjectInfo{}, err
}
return objectData, nil
}
// newClientURL returns an abstracted URL for filesystems and object storage.
func newClientURL(urlStr string) *mc.ClientURL {
scheme, rest := getScheme(urlStr)

View File

@@ -43,6 +43,7 @@ var minioPutObjectLegalHoldMock func(ctx context.Context, bucketName, objectName
var minioPutObjectRetentionMock func(ctx context.Context, bucketName, objectName string, opts minio.PutObjectRetentionOptions) error
var minioGetObjectTaggingMock func(ctx context.Context, bucketName, objectName string, opts minio.GetObjectTaggingOptions) (*tags.Tags, error)
var minioPutObjectTaggingMock func(ctx context.Context, bucketName, objectName string, otags *tags.Tags, opts minio.PutObjectTaggingOptions) error
var minioStatObjectMock func(ctx context.Context, bucketName, prefix string, opts minio.GetObjectOptions) (objectInfo minio.ObjectInfo, err error)
var mcListMock func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent
var mcRemoveMock func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan *probe.Error
@@ -81,6 +82,10 @@ func (ac minioClientMock) putObjectTagging(ctx context.Context, bucketName, obje
return minioPutObjectTaggingMock(ctx, bucketName, objectName, otags, opts)
}
func (ac minioClientMock) statObject(ctx context.Context, bucketName, prefix string, opts minio.GetObjectOptions) (objectInfo minio.ObjectInfo, err error) {
return minioStatObjectMock(ctx, bucketName, prefix, opts)
}
// mock functions for s3ClientMock
func (c s3ClientMock) list(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent {
return mcListMock(ctx, opts)
@@ -1046,3 +1051,55 @@ func Test_deleteObjectRetention(t *testing.T) {
})
}
}
func Test_getObjectInfo(t *testing.T) {
assert := assert.New(t)
ctx := context.Background()
client := minioClientMock{}
type args struct {
bucketName string
prefix string
statFunc func(ctx context.Context, bucketName string, prefix string, opts minio.GetObjectOptions) (objectInfo minio.ObjectInfo, err error)
}
tests := []struct {
test string
args args
wantError error
}{
{
test: "Test function not returns an error",
args: args{
bucketName: "bucket1",
prefix: "someprefix",
statFunc: func(ctx context.Context, bucketName string, prefix string, opts minio.GetObjectOptions) (minio.ObjectInfo, error) {
return minio.ObjectInfo{}, nil
},
},
wantError: nil,
},
{
test: "Test function returns an error",
args: args{
bucketName: "bucket2",
prefix: "someprefi2",
statFunc: func(ctx context.Context, bucketName string, prefix string, opts minio.GetObjectOptions) (minio.ObjectInfo, error) {
return minio.ObjectInfo{}, errors.New("new Error")
},
},
wantError: errors.New("new Error"),
},
}
for _, tt := range tests {
t.Run(tt.test, func(t *testing.T) {
minioStatObjectMock = tt.args.statFunc
_, err := getObjectInfo(ctx, client, tt.args.bucketName, tt.args.prefix)
if tt.wantError != nil {
fmt.Println(t.Name())
assert.Equal(tt.wantError.Error(), err.Error(), fmt.Sprintf("getObjectInfo() error: `%s`, wantErr: `%s`", err, tt.wantError))
} else {
assert.Nil(err, fmt.Sprintf("getObjectInfo() error: %v, wantErr: %v", err, tt.wantError))
}
})
}
}

View File

@@ -611,6 +611,31 @@ paths:
tags:
- UserAPI
/buckets/{bucket_name}/objects/metadata:
get:
summary: Gets the metadata of an object
operationId: GetObjectMetadata
parameters:
- name: bucket_name
in: path
required: true
type: string
- name: prefix
in: query
required: true
type: string
responses:
200:
description: A successful response.
schema:
$ref: "#/definitions/metadata"
default:
description: Generic error response.
schema:
$ref: "#/definitions/error"
tags:
- UserAPI
/buckets/{bucket_name}/tags:
put:
summary: Put Bucket's tags
@@ -3929,3 +3954,10 @@ definitions:
type: object
additionalProperties:
type: object
metadata:
type: object
properties:
objectMetadata:
type: object
additionalProperties: true