fix(core): update
This commit is contained in:
parent
3c7e3e2589
commit
c9f79e6ea4
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/qenv',
|
||||
version: '6.0.0',
|
||||
version: '6.0.1',
|
||||
description: 'easy promised environments'
|
||||
}
|
||||
|
@ -22,8 +22,14 @@ export class Qenv {
|
||||
}
|
||||
|
||||
private initializeFilePaths(qenvFileBasePathArg: string, envFileBasePathArg: string) {
|
||||
this.qenvFilePathAbsolute = plugins.path.join(plugins.path.resolve(qenvFileBasePathArg), 'qenv.yml');
|
||||
this.envFilePathAbsolute = plugins.path.join(plugins.path.resolve(envFileBasePathArg), 'env.json');
|
||||
this.qenvFilePathAbsolute = plugins.path.join(
|
||||
plugins.path.resolve(qenvFileBasePathArg),
|
||||
'qenv.yml'
|
||||
);
|
||||
this.envFilePathAbsolute = plugins.path.join(
|
||||
plugins.path.resolve(envFileBasePathArg),
|
||||
'env.json'
|
||||
);
|
||||
}
|
||||
|
||||
private loadRequiredEnvVars() {
|
||||
@ -48,7 +54,9 @@ export class Qenv {
|
||||
}
|
||||
|
||||
private checkForMissingEnvVars(failOnMissing: boolean) {
|
||||
this.missingEnvVars = this.requiredEnvVars.filter((envVar) => !this.availableEnvVars.includes(envVar));
|
||||
this.missingEnvVars = this.requiredEnvVars.filter(
|
||||
(envVar) => !this.availableEnvVars.includes(envVar)
|
||||
);
|
||||
|
||||
if (this.missingEnvVars.length > 0) {
|
||||
console.info('Required Env Vars are:', this.requiredEnvVars);
|
||||
@ -62,27 +70,40 @@ export class Qenv {
|
||||
}
|
||||
}
|
||||
|
||||
public async getEnvVarOnDemand(envVarName: string): Promise<string | undefined> {
|
||||
return (
|
||||
this.getFromEnvironmentVariable(envVarName) ||
|
||||
this.getFromEnvJsonFile(envVarName) ||
|
||||
this.getFromDockerSecret(envVarName) ||
|
||||
this.getFromDockerSecretJson(envVarName)
|
||||
);
|
||||
public async getEnvVarOnDemand(
|
||||
envVarNameOrNames: string | string[]
|
||||
): Promise<string | undefined> {
|
||||
if (Array.isArray(envVarNameOrNames)) {
|
||||
for (const envVarName of envVarNameOrNames) {
|
||||
const value = await this.tryGetEnvVar(envVarName);
|
||||
if (value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
} else {
|
||||
return await this.tryGetEnvVar(envVarNameOrNames);
|
||||
}
|
||||
}
|
||||
|
||||
public async getEnvVarOnDemandSync(envVarName: string): Promise<string | undefined> {
|
||||
public getEnvVarOnDemandSync(envVarNameOrNames: string | string[]): string | undefined {
|
||||
console.warn('requesting env var sync leaves out potentially important async env sources.');
|
||||
return (
|
||||
this.getFromEnvironmentVariable(envVarName) ||
|
||||
this.getFromEnvJsonFile(envVarName) ||
|
||||
this.getFromDockerSecret(envVarName) ||
|
||||
this.getFromDockerSecretJson(envVarName)
|
||||
);
|
||||
|
||||
if (Array.isArray(envVarNameOrNames)) {
|
||||
for (const envVarName of envVarNameOrNames) {
|
||||
const value = this.tryGetEnvVarSync(envVarName);
|
||||
if (value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
} else {
|
||||
return this.tryGetEnvVarSync(envVarNameOrNames);
|
||||
}
|
||||
}
|
||||
|
||||
public async getEnvVarOnDemandAsObject(envVarName: string): Promise<any> {
|
||||
const rawValue = await this.getEnvVarOnDemand(envVarName);
|
||||
public async getEnvVarOnDemandAsObject(envVarNameOrNames: string | string[]): Promise<any> {
|
||||
const rawValue = await this.getEnvVarOnDemand(envVarNameOrNames);
|
||||
if (rawValue && rawValue.startsWith('base64Object:')) {
|
||||
const base64Part = rawValue.split('base64Object:')[1];
|
||||
return this.decodeBase64(base64Part);
|
||||
@ -90,6 +111,24 @@ export class Qenv {
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
private async tryGetEnvVar(envVarName: string): Promise<string | undefined> {
|
||||
return (
|
||||
this.getFromEnvironmentVariable(envVarName) ||
|
||||
this.getFromEnvJsonFile(envVarName) ||
|
||||
this.getFromDockerSecret(envVarName) ||
|
||||
this.getFromDockerSecretJson(envVarName)
|
||||
);
|
||||
}
|
||||
|
||||
private tryGetEnvVarSync(envVarName: string): string | undefined {
|
||||
return (
|
||||
this.getFromEnvironmentVariable(envVarName) ||
|
||||
this.getFromEnvJsonFile(envVarName) ||
|
||||
this.getFromDockerSecret(envVarName) ||
|
||||
this.getFromDockerSecretJson(envVarName)
|
||||
);
|
||||
}
|
||||
|
||||
private getFromEnvironmentVariable(envVarName: string): string | undefined {
|
||||
return process.env[envVarName];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user