Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit 6e74c78

Browse files
committed
Prevent error when secrets directory not found
If no secrets are found, simply returns an empty object. At least prevents the code from exploding.
1 parent 2b9e515 commit 6e74c78

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ const path = require('path');
66
const SECRETS_DIR = '/run/secrets';
77
const output = {};
88

9-
const files = fs.readdirSync(SECRETS_DIR);
9+
if (fs.existsSync(SECRETS_DIR)) {
10+
const files = fs.readdirSync(SECRETS_DIR);
1011

11-
files.forEach(function(file, index) {
12-
const fullPath = path.join(SECRETS_DIR, file);
13-
const key = file;
14-
const data = fs.readFileSync(fullPath, 'utf8').toString().trim();
12+
files.forEach(function(file, index) {
13+
const fullPath = path.join(SECRETS_DIR, file);
14+
const key = file;
15+
const data = fs.readFileSync(fullPath, 'utf8').toString().trim();
1516

16-
output[key] = data;
17-
});
17+
output[key] = data;
18+
});
19+
}
1820

1921
module.exports = output;

0 commit comments

Comments
 (0)