Added VersionID support to Metadata Details (#3332)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
@@ -1762,6 +1762,11 @@ func init() {
|
|||||||
"name": "prefix",
|
"name": "prefix",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"name": "versionID",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
@@ -10974,6 +10979,11 @@ func init() {
|
|||||||
"name": "prefix",
|
"name": "prefix",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"name": "versionID",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ type GetObjectMetadataParams struct {
|
|||||||
In: query
|
In: query
|
||||||
*/
|
*/
|
||||||
Prefix string
|
Prefix string
|
||||||
|
/*
|
||||||
|
In: query
|
||||||
|
*/
|
||||||
|
VersionID *string
|
||||||
}
|
}
|
||||||
|
|
||||||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||||
@@ -81,6 +85,11 @@ func (o *GetObjectMetadataParams) BindRequest(r *http.Request, route *middleware
|
|||||||
if err := o.bindPrefix(qPrefix, qhkPrefix, route.Formats); err != nil {
|
if err := o.bindPrefix(qPrefix, qhkPrefix, route.Formats); err != nil {
|
||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qVersionID, qhkVersionID, _ := qs.GetOK("versionID")
|
||||||
|
if err := o.bindVersionID(qVersionID, qhkVersionID, route.Formats); err != nil {
|
||||||
|
res = append(res, err)
|
||||||
|
}
|
||||||
if len(res) > 0 {
|
if len(res) > 0 {
|
||||||
return errors.CompositeValidationError(res...)
|
return errors.CompositeValidationError(res...)
|
||||||
}
|
}
|
||||||
@@ -121,3 +130,21 @@ func (o *GetObjectMetadataParams) bindPrefix(rawData []string, hasKey bool, form
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bindVersionID binds and validates parameter VersionID from query.
|
||||||
|
func (o *GetObjectMetadataParams) bindVersionID(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
|
||||||
|
}
|
||||||
|
o.VersionID = &raw
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ import (
|
|||||||
type GetObjectMetadataURL struct {
|
type GetObjectMetadataURL struct {
|
||||||
BucketName string
|
BucketName string
|
||||||
|
|
||||||
Prefix string
|
Prefix string
|
||||||
|
VersionID *string
|
||||||
|
|
||||||
_basePath string
|
_basePath string
|
||||||
// avoid unkeyed usage
|
// avoid unkeyed usage
|
||||||
@@ -81,6 +82,14 @@ func (o *GetObjectMetadataURL) Build() (*url.URL, error) {
|
|||||||
qs.Set("prefix", prefixQ)
|
qs.Set("prefix", prefixQ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var versionIDQ string
|
||||||
|
if o.VersionID != nil {
|
||||||
|
versionIDQ = *o.VersionID
|
||||||
|
}
|
||||||
|
if versionIDQ != "" {
|
||||||
|
qs.Set("versionID", versionIDQ)
|
||||||
|
}
|
||||||
|
|
||||||
_result.RawQuery = qs.Encode()
|
_result.RawQuery = qs.Encode()
|
||||||
|
|
||||||
return &_result, nil
|
return &_result, nil
|
||||||
|
|||||||
@@ -1338,6 +1338,7 @@ func getObjectMetadataResponse(session *models.Principal, params objectApi.GetOb
|
|||||||
// defining the client to be used
|
// defining the client to be used
|
||||||
minioClient := minioClient{client: mClient}
|
minioClient := minioClient{client: mClient}
|
||||||
var prefix string
|
var prefix string
|
||||||
|
var versionID string
|
||||||
|
|
||||||
if params.Prefix != "" {
|
if params.Prefix != "" {
|
||||||
encodedPrefix := SanitizeEncodedPrefix(params.Prefix)
|
encodedPrefix := SanitizeEncodedPrefix(params.Prefix)
|
||||||
@@ -1348,7 +1349,11 @@ func getObjectMetadataResponse(session *models.Principal, params objectApi.GetOb
|
|||||||
prefix = string(decodedPrefix)
|
prefix = string(decodedPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
objectInfo, err := getObjectInfo(ctx, minioClient, params.BucketName, prefix)
|
if params.VersionID != nil {
|
||||||
|
versionID = *params.VersionID
|
||||||
|
}
|
||||||
|
|
||||||
|
objectInfo, err := getObjectInfo(ctx, minioClient, params.BucketName, prefix, versionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrorWithContext(ctx, err)
|
return nil, ErrorWithContext(ctx, err)
|
||||||
}
|
}
|
||||||
@@ -1358,8 +1363,8 @@ func getObjectMetadataResponse(session *models.Principal, params objectApi.GetOb
|
|||||||
return metadata, nil
|
return metadata, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getObjectInfo(ctx context.Context, client MinioClient, bucketName, prefix string) (minio.ObjectInfo, error) {
|
func getObjectInfo(ctx context.Context, client MinioClient, bucketName, prefix, versionID string) (minio.ObjectInfo, error) {
|
||||||
objectData, err := client.statObject(ctx, bucketName, prefix, minio.GetObjectOptions{})
|
objectData, err := client.statObject(ctx, bucketName, prefix, minio.GetObjectOptions{VersionID: versionID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return minio.ObjectInfo{}, err
|
return minio.ObjectInfo{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1293,6 +1293,7 @@ func Test_getObjectInfo(t *testing.T) {
|
|||||||
type args struct {
|
type args struct {
|
||||||
bucketName string
|
bucketName string
|
||||||
prefix string
|
prefix string
|
||||||
|
versionID string
|
||||||
statFunc func(ctx context.Context, bucketName string, prefix string, opts minio.GetObjectOptions) (objectInfo minio.ObjectInfo, err error)
|
statFunc func(ctx context.Context, bucketName string, prefix string, opts minio.GetObjectOptions) (objectInfo minio.ObjectInfo, err error)
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@@ -1305,6 +1306,7 @@ func Test_getObjectInfo(t *testing.T) {
|
|||||||
args: args{
|
args: args{
|
||||||
bucketName: "bucket1",
|
bucketName: "bucket1",
|
||||||
prefix: "someprefix",
|
prefix: "someprefix",
|
||||||
|
versionID: "version123",
|
||||||
statFunc: func(_ context.Context, _ string, _ string, _ minio.GetObjectOptions) (minio.ObjectInfo, error) {
|
statFunc: func(_ context.Context, _ string, _ string, _ minio.GetObjectOptions) (minio.ObjectInfo, error) {
|
||||||
return minio.ObjectInfo{}, nil
|
return minio.ObjectInfo{}, nil
|
||||||
},
|
},
|
||||||
@@ -1316,6 +1318,7 @@ func Test_getObjectInfo(t *testing.T) {
|
|||||||
args: args{
|
args: args{
|
||||||
bucketName: "bucket2",
|
bucketName: "bucket2",
|
||||||
prefix: "someprefi2",
|
prefix: "someprefi2",
|
||||||
|
versionID: "version456",
|
||||||
statFunc: func(_ context.Context, _ string, _ string, _ minio.GetObjectOptions) (minio.ObjectInfo, error) {
|
statFunc: func(_ context.Context, _ string, _ string, _ minio.GetObjectOptions) (minio.ObjectInfo, error) {
|
||||||
return minio.ObjectInfo{}, errors.New("new Error")
|
return minio.ObjectInfo{}, errors.New("new Error")
|
||||||
},
|
},
|
||||||
@@ -1326,7 +1329,7 @@ func Test_getObjectInfo(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.test, func(_ *testing.T) {
|
t.Run(tt.test, func(_ *testing.T) {
|
||||||
minioStatObjectMock = tt.args.statFunc
|
minioStatObjectMock = tt.args.statFunc
|
||||||
_, err := getObjectInfo(ctx, client, tt.args.bucketName, tt.args.prefix)
|
_, err := getObjectInfo(ctx, client, tt.args.bucketName, tt.args.prefix, tt.args.versionID)
|
||||||
if tt.wantError != nil {
|
if tt.wantError != nil {
|
||||||
fmt.Println(t.Name())
|
fmt.Println(t.Name())
|
||||||
tAssert.Equal(tt.wantError.Error(), err.Error(), fmt.Sprintf("getObjectInfo() error: `%s`, wantErr: `%s`", err, tt.wantError))
|
tAssert.Equal(tt.wantError.Error(), err.Error(), fmt.Sprintf("getObjectInfo() error: `%s`, wantErr: `%s`", err, tt.wantError))
|
||||||
|
|||||||
@@ -703,6 +703,9 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
- name: versionID
|
||||||
|
in: query
|
||||||
|
type: string
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: A successful response.
|
description: A successful response.
|
||||||
|
|||||||
@@ -2397,6 +2397,7 @@ export class Api<
|
|||||||
bucketName: string,
|
bucketName: string,
|
||||||
query: {
|
query: {
|
||||||
prefix: string;
|
prefix: string;
|
||||||
|
versionID?: string;
|
||||||
},
|
},
|
||||||
params: RequestParams = {},
|
params: RequestParams = {},
|
||||||
) =>
|
) =>
|
||||||
|
|||||||
@@ -216,6 +216,7 @@ const ObjectDetailPanel = ({
|
|||||||
api.buckets
|
api.buckets
|
||||||
.getObjectMetadata(bucketName, {
|
.getObjectMetadata(bucketName, {
|
||||||
prefix: internalPaths,
|
prefix: internalPaths,
|
||||||
|
versionID: actualInfo?.version_id || "",
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
let metadata = get(res.data, "objectMetadata", {});
|
let metadata = get(res.data, "objectMetadata", {});
|
||||||
@@ -228,7 +229,7 @@ const ObjectDetailPanel = ({
|
|||||||
setLoadingMetadata(false);
|
setLoadingMetadata(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [bucketName, internalPaths, loadMetadata]);
|
}, [bucketName, internalPaths, loadMetadata, actualInfo?.version_id]);
|
||||||
|
|
||||||
let tagKeys: string[] = [];
|
let tagKeys: string[] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ const PreviewFile = ({
|
|||||||
api.buckets
|
api.buckets
|
||||||
.getObjectMetadata(bucketName, {
|
.getObjectMetadata(bucketName, {
|
||||||
prefix: encodedPath,
|
prefix: encodedPath,
|
||||||
|
versionID: actualInfo.version_id || "",
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
let metadata = get(res.data, "objectMetadata", {});
|
let metadata = get(res.data, "objectMetadata", {});
|
||||||
@@ -66,7 +67,7 @@ const PreviewFile = ({
|
|||||||
setIsMetaDataLoaded(true);
|
setIsMetaDataLoaded(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [bucketName, objectName, isMetaDataLoaded]);
|
}, [bucketName, objectName, isMetaDataLoaded, actualInfo.version_id]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (bucketName && objectName) {
|
if (bucketName && objectName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user