fix(striker-ui-api): make getAnvilData generic to identify return value

main
Tsu-ba-me 2 years ago committed by digimer
parent 3dd6eb487e
commit dd6315caf9
  1. 4
      striker-ui-api/src/lib/accessModule.ts
  2. 2
      striker-ui-api/src/lib/request_handlers/fence/getFenceTemplate.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts
  4. 8
      striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts
  5. 3
      striker-ui-api/src/types/AnvilDataStruct.d.ts
  6. 10
      striker-ui-api/src/types/DatabaseHash.d.ts
  7. 26
      striker-ui-api/src/types/GetAnvilDataFunction.d.ts
  8. 3
      striker-ui-api/src/types/GetAnvilDataOptions.d.ts

@ -134,10 +134,10 @@ const dbWrite = (query: string, options?: SpawnSyncOptions) => {
return execAnvilAccessModule(['--query', query, '--mode', 'write'], options);
};
const getAnvilData = (
const getAnvilData = <HashType>(
dataStruct: AnvilDataStruct,
{ predata, ...spawnSyncOptions }: GetAnvilDataOptions = {},
) =>
): HashType =>
execAnvilAccessModule(
[
'--predata',

@ -6,7 +6,7 @@ export const getFenceTemplate: RequestHandler = (request, response) => {
let rawFenceData;
try {
({ fence_data: rawFenceData } = getAnvilData(
({ fence_data: rawFenceData } = getAnvilData<{ fence_data: unknown }>(
{ fence_data: true },
{ predata: [['Striker->get_fence_data']] },
));

@ -154,7 +154,7 @@ export const createHostConnection: RequestHandler<
database: {
[localHostUUID]: { port: rawLocalDBPort },
},
} = getAnvilData({ database: true }) as { database: DatabaseHash };
} = getAnvilData<{ database: AnvilDataDatabaseHash }>({ database: true });
localDBPort = sanitize(rawLocalDBPort, 'number');
} catch (subError) {

@ -7,7 +7,7 @@ import { stdout } from '../../shell';
const buildHostConnections = (
fromHostUUID: string,
databaseHash: DatabaseHash,
databaseHash: AnvilDataDatabaseHash,
{
defaultPort = 5432,
defaultUser = 'admin',
@ -42,7 +42,7 @@ export const getHostConnection = buildGetRequestHandler(
(request, buildQueryOptions) => {
const { hostUUIDs: rawHostUUIDs } = request.query;
let rawDatabaseData: DatabaseHash;
let rawDatabaseData: AnvilDataDatabaseHash;
const hostUUIDField = 'ip_add.ip_address_host_uuid';
const localHostUUID: string = getLocalHostUUID();
@ -59,7 +59,9 @@ export const getHostConnection = buildGetRequestHandler(
stdout(`condHostUUIDs=[${condHostUUIDs}]`);
try {
({ database: rawDatabaseData } = getAnvilData({ database: true }));
({ database: rawDatabaseData } = getAnvilData<{ database: AnvilDataDatabaseHash }>(
{ database: true },
));
} catch (subError) {
throw new Error(`Failed to get anvil data; CAUSE: ${subError}`);
}

@ -1,3 +0,0 @@
interface AnvilDataStruct {
[key: string]: AnvilDataStruct | boolean;
}

@ -1,10 +0,0 @@
type DatabaseHash = {
[hostUUID: string]: {
host: string;
name: string;
password: string;
ping: string;
port: string;
user: string;
};
};

@ -0,0 +1,26 @@
interface AnvilDataStruct {
[key: string]: AnvilDataStruct | boolean;
}
type AnvilDataDatabaseHash = {
[hostUUID: string]: {
host: string;
name: string;
password: string;
ping: string;
port: string;
user: string;
};
};
type AnvilDataUPSHash = {
[upsName: string]: {
agent: string;
brand: string;
description: string;
};
};
type GetAnvilDataOptions = import('child_process').SpawnSyncOptions & {
predata?: Array<[string, ...unknown[]]>;
};

@ -1,3 +0,0 @@
type GetAnvilDataOptions = import('child_process').SpawnSyncOptions & {
predata?: Array<[string, ...unknown[]]>;
};
Loading…
Cancel
Save