From db248efd96a033fae10e0f3a14beaa1aa42f0aea Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 17 Mar 2023 16:21:44 -0400 Subject: [PATCH] fix(striker-ui-api): consolidate disassemble host name functions --- striker-ui-api/src/lib/disassembleHostName.ts | 8 ++++++++ striker-ui-api/src/lib/getShortHostName.ts | 2 -- .../src/lib/request_handlers/host/buildQueryHostDetail.ts | 2 +- striker-ui-api/src/lib/request_handlers/host/getHost.ts | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 striker-ui-api/src/lib/disassembleHostName.ts delete mode 100644 striker-ui-api/src/lib/getShortHostName.ts diff --git a/striker-ui-api/src/lib/disassembleHostName.ts b/striker-ui-api/src/lib/disassembleHostName.ts new file mode 100644 index 00000000..c30593a5 --- /dev/null +++ b/striker-ui-api/src/lib/disassembleHostName.ts @@ -0,0 +1,8 @@ +export const getHostNameDomain = (hostName: string) => + hostName.replace(/^.*?[.]/, ''); + +export const getHostNamePrefix = (hostName: string) => + hostName.replace(/-.*$/, ''); + +export const getShortHostName = (hostName: string) => + hostName.replace(/[.].*$/, ''); diff --git a/striker-ui-api/src/lib/getShortHostName.ts b/striker-ui-api/src/lib/getShortHostName.ts deleted file mode 100644 index 1cd3daa1..00000000 --- a/striker-ui-api/src/lib/getShortHostName.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const getShortHostName = (hostName: string) => - hostName.replace(/[.].*$/, ''); diff --git a/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts b/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts index 05da6d53..155fd06b 100644 --- a/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts +++ b/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts @@ -1,7 +1,7 @@ import { buildKnownIDCondition } from '../../buildCondition'; import { buildQueryResultModifier } from '../../buildQueryResultModifier'; import { cap } from '../../cap'; -import { getShortHostName } from '../../getShortHostName'; +import { getShortHostName } from '../../disassembleHostName'; import { stdout } from '../../shell'; type ExtractVariableKeyFunction = (parts: string[]) => string; diff --git a/striker-ui-api/src/lib/request_handlers/host/getHost.ts b/striker-ui-api/src/lib/request_handlers/host/getHost.ts index 8e5b2000..1b47cdaa 100644 --- a/striker-ui-api/src/lib/request_handlers/host/getHost.ts +++ b/striker-ui-api/src/lib/request_handlers/host/getHost.ts @@ -4,7 +4,7 @@ import buildGetRequestHandler from '../buildGetRequestHandler'; import { buildQueryHostDetail } from './buildQueryHostDetail'; import { buildQueryResultReducer } from '../../buildQueryResultModifier'; import { toLocal } from '../../convertHostUUID'; -import { getShortHostName } from '../../getShortHostName'; +import { getShortHostName } from '../../disassembleHostName'; import { sanitize } from '../../sanitize'; export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {