docker-secreto
Advanced tools
Comparing version 1.0.3 to 1.1.0
59
index.js
const fs = require('fs') | ||
const secretos = (key, defaultValue) => new Promise((resolve, reject) => { | ||
fs.readdir('/run/secrets', (err, files) => { | ||
const secrets = files.map(file => { | ||
const secretos = (key, defaultValue) => { | ||
let files = [], | ||
secrets | ||
try { | ||
files = fs.readdirSync('/run/secrets') | ||
} catch (ex) { | ||
// No /run/secrets directory | ||
} | ||
secrets = files.map(file => { | ||
try { | ||
const secret = fs.readFileSync(`/run/secrets/${file}`).toString() | ||
return { file, secret } | ||
}) | ||
} catch (ex) { | ||
let secretObjects = {} | ||
if (secrets.length > 0) { | ||
if (!key) { | ||
secrets.forEach(secret => { | ||
secretObjects[secret.file] = secret.secret | ||
}) | ||
} else { | ||
let value = secrets[key] || defaultValue | ||
secretObjects = value | ||
} | ||
resolve(secretObjects) | ||
} else { | ||
if (defaultValue) { | ||
secretObjects = defaultValue | ||
} else if (key && !defaultValue) { | ||
secretObjects[key] = {} | ||
} | ||
resolve(secretObjects) | ||
} | ||
}) | ||
}) | ||
let secretObjects = {} | ||
if (secrets.length > 0) { | ||
if (!key) { | ||
secrets.forEach(secret => { | ||
secretObjects[secret.file] = secret.secret | ||
}) | ||
} else | ||
secretObjects = secrets[key] || defaultValue | ||
return secretObjects | ||
} else { | ||
if (defaultValue) | ||
secretObjects = defaultValue | ||
else if (key && !defaultValue) | ||
secretObjects[key] = {} | ||
return secretObjects | ||
} | ||
} | ||
module.exports = secretos |
{ | ||
"name": "docker-secreto", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "pull docker secrets into an object", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,7 +12,7 @@ # docker-secreto | ||
```js | ||
const secreto = require('docker-secreto') | ||
const dockerSecreto = require('docker-secreto') | ||
secreto() | ||
.then(secretos => console.info(secretos)) | ||
.catch(err => console.error(err)) | ||
let values = dockerSecreto() | ||
console.info(values) | ||
``` | ||
@@ -30,7 +30,7 @@ | ||
```js | ||
const secreto = require('docker-secreto') | ||
const dockerSecreto = require('docker-secreto') | ||
secreto('secret_name', 'Default Value') | ||
.then(secretos => console.info(secretos)) | ||
.catch(err => console.error(err)) | ||
let values = dockerSecreto('secret_name', 'Default Value') | ||
console.info(values) | ||
``` | ||
@@ -45,7 +45,7 @@ | ||
```js | ||
const secreto = require('docker-secreto') | ||
const dockerSecreto = require('docker-secreto') | ||
secreto('secret_name', 'Default Value') | ||
.then(secretos => console.info(secretos)) | ||
.catch(err => console.error(err)) | ||
let values = dockerSecreto('secret_name', 'Default Value') | ||
console.info(values) | ||
``` | ||
@@ -52,0 +52,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34
2026