mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
fix(plugin-connections): CB-1359 make private key always required
This commit is contained in:
-1
@@ -172,7 +172,6 @@ export class ConnectionController
|
||||
authType: handler.authType,
|
||||
userName: handler.userName,
|
||||
password: handler.password,
|
||||
key: handler.key,
|
||||
savePassword: handler.savePassword,
|
||||
});
|
||||
}
|
||||
|
||||
+1
-44
@@ -9,12 +9,11 @@
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import styled from 'reshadow';
|
||||
|
||||
import { BASE_CONTAINERS_STYLES, Button, FieldCheckbox, GroupItem, GroupTitle, InputField, Textarea, UploadArea, useMapResource } from '@cloudbeaver/core-blocks';
|
||||
import { BASE_CONTAINERS_STYLES, FieldCheckbox, GroupTitle, InputField, useMapResource } from '@cloudbeaver/core-blocks';
|
||||
import { NetworkHandlerResource } from '@cloudbeaver/core-connections';
|
||||
import { useTranslate } from '@cloudbeaver/core-localization';
|
||||
import { NetworkHandlerAuthType, NetworkHandlerConfigInput } from '@cloudbeaver/core-sdk';
|
||||
import { useStyles } from '@cloudbeaver/core-theming';
|
||||
import { getTextFileReadingProcess } from '@cloudbeaver/core-utils';
|
||||
|
||||
interface Props {
|
||||
id: string;
|
||||
@@ -38,22 +37,6 @@ export const NetworkHandlerAuthForm = observer<Props>(function NetworkHandlerAut
|
||||
}
|
||||
|
||||
const state = networkHandlersConfig.find(state => state.id === id)!;
|
||||
|
||||
const handleKeyUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = event.target.files?.[0];
|
||||
|
||||
if (!file) {
|
||||
throw new Error('File is not found');
|
||||
}
|
||||
|
||||
const process = getTextFileReadingProcess(file);
|
||||
const key = await process.promise;
|
||||
|
||||
if (key) {
|
||||
state.key = key;
|
||||
}
|
||||
};
|
||||
|
||||
const keyAuth = state.authType === NetworkHandlerAuthType.PublicKey;
|
||||
const passwordLabel = keyAuth ? 'Passphrase' : translate(`connections_network_handler_${id}_password`, 'connections_network_handler_default_password');
|
||||
|
||||
@@ -78,32 +61,6 @@ export const NetworkHandlerAuthForm = observer<Props>(function NetworkHandlerAut
|
||||
>
|
||||
{passwordLabel}
|
||||
</InputField>
|
||||
{keyAuth && (
|
||||
<>
|
||||
<Textarea
|
||||
name='key'
|
||||
state={state}
|
||||
disabled={disabled}
|
||||
>
|
||||
{translate('connections_network_handler_ssh_tunnel_private_key')}
|
||||
</Textarea>
|
||||
<GroupItem>
|
||||
<UploadArea
|
||||
accept='.txt, .ssh'
|
||||
reset
|
||||
disabled={disabled}
|
||||
onChange={handleKeyUpload}
|
||||
>
|
||||
<Button
|
||||
tag='div'
|
||||
mod={['outlined']}
|
||||
>
|
||||
{translate('ui_file')}
|
||||
</Button>
|
||||
</UploadArea>
|
||||
</GroupItem>
|
||||
</>
|
||||
)}
|
||||
{allowSaveCredentials && (
|
||||
<FieldCheckbox
|
||||
id={id + ' savePassword'}
|
||||
|
||||
+5
-4
@@ -119,6 +119,10 @@ export class ConnectionSSHTabService extends Bootstrap {
|
||||
|
||||
for (const handler of config.networkHandlersConfig) {
|
||||
if (handler.enabled && this.isChanged(handler, info)) {
|
||||
if (handler.authType === NetworkHandlerAuthType.PublicKey && !handler.key?.length) {
|
||||
validation.error("Field SSH 'Private key' can't be empty");
|
||||
}
|
||||
|
||||
if (handler.savePassword) {
|
||||
if (!handler.userName?.length) {
|
||||
validation.error("Field SSH 'User' can't be empty");
|
||||
@@ -126,9 +130,6 @@ export class ConnectionSSHTabService extends Bootstrap {
|
||||
if (handler.authType === NetworkHandlerAuthType.Password && !handler.password?.length) {
|
||||
validation.error("Field SSH 'Password' can't be empty");
|
||||
}
|
||||
if (handler.authType === NetworkHandlerAuthType.PublicKey && !handler.key?.length) {
|
||||
validation.error("Field SSH 'Private key' can't be empty");
|
||||
}
|
||||
}
|
||||
|
||||
if (!handler.properties?.host?.length) {
|
||||
@@ -160,7 +161,7 @@ export class ConnectionSSHTabService extends Bootstrap {
|
||||
|
||||
for (const handler of state.config.networkHandlersConfig) {
|
||||
if (this.isChanged(handler, state.info)) {
|
||||
configs.push({ ...handler });
|
||||
configs.push({ ...handler, key: handler.authType === NetworkHandlerAuthType.PublicKey ? handler.key : undefined });
|
||||
}
|
||||
if (handler.enabled && !handler.savePassword) {
|
||||
credentialsState.requireNetworkHandler(handler.id);
|
||||
|
||||
@@ -125,7 +125,6 @@ export class DBAuthDialogController implements IInitializableController, IDestru
|
||||
authType: handler.authType,
|
||||
userName: handler.userName,
|
||||
password: handler.password,
|
||||
key: handler.key,
|
||||
savePassword: handler.savePassword,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user