Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Several cleanups #117

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Set the following environment variables directly or by placing them in `.env` fi
| `REBOOT_SIGNAL_FILE` | Path to write a file to signal a system reboot | `/signals/reboot` |
| `MIDDLEWARE_API_URL` | IP or domain where [`umbrel-middleware`](https://github.com/getumbrel/umbrel-middleware) is listening | `http://localhost` |
| `MIDDLEWARE_API_PORT` | Port where [`umbrel-middleware`](https://github.com/getumbrel/umbrel-middleware) is listening | `3005` |
| `JWT_PUBLIC_KEY_FILE` | Path to the JWT public key (automatically created) | `/db/jwt-public-key/jwt.pem` |
| `JWT_PRIVATE_KEY_FILE` | Path to the JWT private key (automatically created) | `/db/jwt-public-key/jwt.key` |
| `JWT_PUBLIC_KEY_FILE` | Path to the JWT public key (automatically created) | `/jwt-public-key/jwt.pem` |
| `JWT_PRIVATE_KEY_FILE` | Path to the JWT private key (automatically created) | `/jwt-private-key/jwt.key` |
| `JWT_EXPIRATION` | JWT expiration in miliseconds | `3600` |
| `UMBREL_SEED_FILE` | Path to the seed used to deterministically generate entropy | `'/db/umbrel-seed/seed'` |
| `UMBREL_DASHBOARD_HIDDEN_SERVICE_FILE` | Path to Tor hostname of [`umbrel-dashboard`](https://github.com/getumbrel/umbrel-dashboard) | `/var/lib/tor/dashboard/hostname` |
Expand Down
2 changes: 1 addition & 1 deletion bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var http = require('http');
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3005');
var port = normalizePort(process.env.PORT || '3006');
app.set('port', port);

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"lint": "eslint",
"start": "node ./bin/www",
"test": "mocha --file test.setup 'test/**/*.js'",
"coverage": "nyc --all mocha --file test.setup 'test/**/*.js'",
"test": "mocha 'test/**/*.js'",
"coverage": "nyc --all mocha 'test/**/*.js'",
"postcoverage": "codecov"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion routes/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const pjson = require('../package.json');
const router = express.Router();

router.get('/', function (req, res) {
res.json({ version: 'umbrel-manager-' + pjson.version });
res.json({ version: pjson.name });
});

module.exports = router;
18 changes: 7 additions & 11 deletions services/bash.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
const childProcess = require('child_process');

// Sets environment variables on container.
// Env should not contain sensitive data, because environment variables are not secure.
function extendProcessEnv(env) {
Object.keys(env).map(function (objectKey) { // eslint-disable-line array-callback-return
process.env[objectKey] = env[objectKey];
});
}

// Executes docker-compose command with common options
const exec = (command, args, opts) => new Promise((resolve, reject) => {
const options = opts || {};

const cwd = options.cwd || null;

let spawnOptions = {
cwd
}

// Env should not contain sensitive data, because environment variables are not secure.
if (options.env) {
extendProcessEnv(options.env);
spawnOptions.env = options.env;
}

const childProc = childProcess.spawn(command, args, { cwd });
const childProc = childProcess.spawn(command, args, spawnOptions);

childProc.on('error', err => {
reject(err);
Expand Down
47 changes: 47 additions & 0 deletions test/services/bash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* globals requester */

const assert = require('assert');
const bash = require("../../services/bash");

describe('bash', () => {
it('should execute a command', done => {
const echoString = "Umbrel";

bash.exec('echo', [echoString])
.then(response => {
assert.equal(response.err, "");
assert.equal(response.out, echoString + "\n")

done();
});
});

it('should execute a command with ENV set', done => {
bash.exec('env', [], {
env: {
UMBREL_TEST_KEY: "UMBREL_TEST_VALUE"
}
})
.then(response => {
assert.equal(response.err, "");
expect(response.out).to.match(/(UMBREL_TEST_KEY=UMBREL_TEST_VALUE)/)

done();
});
});

it('should execute a command with ENV and make sure it is not previously polluted', done => {
bash.exec('env', [], {
env: {
UMBREL_TEST_KEY_2: "UMBREL_TEST_VALUE_2"
}
})
.then(response => {
assert.equal(response.err, "");
expect(response.out).to.not.match(/(UMBREL_TEST_KEY=UMBREL_TEST_VALUE)/)
expect(response.out).to.match(/(UMBREL_TEST_KEY_2=UMBREL_TEST_VALUE_2)/)

done();
});
});
});
4 changes: 2 additions & 2 deletions utils/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module.exports = {
TOR_HIDDEN_SERVICE_DIR: process.env.TOR_HIDDEN_SERVICE_DIR || '/var/lib/tor',
SHUTDOWN_SIGNAL_FILE: process.env.SHUTDOWN_SIGNAL_FILE || '/signals/shutdown',
REBOOT_SIGNAL_FILE: process.env.REBOOT_SIGNAL_FILE || '/signals/reboot',
JWT_PUBLIC_KEY_FILE: process.env.JWT_PUBLIC_KEY_FILE || '/db/jwt-public-key/jwt.pem',
JWT_PRIVATE_KEY_FILE: process.env.JWT_PRIVATE_KEY_FILE || '/db/jwt-private-key/jwt.key',
JWT_PUBLIC_KEY_FILE: process.env.JWT_PUBLIC_KEY_FILE || '/jwt-public-key/jwt.pem',
JWT_PRIVATE_KEY_FILE: process.env.JWT_PRIVATE_KEY_FILE || '/jwt-private-key/jwt.key',
UMBREL_SEED_FILE: process.env.UMBREL_SEED_FILE || '/db/umbrel-seed/seed',
UMBREL_DASHBOARD_HIDDEN_SERVICE_FILE: process.env.UMBREL_DASHBOARD_HIDDEN_SERVICE_FILE || '/var/lib/tor/web/hostname',
ELECTRUM_HIDDEN_SERVICE_FILE: process.env.ELECTRUM_HIDDEN_SERVICE_FILE || '/var/lib/tor/electrum/hostname',
Expand Down