fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-13 11:20:47 +02:00
parent 1b2eb1d763
commit adea8d1d69
5 changed files with 74 additions and 69 deletions

View File

@ -38,23 +38,23 @@ snyk:
# test stage # test stage
# ==================== # ====================
testLTS: testStable:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv - priv
testBuild: testBuild:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
@ -65,7 +65,7 @@ testBuild:
release: release:
stage: release stage: release
script: script:
- npmci node install lts - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
@ -100,7 +100,7 @@ trigger:
pages: pages:
image: hosttoday/ht-docker-dbase:npmci image: hosttoday/ht-docker-dbase:npmci
services: services:
- docker:18-dind - docker:stable-dind
stage: metadata stage: metadata
script: script:
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @gitzone/tsdoc

View File

@ -38,6 +38,6 @@ const myQenv = new Qenv('path/to/dir/where/qenv.yml/is/', 'path/to/dir/where/env
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

22
package-lock.json generated
View File

@ -425,9 +425,9 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "12.7.2", "version": "12.7.5",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.2.tgz", "resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.5.tgz",
"integrity": "sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==" "integrity": "sha512-9fq4jZVhPNW8r+UYKnxF1e2HkDWOWKM5bC2/7c9wPV835I0aOrVbS/Hw/pWPk2uKrNXQqg9Z959Kz+IYDd5p3w=="
}, },
"@types/vinyl": { "@types/vinyl": {
"version": "2.0.2", "version": "2.0.2",
@ -1456,16 +1456,16 @@
"dev": true "dev": true
}, },
"tslint": { "tslint": {
"version": "5.19.0", "version": "5.20.0",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.19.0.tgz", "resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz",
"integrity": "sha512-1LwwtBxfRJZnUvoS9c0uj8XQtAnyhWr9KlNvDIdB+oXyT+VpsOAaEhEgKi1HrZ8rq0ki/AAnbGSv4KM6/AfVZw==", "integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.0.0", "@babel/code-frame": "^7.0.0",
"builtin-modules": "^1.1.1", "builtin-modules": "^1.1.1",
"chalk": "^2.3.0", "chalk": "^2.3.0",
"commander": "^2.12.1", "commander": "^2.12.1",
"diff": "^3.2.0", "diff": "^4.0.1",
"glob": "^7.1.1", "glob": "^7.1.1",
"js-yaml": "^3.13.1", "js-yaml": "^3.13.1",
"minimatch": "^3.0.4", "minimatch": "^3.0.4",
@ -1474,14 +1474,6 @@
"semver": "^5.3.0", "semver": "^5.3.0",
"tslib": "^1.8.0", "tslib": "^1.8.0",
"tsutils": "^2.29.0" "tsutils": "^2.29.0"
},
"dependencies": {
"diff": {
"version": "3.5.0",
"resolved": "https://verdaccio.lossless.one/diff/-/diff-3.5.0.tgz",
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
"dev": true
}
} }
}, },
"tslint-config-prettier": { "tslint-config-prettier": {

View File

@ -29,8 +29,8 @@
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24", "@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.2", "@types/node": "^12.7.5",
"tslint": "^5.19.0", "tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {

View File

@ -64,40 +64,39 @@ export class Qenv {
/** /**
* tries to get any env var even if it is not required * tries to get any env var even if it is not required
* @param requiredEnvVar * @param wantedEnvVar
*/ */
public getEnvVarOnDemand(requiredEnvVar: string): string { public getEnvVarOnDemand(wantedEnvVar: string): string {
// lets determine the actual env yml let envVarFromEnvironmentVariable: string;
let envYml; let envVarFromEnvJsonFile: string;
try { let envVarFromDockerSecret: string;
envYml = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
} catch (err) {
envYml = {};
}
let envVar: string;
let envFileVar: string;
let dockerSecret: string;
let dockerSecretJson: string; let dockerSecretJson: string;
// env var check // env var check
if (process.env[requiredEnvVar]) { if (process.env[wantedEnvVar]) {
this.availableEnvVars.push(requiredEnvVar); this.availableEnvVars.push(wantedEnvVar);
envVar = process.env[requiredEnvVar]; envVarFromEnvironmentVariable = process.env[wantedEnvVar];
} }
// env file check // env file check
if (envYml.hasOwnProperty(requiredEnvVar)) { // lets determine the actual env yml
envFileVar = envYml[requiredEnvVar]; let envJsonFileAsObject;
this.availableEnvVars.push(requiredEnvVar); try {
envJsonFileAsObject = plugins.smartfile.fs.toObjectSync(this.envFilePathAbsolute);
} catch (err) {
envJsonFileAsObject = {};
}
if (envJsonFileAsObject.hasOwnProperty(wantedEnvVar)) {
envVarFromEnvJsonFile = envJsonFileAsObject[wantedEnvVar];
} }
// docker secret check // docker secret check
if ( if (
plugins.smartfile.fs.isDirectory('/run') && plugins.smartfile.fs.isDirectory('/run') &&
plugins.smartfile.fs.isDirectory('/run/secrets') && plugins.smartfile.fs.isDirectory('/run/secrets') &&
plugins.smartfile.fs.fileExistsSync(`/run/secrets/${requiredEnvVar}`) plugins.smartfile.fs.fileExistsSync(`/run/secrets/${wantedEnvVar}`)
) { ) {
dockerSecret = plugins.smartfile.fs.toStringSync(`/run/secrets/${requiredEnvVar}`); envVarFromDockerSecret = plugins.smartfile.fs.toStringSync(`/run/secrets/${wantedEnvVar}`);
} }
// docker secret.json // docker secret.json
@ -107,42 +106,53 @@ export class Qenv {
) { ) {
const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets'); const availableSecrets = plugins.smartfile.fs.listAllItemsSync('/run/secrets');
for (const secret of availableSecrets) { for (const secret of availableSecrets) {
if (secret.includes('secret.json') && !dockerSecret) { if (secret.includes('secret.json') && !envVarFromDockerSecret) {
const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`); const secretObject = plugins.smartfile.fs.toObjectSync(`/run/secrets/${secret}`);
dockerSecret = secretObject[requiredEnvVar]; envVarFromDockerSecret = secretObject[wantedEnvVar];
} }
} }
} }
// warn if there is more than one candidate // warn if there is more than one candidate
let candidatesCounter = 0; const availableCcandidates: any[] = [];
[envVar, envFileVar, dockerSecret, dockerSecretJson].forEach(candidate => { [
envVarFromEnvironmentVariable,
envVarFromEnvJsonFile,
envVarFromDockerSecret,
dockerSecretJson
].forEach(candidate => {
if (candidate) { if (candidate) {
candidatesCounter++; availableCcandidates.push(candidate);
} }
}); });
if (candidatesCounter > 1) { if (availableCcandidates.length > 1) {
this.logger.log( this.logger.log(
'warn', 'warn',
`found multiple candidates for ${requiredEnvVar} Choosing in the order of envVar, envFileVar, dockerSecret, dockerSecretJson` `found multiple candidates for ${wantedEnvVar} Choosing in the order of envVar, envFileVar, dockerSecret, dockerSecretJson`
); );
console.log(availableCcandidates);
} }
let chosenVar: string = null; switch (true) {
if (envVar) { case !!envVarFromEnvironmentVariable:
this.logger.log('ok', `found ${requiredEnvVar} as environment variable`); this.logger.log('ok', `found ${wantedEnvVar} as environment variable`);
chosenVar = envVar; return envVarFromEnvironmentVariable;
} else if (envFileVar) { case !!envVarFromEnvJsonFile:
this.logger.log('ok', `found ${requiredEnvVar} as env.json variable`); this.logger.log('ok', `found ${wantedEnvVar} as env.json variable`);
chosenVar = envFileVar; return envVarFromEnvJsonFile;
} else if (dockerSecret) { case !!envVarFromDockerSecret:
this.logger.log('ok', `found ${requiredEnvVar} as docker secret`); this.logger.log('ok', `found ${wantedEnvVar} as docker secret`);
chosenVar = dockerSecret; return envVarFromDockerSecret;
} else if (dockerSecretJson) { case !!dockerSecretJson:
this.logger.log('ok', `found ${requiredEnvVar} as docker secret.json`); this.logger.log('ok', `found ${wantedEnvVar} as docker secret.json`);
chosenVar = dockerSecretJson; return dockerSecretJson;
default:
this.logger.log(
'warn',
`could not find the wanted environment variable ${wantedEnvVar} anywhere`
);
return;
} }
return chosenVar;
} }
/** /**
@ -154,13 +164,16 @@ export class Qenv {
qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute); qenvFile = plugins.smartfile.fs.toObjectSync(this.qenvFilePathAbsolute);
} }
if (!qenvFile || !qenvFile.required || !Array.isArray(qenvFile.required)) { if (!qenvFile || !qenvFile.required || !Array.isArray(qenvFile.required)) {
this.logger.log('warn', `qenv (promised environment): ./env.yml File does not contain a 'required' Array!`); this.logger.log(
'warn',
`qenv (promised environment): ./env.yml File does not contain a 'required' Array!`
);
} else { } else {
for (const keyArg of Object.keys(qenvFile.required)) { for (const keyArg of Object.keys(qenvFile.required)) {
this.requiredEnvVars.push(qenvFile.required[keyArg]); this.requiredEnvVars.push(qenvFile.required[keyArg]);
} }
} }
} };
/** /**
* gets the available env vars * gets the available env vars