refactor(striker-ui-api): group API-related types by endpoint

main
Tsu-ba-me 2 years ago
parent 46891f322b
commit 5c7ddbfb5e
  1. 6
      striker-ui-api/src/lib/request_handlers/command/getHostSSH.ts
  2. 6
      striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/ssh-key/deleteSSHKeyConflict.ts
  4. 11
      striker-ui-api/src/lib/request_handlers/ssh-key/getSSHKeyConflict.ts
  5. 2
      striker-ui-api/src/lib/request_handlers/ups/getUPS.ts
  6. 4
      striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts
  7. 8
      striker-ui-api/src/types/AnvilOverview.d.ts
  8. 9
      striker-ui-api/src/types/ApiAn.d.ts
  9. 0
      striker-ui-api/src/types/ApiAuth.d.ts
  10. 0
      striker-ui-api/src/types/ApiFence.d.ts
  11. 89
      striker-ui-api/src/types/ApiHost.d.ts
  12. 0
      striker-ui-api/src/types/ApiManifest.d.ts
  13. 0
      striker-ui-api/src/types/ApiNetworkInterface.d.ts
  14. 0
      striker-ui-api/src/types/ApiServer.d.ts
  15. 12
      striker-ui-api/src/types/ApiSshKey.d.ts
  16. 4
      striker-ui-api/src/types/ApiUps.d.ts
  17. 7
      striker-ui-api/src/types/ApiUser.d.ts
  18. 11
      striker-ui-api/src/types/CreateHostConnectionRequestBody.d.ts
  19. 3
      striker-ui-api/src/types/DeleteHostConnectionRequestBody.d.ts
  20. 1
      striker-ui-api/src/types/DeleteSSHKeyConflictRequestBody.d.ts
  21. 25
      striker-ui-api/src/types/HostConnectionOverview.d.ts
  22. 6
      striker-ui-api/src/types/HostOverview.d.ts
  23. 19
      striker-ui-api/src/types/InitializeStrikerForm.d.ts
  24. 20
      striker-ui-api/src/types/UpdateHostRequestBody.d.ts

@ -9,7 +9,7 @@ import { stderr } from '../../shell';
export const getHostSSH: RequestHandler< export const getHostSSH: RequestHandler<
unknown, unknown,
{ {
badSSHKeys?: DeleteSSHKeyConflictRequestBody; badSSHKeys?: DeleteSshKeyConflictRequestBody;
hostName: string; hostName: string;
hostOS: string; hostOS: string;
hostUUID: string; hostUUID: string;
@ -53,7 +53,7 @@ export const getHostSSH: RequestHandler<
return; return;
} }
let badSSHKeys: DeleteSSHKeyConflictRequestBody | undefined; let badSSHKeys: DeleteSshKeyConflictRequestBody | undefined;
if (!isConnected) { if (!isConnected) {
const rows = dbQuery(` const rows = dbQuery(`
@ -65,7 +65,7 @@ export const getHostSSH: RequestHandler<
)}';`).stdout as [stateNote: string, stateUUID: string][]; )}';`).stdout as [stateNote: string, stateUUID: string][];
if (rows.length > 0) { if (rows.length > 0) {
badSSHKeys = rows.reduce<DeleteSSHKeyConflictRequestBody>( badSSHKeys = rows.reduce<DeleteSshKeyConflictRequestBody>(
(previous, [, stateUUID]) => { (previous, [, stateUUID]) => {
previous[localHostUUID].push(stateUUID); previous[localHostUUID].push(stateUUID);

@ -59,9 +59,9 @@ export const getHostConnection = buildGetRequestHandler(
stdout(`condHostUUIDs=[${condHostUUIDs}]`); stdout(`condHostUUIDs=[${condHostUUIDs}]`);
try { try {
({ database: rawDatabaseData } = getAnvilData<{ database: AnvilDataDatabaseHash }>( ({ database: rawDatabaseData } = getAnvilData<{
{ database: true }, 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}`);
} }

@ -9,7 +9,7 @@ import { stderr } from '../../shell';
export const deleteSSHKeyConflict: RequestHandler< export const deleteSSHKeyConflict: RequestHandler<
unknown, unknown,
undefined, undefined,
DeleteSSHKeyConflictRequestBody DeleteSshKeyConflictRequestBody
> = (request, response) => { > = (request, response) => {
const { body } = request; const { body } = request;
const hostUUIDs = Object.keys(body); const hostUUIDs = Object.keys(body);

@ -22,16 +22,7 @@ export const getSSHKeyConflict = buildGetRequestHandler(
ON sta.state_host_uuid = hos.host_uuid ON sta.state_host_uuid = hos.host_uuid
WHERE sta.state_name LIKE '${HOST_KEY_CHANGED_PREFIX}%';`; WHERE sta.state_name LIKE '${HOST_KEY_CHANGED_PREFIX}%';`;
const afterQueryReturn = buildQueryResultReducer<{ const afterQueryReturn = buildQueryResultReducer<{
[hostUUID: string]: { [hostUUID: string]: SshKeyConflict;
[stateUUID: string]: {
badFile: string;
badLine: number;
hostName: string;
hostUUID: string;
ipAddress: string;
stateUUID: string;
};
};
}>((previous, [hostName, hostUUID, stateName, stateNote, stateUUID]) => { }>((previous, [hostName, hostUUID, stateName, stateNote, stateUUID]) => {
const hostUUIDKey = toLocal(hostUUID, localHostUUID); const hostUUIDKey = toLocal(hostUUID, localHostUUID);

@ -14,7 +14,7 @@ export const getUPS: RequestHandler = buildGetRequestHandler(
FROM upses FROM upses
ORDER BY ups_name ASC;`; ORDER BY ups_name ASC;`;
const afterQueryReturn: QueryResultModifierFunction | undefined = const afterQueryReturn: QueryResultModifierFunction | undefined =
buildQueryResultReducer<{ [upsUUID: string]: UPSOverview }>( buildQueryResultReducer<{ [upsUUID: string]: UpsOverview }>(
(previous, [upsUUID, upsName, upsAgent, upsIPAddress]) => { (previous, [upsUUID, upsName, upsAgent, upsIPAddress]) => {
previous[upsUUID] = { previous[upsUUID] = {
upsAgent, upsAgent,

@ -21,13 +21,13 @@ export const getUPSTemplate: RequestHandler = (request, response) => {
const upsData: AnvilDataUPSHash = Object.entries( const upsData: AnvilDataUPSHash = Object.entries(
rawUPSData, rawUPSData,
).reduce<UPSTemplate>((previous, [upsTypeId, value]) => { ).reduce<UpsTemplate>((previous, [upsTypeId, value]) => {
const { brand, description: rawDescription, ...rest } = value; const { brand, description: rawDescription, ...rest } = value;
const matched = rawDescription.match( const matched = rawDescription.match(
/^(.+)\s+[-]\s+[<][^>]+href=[\\"]+([^\s]+)[\\"]+.+[>]([^<]+)[<]/, /^(.+)\s+[-]\s+[<][^>]+href=[\\"]+([^\s]+)[\\"]+.+[>]([^<]+)[<]/,
); );
const result: UPSTemplate[string] = { const result: UpsTemplate[string] = {
...rest, ...rest,
brand, brand,
description: rawDescription, description: rawDescription,

@ -1,8 +0,0 @@
type AnvilOverview = {
anvilName: string;
anvilUUID: string;
hosts: Array<{
hostName: string;
hostUUID: string;
}>;
};

@ -31,3 +31,12 @@ type AnvilDetailForProvisionServer = {
fileName: string; fileName: string;
}>; }>;
}; };
type AnvilOverview = {
anvilName: string;
anvilUUID: string;
hosts: Array<{
hostName: string;
hostUUID: string;
}>;
};

@ -0,0 +1,89 @@
type CreateHostConnectionRequestBody = {
dbName?: string;
ipAddress: string;
isPing?: boolean;
/** Host password; same as database password */
password: string;
port?: number;
sshPort?: number;
/** Database user */
user?: string;
};
type DeleteHostConnectionRequestBody = {
[hostUUID: string]: string[];
};
type HostConnectionOverview = {
inbound: {
ipAddress: {
[ipAddress: string]: {
hostUUID: string;
ipAddress: string;
ipAddressUUID: string;
networkLinkNumber: number;
networkNumber: number;
networkType: string;
};
};
port: number;
user: string;
};
peer: {
[ipAddress: string]: {
hostUUID: string;
ipAddress: string;
isPing: boolean;
port: number;
user: string;
};
};
};
type HostOverview = {
hostName: string;
hostType: string;
hostUUID: string;
shortHostName: string;
};
type InitializeStrikerNetworkForm = {
interfaces: Array<NetworkInterfaceOverview | null | undefined>;
ipAddress: string;
name: string;
subnetMask: string;
type: string;
};
type InitializeStrikerForm = {
adminPassword: string;
domainName: string;
hostName: string;
hostNumber: number;
networkDNS: string;
networkGateway: string;
networks: InitializeStrikerNetworkForm[];
organizationName: string;
organizationPrefix: string;
};
type PrepareHostRequestBody = {
enterpriseUUID?: string;
hostIPAddress: string;
hostName: string;
hostPassword: string;
hostSSHPort?: number;
hostType: string;
hostUser?: string;
hostUUID?: string;
redhatPassword: string;
redhatUser: string;
};
type SetHostInstallTargetRequestBody = {
isEnableInstallTarget: boolean;
};
type UpdateHostParams = {
hostUUID: string;
};

@ -0,0 +1,12 @@
type SshKeyConflict = {
[stateUUID: string]: {
badFile: string;
badLine: number;
hostName: string;
hostUUID: string;
ipAddress: string;
stateUUID: string;
};
};
type DeleteSshKeyConflictRequestBody = { [hostUUID: string]: string[] };

@ -1,11 +1,11 @@
type UPSOverview = { type UpsOverview = {
upsAgent: string; upsAgent: string;
upsIPAddress: string; upsIPAddress: string;
upsName: string; upsName: string;
upsUUID: string; upsUUID: string;
}; };
type UPSTemplate = { type UpsTemplate = {
[upsName: string]: AnvilDataUPSHash[string] & { [upsName: string]: AnvilDataUPSHash[string] & {
links: { links: {
[linkId: string]: { [linkId: string]: {

@ -0,0 +1,7 @@
type DeleteUserParamsDictionary = {
userUuid: string;
};
type DeleteUserRequestBody = {
uuids?: string[];
};

@ -1,11 +0,0 @@
type CreateHostConnectionRequestBody = {
dbName?: string;
ipAddress: string;
isPing?: boolean;
// Host password; same as database password.
password: string;
port?: number;
sshPort?: number;
// database user.
user?: string;
};

@ -1,3 +0,0 @@
type DeleteHostConnectionRequestBody = {
[hostUUID: string]: string[];
};

@ -1 +0,0 @@
type DeleteSSHKeyConflictRequestBody = { [hostUUID: string]: string[] };

@ -1,25 +0,0 @@
type HostConnectionOverview = {
inbound: {
ipAddress: {
[ipAddress: string]: {
hostUUID: string;
ipAddress: string;
ipAddressUUID: string;
networkLinkNumber: number;
networkNumber: number;
networkType: string;
};
};
port: number;
user: string;
};
peer: {
[ipAddress: string]: {
hostUUID: string;
ipAddress: string;
isPing: boolean;
port: number;
user: string;
};
};
};

@ -1,6 +0,0 @@
type HostOverview = {
hostName: string;
hostType: string;
hostUUID: string;
shortHostName: string;
};

@ -1,19 +0,0 @@
type InitializeStrikerNetworkForm = {
interfaces: Array<NetworkInterfaceOverview | null | undefined>;
ipAddress: string;
name: string;
subnetMask: string;
type: string;
};
type InitializeStrikerForm = {
adminPassword: string;
domainName: string;
hostName: string;
hostNumber: number;
networkDNS: string;
networkGateway: string;
networks: InitializeStrikerNetworkForm[];
organizationName: string;
organizationPrefix: string;
};

@ -1,20 +0,0 @@
type SetHostInstallTargetRequestBody = {
isEnableInstallTarget: boolean;
};
type PrepareHostRequestBody = {
enterpriseUUID?: string;
hostIPAddress: string;
hostName: string;
hostPassword: string;
hostSSHPort?: number;
hostType: string;
hostUser?: string;
hostUUID?: string;
redhatPassword: string;
redhatUser: string;
};
type UpdateHostParams = {
hostUUID: string;
};
Loading…
Cancel
Save