Skip to content

Commit

Permalink
Upgrade all dependencies (#432)
Browse files Browse the repository at this point in the history
* Upgrade Node.js 20 & all dependencies

* Add flag to allow/disallow delete operations
  • Loading branch information
fmartinou authored Sep 15, 2024
1 parent 017e1f8 commit 7f6c27f
Show file tree
Hide file tree
Showing 18 changed files with 6,538 additions and 3,671 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@ env:
global:
- NODE_VERSION=18
- CC_TEST_REPORTER_ID=46ef31dae5b656e0f4be410a86bd83bdcf73e7d27ab33a704c197e6fe4bf02a0
# - DOCKER_CLI_EXPERIMENTAL=enabled

before_install:

- export IMAGE_VERSION=${TRAVIS_BRANCH//\//\_}
- export IMAGE_VERSION=${IMAGE_VERSION//\#/\_}

# Install docker with buildx
# - for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
# - sudo apt-get update
# - sudo apt-get install ca-certificates curl
- sudo install -m 0755 -d /etc/apt/keyrings
- sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
- sudo chmod a+r /etc/apt/keyrings/docker.asc
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- sudo apt-get update
- sudo apt-get install -y docker-buildx-plugin
# - docker run --rm --privileged docker/binfmt:820fdd95a9972a5308930a2bdfb8573dd4447ad3
# - cat /proc/sys/fs/binfmt_misc/qemu-aarch64

# Install Nodejs
- nvm install $NODE_VERSION
Expand Down
19 changes: 13 additions & 6 deletions app/api/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ const express = require('express');
const nocache = require('nocache');
const storeContainer = require('../store/container');
const registry = require('../registry');
const { getServerConfiguration } = require('../configuration');

const router = express.Router();

const serverConfiguration = getServerConfiguration();

/**
* Return registered watchers.
* @returns {{id: string}[]}
Expand Down Expand Up @@ -53,13 +56,17 @@ function getContainer(req, res) {
* @param res
*/
function deleteContainer(req, res) {
const { id } = req.params;
const container = storeContainer.getContainer(id);
if (container) {
storeContainer.deleteContainer(id);
res.sendStatus(204);
if (!serverConfiguration.feature.delete) {
res.sendStatus(403);
} else {
res.sendStatus(404);
const { id } = req.params;
const container = storeContainer.getContainer(id);
if (container) {
storeContainer.deleteContainer(id);
res.sendStatus(204);
} else {
res.sendStatus(404);
}
}
}

Expand Down
26 changes: 1 addition & 25 deletions app/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fs = require('fs');
const https = require('https');
const joi = require('joi');
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
Expand All @@ -10,32 +9,9 @@ const apiRouter = require('./api');
const uiRouter = require('./ui');
const prometheusRouter = require('./prometheus');
const healthRouter = require('./health');

const { getServerConfiguration } = require('../configuration');

// Configuration Schema
const configurationSchema = joi.object().keys({
enabled: joi.boolean().default(true),
port: joi.number().default(3000).integer().min(0)
.max(65535),
tls: joi.object({
enabled: joi.boolean().default(false),
key: joi.string().when('enabled', { is: true, then: joi.required(), otherwise: joi.optional() }),
cert: joi.string().when('enabled', { is: true, then: joi.required(), otherwise: joi.optional() }),
}).default({}),
cors: joi.object({
enabled: joi.boolean().default(false),
origin: joi.string().default('*'),
methods: joi.string().default('GET,HEAD,PUT,PATCH,POST,DELETE'),
}).default({}),
});

// Validate Configuration
const configurationToValidate = configurationSchema.validate(getServerConfiguration() || {});
if (configurationToValidate.error) {
throw configurationToValidate.error;
}
const configuration = configurationToValidate.value;
const configuration = getServerConfiguration();

/**
* Init Http API.
Expand Down
38 changes: 28 additions & 10 deletions app/configuration/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs');
const joi = require('joi');
const setValue = require('set-value');

const VAR_FILE_SUFFIX = '__FILE';
Expand Down Expand Up @@ -97,17 +98,34 @@ function getStoreConfiguration() {
* Get Server configurations.
*/
function getServerConfiguration() {
// Deprecated env var namespace; to be removed on next major version
const apiConfiguration = get('wud.api', wudEnvVars);

// New en var namespace
const serverConfiguration = get('wud.server', wudEnvVars);
const configurationFromEnv = get('wud.server', wudEnvVars);
const configurationSchema = joi.object().keys({
enabled: joi.boolean().default(true),
port: joi.number().default(3000).integer().min(0)
.max(65535),
tls: joi.object({
enabled: joi.boolean().default(false),
key: joi.string().when('enabled', { is: true, then: joi.required(), otherwise: joi.optional() }),
cert: joi.string().when('enabled', { is: true, then: joi.required(), otherwise: joi.optional() }),
}).default({}),
cors: joi.object({
enabled: joi.boolean().default(false),
origin: joi.string().default('*'),
methods: joi.string().default('GET,HEAD,PUT,PATCH,POST,DELETE'),
}).default({}),
feature: joi.object({
delete: joi.boolean().default(true),
}).default({
delete: true,
}),
});

// Merge deprecated & new env vars
return {
...apiConfiguration,
...serverConfiguration,
};
// Validate Configuration
const configurationToValidate = configurationSchema.validate(configurationFromEnv || {});
if (configurationToValidate.error) {
throw configurationToValidate.error;
}
return configurationToValidate.value;
}

function getPublicUrl(req) {
Expand Down
26 changes: 12 additions & 14 deletions app/configuration/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,25 @@ test('getStoreConfiguration should return configured store', () => {
expect(configuration.getStoreConfiguration()).toStrictEqual({ x: 'x', y: 'y' });
});

test('getServerConfiguration should return configured api (deprecated vars)', () => {
configuration.wudEnvVars.WUD_API_X = 'x';
configuration.wudEnvVars.WUD_API_Y = 'y';
expect(configuration.getServerConfiguration()).toStrictEqual({ x: 'x', y: 'y' });
});

test('getServerConfiguration should return configured api (new vars)', () => {
configuration.wudEnvVars.WUD_API_W = 'w';
configuration.wudEnvVars.WUD_API_X = 'x';
configuration.wudEnvVars.WUD_API_Y = 'y';
configuration.wudEnvVars.WUD_SERVER_X = 'x2';
configuration.wudEnvVars.WUD_SERVER_Y = 'y2';
expect(configuration.getServerConfiguration()).toStrictEqual({ w: 'w', x: 'x2', y: 'y2' });
configuration.wudEnvVars.WUD_SERVER_PORT = '4000';
expect(configuration.getServerConfiguration()).toStrictEqual({
cors: {},
enabled: true,
feature: {
delete: true,
},
port: 4000,
tls: {},
});
});

test('replaceSecrets must read secret in file', () => {
const vars = {
WUD_API_X__FILE: `${__dirname}/secret.txt`,
WUD_SERVER_X__FILE: `${__dirname}/secret.txt`,
};
configuration.replaceSecrets(vars);
expect(vars).toStrictEqual({
WUD_API_X: 'super_secret',
WUD_SERVER_X: 'super_secret',
});
});
2 changes: 1 addition & 1 deletion app/nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"env": {
"WUD_VERSION": "dev",
"WUD_STORE_PATH": ".store",
"WUD_WATCHER_LOCAL_WATCHBYDEFAULT": "false"
"WUD_WATCHER_LOCAL_WATCHBYDEFAULT": "true"
}
}
Loading

0 comments on commit 7f6c27f

Please sign in to comment.