Skip to content

Commit

Permalink
Merge pull request #166 from bcgov/meta-fix
Browse files Browse the repository at this point in the history
Re-name default COMS metadata
  • Loading branch information
jujaga authored Apr 28, 2023
2 parents 5eec390 + 244d8a9 commit 9d1c6ea
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Build the application
#
FROM registry.access.redhat.com/ubi9/nodejs-18:1-35 as builder
FROM registry.access.redhat.com/ubi9/nodejs-18:1-41 as builder

ENV NO_UPDATE_NOTIFIER=true

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

ENV APP_PORT=3000 \
NO_UPDATE_NOTIFIER=true
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ To learn more about the **Common Services** available visit the [Common Services
```txt
.github/ - PR, Issue templates and CI/CD
app/ - Application Root
├── config/ - configuration exposed as environment variables
├── src/ - Node.js web application
│ ├── components/ - Components Layer
│ ├── controllers/ - Controller Layer
Expand All @@ -28,10 +29,13 @@ app/ - Application Root
│ ├── middleware/ - Middleware Layer
│ ├── routes/ - API Route Layer
│ └── services/ - Services Layer
│ └── validators/ - data validation schemas
└── tests/ - Node.js web application tests
chart/ - General Helm Charts
charts/ - General Helm Charts
└── coms/ - COMS Helm Chart Repository
└── templates/ - COMS Helm Chart Template manifests
k6/ - sample load testing scripts
bcgovpubcode.yml - BCGov public code asset tracking
CODE-OF-CONDUCT.md - Code of Conduct
COMPLIANCE.yaml - BCGov PIA/STRA compliance status
CONTRIBUTING.md - Contributing Guidelines
Expand All @@ -44,7 +48,6 @@ SECURITY.md - Security Policy and Reporting

* [Application Readme](app/README.md)
* [API Specification](app/README.md#openapi-specification)
* [Openshift Readme](openshift/README.md)
* [Product Roadmap](https://github.com/bcgov/common-object-management-service/wiki/Product-Roadmap)
* [Product Wiki](https://github.com/bcgov/common-object-management-service/wiki)
* [Security Reporting](SECURITY.md)
Expand Down
4 changes: 4 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ The following variables enable and configure the use of a backend database to su
| `username` | `DB_USERNAME` | app | Database account username |
| `password` | `DB_PASSWORD` | | Database account password |
| `port` | `DB_PORT` | 5432 | Database connection port |
| `poolMin` | `DB_POOL_MIN` | 2 | avalable connections |
| `poolMax` | `DB_POOL_MAX` | 10 | available connections |

### Keycloak Variables

Expand Down Expand Up @@ -97,7 +99,9 @@ The following variables alter the general Express application behavior. For most
| `bodyLimit` | `SERVER_BODYLIMIT` | 30mb | Maximum body size accepted for parsing to JSON body |
| `logFile` | `SERVER_LOGFILE` | | Writes logs to the following file only if defined |
| `logLevel` | `SERVER_LOGLEVEL` | http | The logging level of COMS |
| `passphrase` | `SERVER_PASSPHRASE` | | A key to encrypt/decrypt bucket secretAccessKey's saved to the database |
| `port` | `SERVER_PORT` | 3000 | The port that COMS application will bind to |
| `privacyMask` | `SERVER_PRIVACY_MASK` | | Strict content privacy controls |

## Quick Start

Expand Down
4 changes: 2 additions & 2 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common-object-management-service",
"version": "0.4.1",
"version": "0.4.2",
"private": true,
"description": "",
"author": "NR Common Service Showcase <[email protected]>",
Expand Down
20 changes: 10 additions & 10 deletions app/src/controllers/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const controller = {
exposedHeaders.push(metadata);
});

if (s3Resp.Metadata.name) res.attachment(s3Resp.Metadata.name);
if (s3Resp.Metadata['coms-name']) res.attachment(s3Resp.Metadata['coms-name']);
}
if (s3Resp.ServerSideEncryption) {
const sse = 'x-amz-server-side-encryption';
Expand Down Expand Up @@ -123,7 +123,7 @@ const controller = {
metadata: {
...source.Metadata, // Take existing metadata first
...metadataToAppend, // Append new metadata
id: source.Metadata.id // Always enforce id key behavior
'coms-id': source.Metadata['coms-id'] // Always enforce coms-id key behavior
},
metadataDirective: MetadataDirective.REPLACE,
s3VersionId: sourceS3VersionId
Expand Down Expand Up @@ -234,9 +234,9 @@ const controller = {
fieldName: name,
mimeType: info.mimeType,
metadata: {
name: info.filename, // provide a default of `name: <file name>`
'coms-name': info.filename, // provide a default of `coms-name: <file name>`
...getMetadata(req.headers),
id: objId
'coms-id': objId
},
tags: req.query.tagset,
bucketId: bucketId
Expand Down Expand Up @@ -333,8 +333,8 @@ const controller = {
filePath: objPath,
metadata: {
...metadata,
name: source.Metadata.name, // Always enforce name and id key behavior
id: source.Metadata.id
'coms-name': source.Metadata['coms-name'], // Always enforce name and id key behavior
'coms-id': source.Metadata['coms-id']
},
metadataDirective: MetadataDirective.REPLACE,
s3VersionId: sourceS3VersionId
Expand Down Expand Up @@ -676,9 +676,9 @@ const controller = {
copySource: objPath,
filePath: objPath,
metadata: {
name: source.Metadata.name, // Always enforce name and id key behavior
'coms-name': source.Metadata['coms-name'], // Always enforce coms-name and coms-id key behavior
...newMetadata, // Add new metadata
id: source.Metadata.id
'coms-id': source.Metadata['coms-id']
},
metadataDirective: MetadataDirective.REPLACE,
s3VersionId: sourceS3VersionId
Expand Down Expand Up @@ -836,9 +836,9 @@ const controller = {
fieldName: name,
mimeType: info.mimeType,
metadata: {
name: info.filename,
'coms-name': info.filename,
...getMetadata(req.headers),
id: objId
'coms-id': objId
},
tags: req.query.tagset
};
Expand Down
23 changes: 23 additions & 0 deletions app/src/db/migrations/20230427000000_006-metadata-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
exports.up = function (knex) {
return Promise.resolve()
.then(() => knex('metadata')
.where({ key: 'id' })
.update({ key: 'coms-id' })
)
.then(() => knex('metadata')
.where({ key: 'name' })
.update({ key: 'coms-name' })
);
};

exports.down = function (knex) {
return Promise.resolve()
.then(() => knex('metadata')
.where({ key: 'coms-id' })
.update({ key: 'id' })
)
.then(() => knex('metadata')
.where({ key: 'coms-name' })
.update({ key: 'name' })
);
};
4 changes: 2 additions & 2 deletions app/src/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ const objectStorageService = {
ContentType: mimeType,
Metadata: {
...metadata,
id: id // enforce metadata `id: <object ID>`
'coms-id': id // enforce metadata `coms-id: <object ID>`
},
// TODO: Consider adding API param support for Server Side Encryption
// ServerSideEncryption: 'AES256'
Expand Down Expand Up @@ -424,7 +424,7 @@ const objectStorageService = {
ContentType: mimeType,
Metadata: {
...metadata,
id: id // enforce metadata `id: <object ID>`
'coms-id': id // enforce metadata `coms-id: <object ID>`
},
// TODO: Consider adding API param support for Server Side Encryption
// ServerSideEncryption: 'AES256'
Expand Down
26 changes: 13 additions & 13 deletions app/tests/unit/controllers/object.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('addMetadata', () => {
// response from S3
const GoodResponse = {
ContentLength: 1234,
Metadata: { id: 1, foo: 'bar' },
Metadata: { 'coms-id': 1, foo: 'bar' },
VersionId: '5678'
};
const BadResponse = {
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('addMetadata', () => {
metadata: {
foo: 'bar',
baz: 'quz',
id: 1
'coms-id': 1
},
metadataDirective: MetadataDirective.REPLACE,
s3VersionId: undefined
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('deleteMetadata', () => {
// response from S3
const GoodResponse = {
ContentLength: 1234,
Metadata: { id: 1, name: 'test', foo: 'bar', baz: 'quz' }
Metadata: { 'coms-id': 1, 'coms-name': 'test', foo: 'bar', baz: 'quz' }
};
const BadResponse = {
ContentLength: MAXCOPYOBJECTLENGTH + 1
Expand Down Expand Up @@ -249,8 +249,8 @@ describe('deleteMetadata', () => {
filePath: 'xyz-789',
metadata: {
baz: 'quz',
id: 1,
name: 'test',
'coms-id': 1,
'coms-name': 'test',
},
metadataDirective: MetadataDirective.REPLACE,
s3VersionId: undefined
Expand All @@ -275,8 +275,8 @@ describe('deleteMetadata', () => {
copySource: 'xyz-789',
filePath: 'xyz-789',
metadata: {
id: 1,
name: 'test'
'coms-id': 1,
'coms-name': 'test'
},
metadataDirective: MetadataDirective.REPLACE,
s3VersionId: undefined
Expand Down Expand Up @@ -479,7 +479,7 @@ describe('replaceMetadata', () => {
// response from S3
const GoodResponse = {
ContentLength: 1234,
Metadata: { id: 1, name: 'test', foo: 'bar' }
Metadata: { 'coms-id': 1, 'coms-name': 'test', foo: 'bar' }
};
const BadResponse = {
ContentLength: MAXCOPYOBJECTLENGTH + 1
Expand Down Expand Up @@ -512,8 +512,8 @@ describe('replaceMetadata', () => {
copySource: 'xyz-789',
filePath: 'xyz-789',
metadata: {
id: 1,
name: 'test',
'coms-id': 1,
'coms-name': 'test',
baz: 'quz'
},
metadataDirective: MetadataDirective.REPLACE,
Expand All @@ -524,7 +524,7 @@ describe('replaceMetadata', () => {
it('should replace replace the name', async () => {
// request object
const req = {
headers: { 'x-amz-meta-name': 'newName', 'x-amz-meta-baz': 'quz' },
headers: { 'x-amz-meta-coms-name': 'newName', 'x-amz-meta-baz': 'quz' },
params: { objectId: 'xyz-789' },
query: {}
};
Expand All @@ -539,8 +539,8 @@ describe('replaceMetadata', () => {
copySource: 'xyz-789',
filePath: 'xyz-789',
metadata: {
id: 1,
name: 'newName',
'coms-id': 1,
'coms-name': 'newName',
baz: 'quz'
},
metadataDirective: MetadataDirective.REPLACE,
Expand Down
10 changes: 5 additions & 5 deletions app/tests/unit/services/storage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ describe('putObject', () => {
it('should send a put object command', async () => {
const stream = new Readable();
const mimeType = 'mimeType';
const metadata = { name: 'originalName', id: id };
const metadata = { 'coms-name': 'originalName', 'coms-id': id };
const result = await service.putObject({ stream, id, mimeType, metadata });

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

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

Expand Down Expand Up @@ -715,7 +715,7 @@ describe('upload', () => {
}
});
const mimeType = 'mimeType';
const metadata = { name: 'originalName', id: id };
const metadata = { 'coms-name': 'originalName', 'coms-id': id };
const result = await service.upload({ stream, id, mimeType, metadata });

expect(result).toBeTruthy();
Expand All @@ -737,7 +737,7 @@ describe('upload', () => {
}
});
const mimeType = 'mimeType';
const metadata = { name: 'originalName', id: id };
const metadata = { 'coms-name': 'originalName', 'coms-id': id };
const tags = { foo: 'bar' };
const result = await service.upload({ stream, id, mimeType, metadata, tags });

Expand Down
4 changes: 2 additions & 2 deletions charts/coms/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: common-object-management-service
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.14
version: 0.0.15
kubeVersion: ">= 1.13.0"
description: A microservice for managing access control to S3 Objects
# A chart can be either an 'application' or a 'library' chart.
Expand Down Expand Up @@ -43,6 +43,6 @@ maintainers:
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.4.1"
appVersion: "0.4.2"
deprecated: false
annotations: {}
2 changes: 1 addition & 1 deletion charts/coms/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# common-object-management-service

![Version: 0.0.14](https://img.shields.io/badge/Version-0.0.14-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.4.1](https://img.shields.io/badge/AppVersion-0.4.1-informational?style=flat-square)
![Version: 0.0.15](https://img.shields.io/badge/Version-0.0.15-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.4.2](https://img.shields.io/badge/AppVersion-0.4.2-informational?style=flat-square)

A microservice for managing access control to S3 Objects

Expand Down

0 comments on commit 9d1c6ea

Please sign in to comment.