fix(striker-ui-api): simplify local host name/uuid getter

main
Tsu-ba-me 2 years ago
parent 448a956313
commit b0e7859d2d
  1. 28
      striker-ui-api/src/lib/accessModule.ts
  2. 4
      striker-ui-api/src/lib/consts/SERVER_PATHS.ts
  3. 4
      striker-ui-api/src/lib/consts/index.ts

@ -1,6 +1,7 @@
import { spawnSync, SpawnSyncOptions } from 'child_process';
import { readFileSync } from 'fs';
import SERVER_PATHS from './consts/SERVER_PATHS';
import { SERVER_PATHS } from './consts';
import { stderr as sherr, stdout as shout } from './shell';
@ -8,15 +9,18 @@ const formatQuery = (query: string) => query.replace(/\s+/g, ' ');
const execAnvilAccessModule = (
args: string[],
options: SpawnSyncOptions = {
encoding: 'utf-8',
timeout: 10000,
},
options: SpawnSyncOptions = {},
) => {
const {
encoding = 'utf-8',
timeout = 10000,
...restSpawnSyncOptions
} = options;
const { error, stdout, stderr } = spawnSync(
SERVER_PATHS.usr.sbin['anvil-access-module'].self,
args,
options,
{ encoding, timeout, ...restSpawnSyncOptions },
);
if (error) {
@ -152,9 +156,9 @@ const getLocalHostName = () => {
let result: string;
try {
result = execModuleSubroutine('host_name', {
subModuleName: 'Get',
}).stdout;
result = readFileSync(SERVER_PATHS.etc.hostname.self, {
encoding: 'utf-8',
}).trim();
} catch (subError) {
throw new Error(`Failed to get local host name; CAUSE: ${subError}`);
}
@ -168,9 +172,9 @@ const getLocalHostUUID = () => {
let result: string;
try {
result = execModuleSubroutine('host_uuid', {
subModuleName: 'Get',
}).stdout;
result = readFileSync(SERVER_PATHS.etc.anvil['host.uuid'].self, {
encoding: 'utf-8',
}).trim();
} catch (subError) {
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`);
}

@ -1,6 +1,10 @@
import path from 'path';
const EMPTY_SERVER_PATHS: ServerPath = {
etc: {
anvil: { 'host.uuid': {} },
hostname: {},
},
mnt: {
shared: {
incoming: {},

@ -1,3 +1,7 @@
import SERVER_PATHS from './SERVER_PATHS';
export { SERVER_PATHS };
export * from './AN_VARIABLE_NAME_LIST';
export * from './EXIT_CODE_LIST';
export * from './PROCESS_OWNER';

Loading…
Cancel
Save