Skip to content

Commit 467b14d

Browse files
committed
Re-name default COMS metadata
db migration update property names in object controller
1 parent 41ada7f commit 467b14d

File tree

6 files changed

+55
-32
lines changed

6 files changed

+55
-32
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
# Build the application
99
#
10-
FROM registry.access.redhat.com/ubi9/nodejs-18:1-35 as builder
10+
FROM registry.access.redhat.com/ubi9/nodejs-18:1-41 as builder
1111

1212
ENV NO_UPDATE_NOTIFIER=true
1313

@@ -22,7 +22,7 @@ RUN npm ci --omit=dev
2222
#
2323
# Create the final container image
2424
#
25-
FROM registry.access.redhat.com/ubi9/nodejs-18-minimal:1-36
25+
FROM registry.access.redhat.com/ubi9/nodejs-18-minimal:1-42
2626

2727
ENV APP_PORT=3000 \
2828
NO_UPDATE_NOTIFIER=true

app/src/controllers/object.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const controller = {
7171
exposedHeaders.push(metadata);
7272
});
7373

74-
if (s3Resp.Metadata.name) res.attachment(s3Resp.Metadata.name);
74+
if (s3Resp.Metadata['coms-name']) res.attachment(s3Resp.Metadata['coms-name']);
7575
}
7676
if (s3Resp.ServerSideEncryption) {
7777
const sse = 'x-amz-server-side-encryption';
@@ -123,7 +123,7 @@ const controller = {
123123
metadata: {
124124
...source.Metadata, // Take existing metadata first
125125
...metadataToAppend, // Append new metadata
126-
id: source.Metadata.id // Always enforce id key behavior
126+
'coms-id': source.Metadata['coms-id'] // Always enforce coms-id key behavior
127127
},
128128
metadataDirective: MetadataDirective.REPLACE,
129129
s3VersionId: sourceS3VersionId
@@ -234,9 +234,9 @@ const controller = {
234234
fieldName: name,
235235
mimeType: info.mimeType,
236236
metadata: {
237-
name: info.filename, // provide a default of `name: <file name>`
237+
'coms-name': info.filename, // provide a default of `coms-name: <file name>`
238238
...getMetadata(req.headers),
239-
id: objId
239+
'coms-id': objId
240240
},
241241
tags: req.query.tagset,
242242
bucketId: bucketId
@@ -333,8 +333,8 @@ const controller = {
333333
filePath: objPath,
334334
metadata: {
335335
...metadata,
336-
name: source.Metadata.name, // Always enforce name and id key behavior
337-
id: source.Metadata.id
336+
'coms-name': source.Metadata['coms-name'], // Always enforce name and id key behavior
337+
'coms-id': source.Metadata['coms-id']
338338
},
339339
metadataDirective: MetadataDirective.REPLACE,
340340
s3VersionId: sourceS3VersionId
@@ -676,9 +676,9 @@ const controller = {
676676
copySource: objPath,
677677
filePath: objPath,
678678
metadata: {
679-
name: source.Metadata.name, // Always enforce name and id key behavior
679+
'coms-name': source.Metadata['coms-name'], // Always enforce coms-name and coms-id key behavior
680680
...newMetadata, // Add new metadata
681-
id: source.Metadata.id
681+
'coms-id': source.Metadata['coms-id']
682682
},
683683
metadataDirective: MetadataDirective.REPLACE,
684684
s3VersionId: sourceS3VersionId
@@ -836,9 +836,9 @@ const controller = {
836836
fieldName: name,
837837
mimeType: info.mimeType,
838838
metadata: {
839-
name: info.filename,
839+
'coms-name': info.filename,
840840
...getMetadata(req.headers),
841-
id: objId
841+
'coms-id': objId
842842
},
843843
tags: req.query.tagset
844844
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
exports.up = function (knex) {
2+
return Promise.resolve()
3+
.then(() => knex('metadata')
4+
.where({ key: 'id' })
5+
.update({ key: 'coms-id' })
6+
)
7+
.then(() => knex('metadata')
8+
.where({ key: 'name' })
9+
.update({ key: 'coms-name' })
10+
);
11+
};
12+
13+
exports.down = function (knex) {
14+
return Promise.resolve()
15+
.then(() => knex('metadata')
16+
.where({ key: 'coms-id' })
17+
.update({ key: 'id' })
18+
)
19+
.then(() => knex('metadata')
20+
.where({ key: 'coms-name' })
21+
.update({ key: 'name' })
22+
);
23+
};

app/src/services/storage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ const objectStorageService = {
322322
ContentType: mimeType,
323323
Metadata: {
324324
...metadata,
325-
id: id // enforce metadata `id: <object ID>`
325+
'coms-id': id // enforce metadata `coms-id: <object ID>`
326326
},
327327
// TODO: Consider adding API param support for Server Side Encryption
328328
// ServerSideEncryption: 'AES256'
@@ -424,7 +424,7 @@ const objectStorageService = {
424424
ContentType: mimeType,
425425
Metadata: {
426426
...metadata,
427-
id: id // enforce metadata `id: <object ID>`
427+
'coms-id': id // enforce metadata `coms-id: <object ID>`
428428
},
429429
// TODO: Consider adding API param support for Server Side Encryption
430430
// ServerSideEncryption: 'AES256'

app/tests/unit/controllers/object.spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('addMetadata', () => {
3939
// response from S3
4040
const GoodResponse = {
4141
ContentLength: 1234,
42-
Metadata: { id: 1, foo: 'bar' },
42+
Metadata: { 'coms-id': 1, foo: 'bar' },
4343
VersionId: '5678'
4444
};
4545
const BadResponse = {
@@ -93,7 +93,7 @@ describe('addMetadata', () => {
9393
metadata: {
9494
foo: 'bar',
9595
baz: 'quz',
96-
id: 1
96+
'coms-id': 1
9797
},
9898
metadataDirective: MetadataDirective.REPLACE,
9999
s3VersionId: undefined
@@ -215,7 +215,7 @@ describe('deleteMetadata', () => {
215215
// response from S3
216216
const GoodResponse = {
217217
ContentLength: 1234,
218-
Metadata: { id: 1, name: 'test', foo: 'bar', baz: 'quz' }
218+
Metadata: { 'coms-id': 1, 'coms-name': 'test', foo: 'bar', baz: 'quz' }
219219
};
220220
const BadResponse = {
221221
ContentLength: MAXCOPYOBJECTLENGTH + 1
@@ -249,8 +249,8 @@ describe('deleteMetadata', () => {
249249
filePath: 'xyz-789',
250250
metadata: {
251251
baz: 'quz',
252-
id: 1,
253-
name: 'test',
252+
'coms-id': 1,
253+
'coms-name': 'test',
254254
},
255255
metadataDirective: MetadataDirective.REPLACE,
256256
s3VersionId: undefined
@@ -275,8 +275,8 @@ describe('deleteMetadata', () => {
275275
copySource: 'xyz-789',
276276
filePath: 'xyz-789',
277277
metadata: {
278-
id: 1,
279-
name: 'test'
278+
'coms-id': 1,
279+
'coms-name': 'test'
280280
},
281281
metadataDirective: MetadataDirective.REPLACE,
282282
s3VersionId: undefined
@@ -479,7 +479,7 @@ describe('replaceMetadata', () => {
479479
// response from S3
480480
const GoodResponse = {
481481
ContentLength: 1234,
482-
Metadata: { id: 1, name: 'test', foo: 'bar' }
482+
Metadata: { 'coms-id': 1, 'coms-name': 'test', foo: 'bar' }
483483
};
484484
const BadResponse = {
485485
ContentLength: MAXCOPYOBJECTLENGTH + 1
@@ -512,8 +512,8 @@ describe('replaceMetadata', () => {
512512
copySource: 'xyz-789',
513513
filePath: 'xyz-789',
514514
metadata: {
515-
id: 1,
516-
name: 'test',
515+
'coms-id': 1,
516+
'coms-name': 'test',
517517
baz: 'quz'
518518
},
519519
metadataDirective: MetadataDirective.REPLACE,
@@ -524,7 +524,7 @@ describe('replaceMetadata', () => {
524524
it('should replace replace the name', async () => {
525525
// request object
526526
const req = {
527-
headers: { 'x-amz-meta-name': 'newName', 'x-amz-meta-baz': 'quz' },
527+
headers: { 'x-amz-meta-coms-name': 'newName', 'x-amz-meta-baz': 'quz' },
528528
params: { objectId: 'xyz-789' },
529529
query: {}
530530
};
@@ -539,8 +539,8 @@ describe('replaceMetadata', () => {
539539
copySource: 'xyz-789',
540540
filePath: 'xyz-789',
541541
metadata: {
542-
id: 1,
543-
name: 'newName',
542+
'coms-id': 1,
543+
'coms-name': 'newName',
544544
baz: 'quz'
545545
},
546546
metadataDirective: MetadataDirective.REPLACE,

app/tests/unit/services/storage.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ describe('putObject', () => {
495495
it('should send a put object command', async () => {
496496
const stream = new Readable();
497497
const mimeType = 'mimeType';
498-
const metadata = { name: 'originalName', id: id };
498+
const metadata = { 'coms-name': 'originalName', 'coms-id': id };
499499
const result = await service.putObject({ stream, id, mimeType, metadata });
500500

501501
expect(result).toBeTruthy();
@@ -513,7 +513,7 @@ describe('putObject', () => {
513513
it('should send a put object command with custom metadata', async () => {
514514
const stream = new Readable();
515515
const mimeType = 'mimeType';
516-
const metadata = { name: 'originalName', id: id, foo: 'foo', bar: 'bar' };
516+
const metadata = { 'coms-name': 'originalName', 'coms-id': id, foo: 'foo', bar: 'bar' };
517517
const result = await service.putObject({ stream, id, mimeType, metadata });
518518

519519
expect(result).toBeTruthy();
@@ -531,7 +531,7 @@ describe('putObject', () => {
531531
it('should send a put object command with custom tags', async () => {
532532
const stream = new Readable();
533533
const mimeType = 'mimeType';
534-
const metadata = { name: 'originalName', id: id };
534+
const metadata = { 'coms-name': 'originalName', 'coms-id': id };
535535
const tags = { foo: 'foo', bar: 'bar' };
536536
const result = await service.putObject({ stream, id, mimeType, metadata, tags });
537537

@@ -715,7 +715,7 @@ describe('upload', () => {
715715
}
716716
});
717717
const mimeType = 'mimeType';
718-
const metadata = { name: 'originalName', id: id };
718+
const metadata = { 'coms-name': 'originalName', 'coms-id': id };
719719
const result = await service.upload({ stream, id, mimeType, metadata });
720720

721721
expect(result).toBeTruthy();
@@ -737,7 +737,7 @@ describe('upload', () => {
737737
}
738738
});
739739
const mimeType = 'mimeType';
740-
const metadata = { name: 'originalName', id: id };
740+
const metadata = { 'coms-name': 'originalName', 'coms-id': id };
741741
const tags = { foo: 'bar' };
742742
const result = await service.upload({ stream, id, mimeType, metadata, tags });
743743

0 commit comments

Comments
 (0)