fix(striker-ui): load SSH key conflicts

main
Tsu-ba-me 2 years ago
parent 57735063f7
commit ab3fe5c625
  1. 34
      striker-ui/components/StrikerConfig/ManageChangedSSHKeysForm.tsx
  2. 14
      striker-ui/types/APISSHKey.d.ts
  3. 3
      striker-ui/types/ManageChangedSSHKeysForm.d.ts

@ -1,17 +1,21 @@
import { FC, useMemo, useRef } from 'react';
import API_BASE_URL from '../../lib/consts/API_BASE_URL';
import Divider from '../Divider';
import FlexBox from '../FlexBox';
import Link from '../Link';
import List from '../List';
import MessageBox from '../MessageBox';
import { ExpandablePanel } from '../Panels';
import periodicFetch from '../../lib/fetchers/periodicFetch';
import { BodyText } from '../Text';
import useProtect from '../../hooks/useProtect';
import useProtectedState from '../../hooks/useProtectedState';
const ManageChangedSSHKeysForm: FC<ManageChangedSSHKeysFormProps> = ({
mitmExternalHref = 'https://en.wikipedia.org/wiki/Man-in-the-middle_attack',
refreshInterval = 60000,
}) => {
const { protect } = useProtect();
@ -27,8 +31,36 @@ const ManageChangedSSHKeysForm: FC<ManageChangedSSHKeysFormProps> = ({
[changedSSHKeys],
);
const { isLoading } = periodicFetch<APISSHKeyConflictOverviewList>(
`${API_BASE_URL}/ssh-key/conflict`,
{
refreshInterval,
onSuccess: (data) => {
setChangedSSHKeys((previous) =>
Object.values(data).reduce<ChangedSSHKeys>((nyu, stateList) => {
Object.values(stateList).forEach(
({ hostName, hostUUID, ipAddress, stateUUID }) => {
nyu[stateUUID] = {
...previous[stateUUID],
hostName,
hostUUID,
ipAddress,
};
},
);
return nyu;
}, {}),
);
},
},
);
return (
<ExpandablePanel header={<BodyText>Manage changed SSH keys</BodyText>}>
<ExpandablePanel
header={<BodyText>Manage changed SSH keys</BodyText>}
loading={isLoading}
>
<FlexBox spacing=".2em">
<BodyText>
The identity of the following targets have unexpectedly changed.

@ -0,0 +1,14 @@
type APISSHKeyConflictOverview = {
[stateUUID: string]: {
badFile: string;
badLine: number;
hostName: string;
hostUUID: string;
ipAddress: string;
stateUUID: string;
};
};
type APISSHKeyConflictOverviewList = {
[hostUUID: 'local' | string]: APISSHKeyConflictOverview;
};

@ -1,5 +1,5 @@
type ChangedSSHKeys = {
[hostUUID: string]: {
[stateUUID: string]: {
hostName: string;
hostUUID: string;
ipAddress: string;
@ -9,6 +9,7 @@ type ChangedSSHKeys = {
type ManageChangedSSHKeysFormOptionalProps = {
mitmExternalHref?: LinkProps['href'];
refreshInterval?: number;
};
type ManageChangedSSHKeysFormProps = ManageChangedSSHKeysFormOptionalProps;

Loading…
Cancel
Save