sdk/ts/sdk.classes.aghandler.ts

50 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2020-03-25 15:16:03 +00:00
import * as plugins from './sdk.plugins';
2020-03-25 20:15:46 +00:00
import { AuthInfo } from './sdk.classes.authinfo';
2020-09-22 23:06:34 +00:00
import { AgEnvironment } from './sdk.classes.agenvironment';
2020-03-25 15:16:03 +00:00
2020-07-04 14:38:25 +00:00
export interface IRequirementResult {
allOk: boolean;
reason: string;
}
2020-03-25 20:15:46 +00:00
export abstract class AAgHandler<TClaim> {
2020-09-22 23:06:34 +00:00
public agEnvironment: AgEnvironment;
2020-03-25 15:16:03 +00:00
/**
* a slug that separates the handler from other handlers
*/
public abstract slug: string;
2020-09-23 21:24:32 +00:00
public abstract typedrouter: plugins.typedrequest.TypedRouter;
2020-07-05 15:16:50 +00:00
public abstract checkRequirements(): Promise<IRequirementResult>;
2020-09-23 22:34:42 +00:00
public async checkQenvFile(pathToQenvFileArg: string) {
if(!(await plugins.smartfile.fs.fileExists(pathToQenvFileArg))) {
throw new Error(`AgHandler with slug '${this.slug}': qenv file does not exists at ${pathToQenvFileArg}`);
}
const qenvFile = plugins.smartfile.fs.toObjectSync(pathToQenvFileArg);
const missingEnvironmentVariables: string[] = [];
for (const envVar of qenvFile.required as string[]) {
const result = this.agEnvironment.getEnvVar(envVar);
if (!result) {
missingEnvironmentVariables.push(envVar);
}
}
if (missingEnvironmentVariables.length > 0) {
console.log(`AgHandler with slug '${this.slug}': There are ${missingEnvironmentVariables.length} missing environment variables`);
const errorMessage = `AgHandler with slug '${this.slug}': The missing env Varibles are ${missingEnvironmentVariables}`;
console.log(errorMessage);
throw new Error(errorMessage);
}
}
2020-09-22 23:06:34 +00:00
constructor(agEnvironmentArg: AgEnvironment) {
this.agEnvironment = agEnvironmentArg;
2020-09-23 21:24:32 +00:00
}
2020-09-22 23:06:34 +00:00
2020-07-04 14:38:25 +00:00
/**
* start the ag-handler
*/
public abstract start(): Promise<any>;
public abstract stop(): Promise<any>;
2020-07-04 14:50:24 +00:00
}