fix(striker-ui): allow delete key conflicts in test access form

main^2
Tsu-ba-me 7 months ago
parent 7b1ea9c56c
commit 92fbbdb1cb
  1. 2
      striker-ui/components/ManageHost/ManageHost.tsx
  2. 75
      striker-ui/components/ManageHost/TestAccessForm.tsx
  3. 1
      striker-ui/types/APICommand.d.ts
  4. 1
      striker-ui/types/ManageHost.d.ts

@ -46,7 +46,7 @@ const ManageHost: FC = () => {
}}
renderAddForm={(tools) => (
<>
<TestAccessForm setResponse={setInquireHostResponse} />
<TestAccessForm setResponse={setInquireHostResponse} tools={tools} />
{inquireHostResponse && (
<PrepareHostForm host={inquireHostResponse} tools={tools} />
)}

@ -10,17 +10,19 @@ import UncontrolledInput from '../UncontrolledInput';
import useFormikUtils from '../../hooks/useFormikUtils';
import Spinner from '../Spinner';
import schema from './testAccessSchema';
import { BodyText } from '../Text';
const TestAccessForm: FC<TestAccessFormProps> = (props) => {
const { setResponse } = props;
const { setResponse, tools } = props;
const messageGroupRef = useRef<MessageGroupForwardedRefContent>(null);
const [loadingInquiry, setLoadingInquiry] = useState<boolean>(false);
const [moreActions, setMoreActions] = useState<ContainedButtonProps[]>([]);
const setApiMessage = useCallback(
(message?: Message) =>
messageGroupRef?.current?.setMessage?.call(null, 'api', message),
messageGroupRef.current?.setMessage?.call(null, 'api', message),
[],
);
@ -33,6 +35,7 @@ const TestAccessForm: FC<TestAccessFormProps> = (props) => {
onSubmit: (values, { setSubmitting }) => {
setApiMessage();
setLoadingInquiry(true);
setMoreActions([]);
setResponse(undefined);
const { ip, password } = values;
@ -43,7 +46,72 @@ const TestAccessForm: FC<TestAccessFormProps> = (props) => {
password,
})
.then(({ data }) => {
const { isConnected } = data;
const { badSshKeys, isConnected } = data;
if (badSshKeys) {
setApiMessage({
children: (
<>
Host identification at {ip} changed. If this is valid,
please delete the conflicting SSH host key.
</>
),
type: 'warning',
});
setMoreActions([
{
background: 'red',
children: 'Delete keys',
onClick: () => {
tools.confirm.prepare({
actionProceedText: 'Delete',
content: (
<BodyText>
There&apos;s a different host key on {ip}, which could
mean a MITM attack. But if this change is expected,
you can delete the known host key(s) to resolve the
conflict.
</BodyText>
),
onProceedAppend: () => {
tools.confirm.loading(true);
api
.delete('/ssh-key/conflict', {
data: badSshKeys,
})
.then(() => {
tools.confirm.finish('Success', {
children: (
<>Started job to delete host key(s) for {ip}.</>
),
});
setMoreActions([]);
})
.catch((error) => {
const emsg = handleAPIError(error);
emsg.children = (
<>Failed to delete host key(s). {emsg.children}</>
);
tools.confirm.finish('Error', emsg);
});
},
proceedColour: 'red',
titleText: `Delete all known SSH host key(s) for ${ip}?`,
});
tools.confirm.open(true);
},
type: 'button',
},
]);
return;
}
if (!isConnected) {
setApiMessage({
@ -141,6 +209,7 @@ const TestAccessForm: FC<TestAccessFormProps> = (props) => {
) : (
<ActionGroup
actions={[
...moreActions,
{
background: 'blue',
children: 'Test access',

@ -1,4 +1,5 @@
type APICommandInquireHostResponseBody = {
badSshKeys?: Record<string, string[]>;
hostName: string;
hostOS: string;
hostUUID: string;

@ -14,6 +14,7 @@ type TestAccessFormProps = {
setResponse: React.Dispatch<
React.SetStateAction<InquireHostResponse | undefined>
>;
tools: CrudListFormTools;
};
/** PrepareHostForm */

Loading…
Cancel
Save