fix(striker-ui-api): add getPeerData() to accessModule

main
Tsu-ba-me 2 years ago
parent 0a3d36c340
commit e394b0736e
  1. 30
      striker-ui-api/src/lib/accessModule.ts
  2. 41
      striker-ui-api/src/lib/request_handlers/command/getHostSSH.ts
  3. 3
      striker-ui-api/src/types/DBInsertOrUpdateFunctionCommon.d.ts
  4. 28
      striker-ui-api/src/types/GetPeerDataFunction.d.ts
  5. 3
      striker-ui-api/src/types/ModuleSubroutineCommonParams.d.ts

@ -164,6 +164,35 @@ const getLocalHostUUID = () => {
return result;
};
const getPeerData: GetPeerDataFunction = (
target,
{ password, port, ...restOptions } = {},
) => {
const [
rawIsConnected,
{
host_name: hostName,
host_os: hostOS,
host_uuid: hostUUID,
internet: rawIsInetConnected,
os_registered: rawIsOSRegistered,
},
] = execModuleSubroutine('get_peer_data', {
subModuleName: 'Striker',
subParams: { password, port, target },
...restOptions,
}).stdout as [connected: string, data: PeerDataHash];
return {
hostName,
hostOS,
hostUUID,
isConnected: rawIsConnected === '1',
isInetConnected: rawIsInetConnected === '1',
isOSRegistered: rawIsOSRegistered === 'yes',
};
};
export {
dbInsertOrUpdateJob as job,
dbInsertOrUpdateVariable as variable,
@ -173,5 +202,6 @@ export {
dbWrite,
getAnvilData,
getLocalHostUUID,
getPeerData,
execModuleSubroutine as sub,
};

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { HOST_KEY_CHANGED_PREFIX } from '../../consts/HOST_KEY_CHANGED_PREFIX';
import { dbQuery, getLocalHostUUID, sub } from '../../accessModule';
import { dbQuery, getLocalHostUUID, getPeerData } from '../../accessModule';
import { sanitizeSQLParam } from '../../sanitizeSQLParam';
import { stderr } from '../../shell';
@ -27,31 +27,24 @@ export const getHostSSH: RequestHandler<
body: { password, port = 22, ipAddress: target },
} = request;
let hostName: string,
hostOS: string,
hostUUID: string,
rawIsInetConnected: string,
rawIsOSRegistered: string;
let hostName: string;
let hostOS: string;
let hostUUID: string;
let isConnected: boolean;
let isInetConnected: boolean;
let isOSRegistered: boolean;
const localHostUUID = getLocalHostUUID();
try {
({
host_name: hostName,
host_os: hostOS,
host_uuid: hostUUID,
internet: rawIsInetConnected,
os_registered: rawIsOSRegistered,
} = sub('get_peer_data', {
subModuleName: 'Striker',
subParams: { password, port, target },
}).stdout as {
host_name: string;
host_os: string;
host_uuid: string;
internet: string;
os_registered: string;
});
hostName,
hostOS,
hostUUID,
isConnected,
isInetConnected,
isOSRegistered,
} = getPeerData(target, { password, port }));
} catch (subError) {
stderr(`Failed to get peer data; CAUSE: ${subError}`);
@ -60,8 +53,6 @@ export const getHostSSH: RequestHandler<
return;
}
const isConnected: boolean = hostName.length > 0;
let badSSHKeys: DeleteSSHKeyConflictRequestBody | undefined;
if (!isConnected) {
@ -91,7 +82,7 @@ export const getHostSSH: RequestHandler<
hostOS,
hostUUID,
isConnected,
isInetConnected: rawIsInetConnected === '1',
isOSRegistered: rawIsOSRegistered === 'yes',
isInetConnected,
isOSRegistered,
});
};

@ -1,5 +1,4 @@
type DBInsertOrUpdateFunctionCommonParams = {
debug?: number;
type DBInsertOrUpdateFunctionCommonParams = ModuleSubroutineCommonParams & {
file: string;
line?: number;
};

@ -0,0 +1,28 @@
type PeerDataHash = {
host_name: string;
host_os: string;
host_uuid: string;
internet: string;
os_registered: string;
};
type GetPeerDataOptions = Omit<
ExecModuleSubroutineOptions,
'subModuleName' | 'subParams'
> &
ModuleSubroutineCommonParams & {
password?: string;
port?: number;
};
type GetPeerDataFunction = (
target: string,
options?: GetPeerDataOptions,
) => {
hostName: string;
hostOS: string;
hostUUID: string;
isConnected: boolean;
isInetConnected: boolean;
isOSRegistered: boolean;
};

@ -0,0 +1,3 @@
type ModuleSubroutineCommonParams = {
debug?: number;
};
Loading…
Cancel
Save