From 7d73fc931e34f679040203739fb7dda1df57f78b Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 27 Apr 2023 18:18:11 -0400 Subject: [PATCH] fix(striker-ui-api): migrate insert or update variable to access interact --- striker-ui-api/src/lib/accessModule.ts | 19 ++++++++++--------- striker-ui-api/src/lib/getSessionSecret.ts | 2 +- .../lib/request_handlers/host/prepareHost.ts | 16 ++++++---------- .../DBInsertOrUpdateVariableFunction.d.ts | 7 ++----- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/striker-ui-api/src/lib/accessModule.ts b/striker-ui-api/src/lib/accessModule.ts index fa054b87..0ef89bc2 100644 --- a/striker-ui-api/src/lib/accessModule.ts +++ b/striker-ui-api/src/lib/accessModule.ts @@ -270,14 +270,15 @@ const dbInsertOrUpdateJob = ( subParams: { job_progress, line, ...rest }, }).stdout; -const dbInsertOrUpdateVariable: DBInsertOrUpdateVariableFunction = ( - subParams, - { spawnSyncOptions } = {}, -) => - execModuleSubroutine('insert_or_update_variables', { - spawnSyncOptions, - subParams, - }).stdout; +const insertOrUpdateVariable: DBInsertOrUpdateVariableFunction = async ( + params, +) => { + const [uuid]: [string] = await subroutine('insert_or_update_variables', { + params: [params], + }); + + return uuid; +}; const dbJobAnvilSyncShared = ( jobName: string, @@ -420,7 +421,7 @@ const getUpsSpec = async () => { export { dbInsertOrUpdateJob as job, - dbInsertOrUpdateVariable as variable, + insertOrUpdateVariable as variable, dbJobAnvilSyncShared, dbSubRefreshTimestamp as timestamp, getData, diff --git a/striker-ui-api/src/lib/getSessionSecret.ts b/striker-ui-api/src/lib/getSessionSecret.ts index cc20ba04..46878e74 100644 --- a/striker-ui-api/src/lib/getSessionSecret.ts +++ b/striker-ui-api/src/lib/getSessionSecret.ts @@ -39,7 +39,7 @@ export const getSessionSecret = async (): Promise => { } try { - const vuuid = variable({ + const vuuid = await variable({ file: __filename, variable_name: VNAME_SESSION_SECRET, variable_value: sessionSecret, diff --git a/striker-ui-api/src/lib/request_handlers/host/prepareHost.ts b/striker-ui-api/src/lib/request_handlers/host/prepareHost.ts index 3b402136..8031d438 100644 --- a/striker-ui-api/src/lib/request_handlers/host/prepareHost.ts +++ b/striker-ui-api/src/lib/request_handlers/host/prepareHost.ts @@ -6,8 +6,8 @@ import { REP_IPV4, REP_PEACEFUL_STRING, REP_UUID, -} from '../../consts/REG_EXP_PATTERNS'; -import SERVER_PATHS from '../../consts/SERVER_PATHS'; + SERVER_PATHS, +} from '../../consts'; import { job, variable } from '../../accessModule'; import { sanitize } from '../../sanitize'; @@ -17,7 +17,7 @@ export const prepareHost: RequestHandler< unknown, undefined, PrepareHostRequestBody -> = (request, response) => { +> = async (request, response) => { const { body: { enterpriseUUID, @@ -106,14 +106,12 @@ export const prepareHost: RequestHandler< `Failed to assert value when trying to prepare host; CAUSE: ${assertError}`, ); - response.status(400).send(); - - return; + return response.status(400).send(); } try { if (isHostUUIDProvided) { - variable({ + await variable({ file: __filename, update_value_only: 1, variable_name: 'system::configured', @@ -141,9 +139,7 @@ type=${dataHostType}`, } catch (subError) { stderr(`Failed to init host; CAUSE: ${subError}`); - response.status(500).send(); - - return; + return response.status(500).send(); } response.status(200).send(); diff --git a/striker-ui-api/src/types/DBInsertOrUpdateVariableFunction.d.ts b/striker-ui-api/src/types/DBInsertOrUpdateVariableFunction.d.ts index 07310ed9..bce32c5d 100644 --- a/striker-ui-api/src/types/DBInsertOrUpdateVariableFunction.d.ts +++ b/striker-ui-api/src/types/DBInsertOrUpdateVariableFunction.d.ts @@ -10,9 +10,6 @@ type DBVariableParams = DBInsertOrUpdateFunctionCommonParams & { variable_value?: number | string; }; -type DBInsertOrUpdateVariableOptions = DBInsertOrUpdateFunctionCommonOptions; - type DBInsertOrUpdateVariableFunction = ( - subParams: DBVariableParams, - options?: DBInsertOrUpdateVariableOptions, -) => string; + params: DBVariableParams, +) => Promise;