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

main
Tsu-ba-me 2 years ago
parent 941221fa41
commit 508c7aa1f5
  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); return execAnvilAccessModule(['--query', query, '--mode', 'write'], options);
}; };
const getAnvilData = ( const getAnvilData = <HashType>(
dataStruct: AnvilDataStruct, dataStruct: AnvilDataStruct,
{ predata, ...spawnSyncOptions }: GetAnvilDataOptions = {}, { predata, ...spawnSyncOptions }: GetAnvilDataOptions = {},
) => ): HashType =>
execAnvilAccessModule( execAnvilAccessModule(
[ [
'--predata', '--predata',

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

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

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