mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 14:23:58 +00:00
auth types in driver
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const { extractPackageName } = require('dbgate-tools');
|
||||||
const { pluginsdir, datadir } = require('../utility/directories');
|
const { pluginsdir, datadir } = require('../utility/directories');
|
||||||
const socket = require('../utility/socket');
|
const socket = require('../utility/socket');
|
||||||
const requirePlugin = require('../shell/requirePlugin');
|
const requirePlugin = require('../shell/requirePlugin');
|
||||||
@@ -50,7 +51,7 @@ module.exports = {
|
|||||||
`http://registry.npmjs.com/-/v1/search?text=${encodeURIComponent(filter)}+keywords:dbgateplugin&size=25&from=0`
|
`http://registry.npmjs.com/-/v1/search?text=${encodeURIComponent(filter)}+keywords:dbgateplugin&size=25&from=0`
|
||||||
);
|
);
|
||||||
const { objects } = resp.data || {};
|
const { objects } = resp.data || {};
|
||||||
return (objects || []).map((x) => x.package);
|
return (objects || []).map(x => x.package);
|
||||||
},
|
},
|
||||||
|
|
||||||
info_meta: 'get',
|
info_meta: 'get',
|
||||||
@@ -88,9 +89,7 @@ module.exports = {
|
|||||||
const files = await fs.readdir(pluginsdir());
|
const files = await fs.readdir(pluginsdir());
|
||||||
const res = [];
|
const res = [];
|
||||||
for (const packageName of files) {
|
for (const packageName of files) {
|
||||||
const manifest = await fs
|
const manifest = await fs.readFile(path.join(pluginsdir(), packageName, 'package.json')).then(x => JSON.parse(x));
|
||||||
.readFile(path.join(pluginsdir(), packageName, 'package.json'))
|
|
||||||
.then((x) => JSON.parse(x));
|
|
||||||
const readmeFile = path.join(pluginsdir(), packageName, 'README.md');
|
const readmeFile = path.join(pluginsdir(), packageName, 'README.md');
|
||||||
if (await fs.exists(readmeFile)) {
|
if (await fs.exists(readmeFile)) {
|
||||||
manifest.readme = await fs.readFile(readmeFile, { encoding: 'utf-8' });
|
manifest.readme = await fs.readFile(readmeFile, { encoding: 'utf-8' });
|
||||||
@@ -131,6 +130,14 @@ module.exports = {
|
|||||||
return content.commands[command](args);
|
return content.commands[command](args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
authTypes_meta: 'post',
|
||||||
|
async authTypes({ engine }) {
|
||||||
|
const packageName = extractPackageName(engine);
|
||||||
|
const content = requirePlugin(packageName);
|
||||||
|
if (!content.driver || content.driver.engine != engine) return null;
|
||||||
|
return content.driver.getAuthTypes() || null;
|
||||||
|
},
|
||||||
|
|
||||||
async _init() {
|
async _init() {
|
||||||
const installed = await this.installed();
|
const installed = await this.installed();
|
||||||
try {
|
try {
|
||||||
@@ -142,7 +149,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
for (const packageName of preinstallPlugins) {
|
for (const packageName of preinstallPlugins) {
|
||||||
if (this.removedPlugins.includes(packageName)) continue;
|
if (this.removedPlugins.includes(packageName)) continue;
|
||||||
if (installed.find((x) => x.name == packageName)) continue;
|
if (installed.find(x => x.name == packageName)) continue;
|
||||||
try {
|
try {
|
||||||
console.log('Preinstalling plugin', packageName);
|
console.log('Preinstalling plugin', packageName);
|
||||||
await this.install({ packageName });
|
await this.install({ packageName });
|
||||||
|
|||||||
7
packages/types/engines.d.ts
vendored
7
packages/types/engines.d.ts
vendored
@@ -18,6 +18,12 @@ export interface WriteTableOptions {
|
|||||||
createIfNotExists?: boolean;
|
createIfNotExists?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface EngineAuthType {
|
||||||
|
title: string;
|
||||||
|
name: string;
|
||||||
|
disabledFields: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface EngineDriver {
|
export interface EngineDriver {
|
||||||
engine: string;
|
engine: string;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -44,6 +50,7 @@ export interface EngineDriver {
|
|||||||
analyseIncremental(pool: any, structure: DatabaseInfo): Promise<DatabaseInfo>;
|
analyseIncremental(pool: any, structure: DatabaseInfo): Promise<DatabaseInfo>;
|
||||||
dialect: SqlDialect;
|
dialect: SqlDialect;
|
||||||
createDumper(): SqlDumper;
|
createDumper(): SqlDumper;
|
||||||
|
getAuthTypes(): EngineAuthType[];
|
||||||
|
|
||||||
analyserClass?: any;
|
analyserClass?: any;
|
||||||
dumperClass?: any;
|
dumperClass?: any;
|
||||||
|
|||||||
@@ -8,9 +8,52 @@ import ModalContent from './ModalContent';
|
|||||||
import useExtensions from '../utility/useExtensions';
|
import useExtensions from '../utility/useExtensions';
|
||||||
import LoadingInfo from '../widgets/LoadingInfo';
|
import LoadingInfo from '../widgets/LoadingInfo';
|
||||||
import { FontIcon } from '../icons';
|
import { FontIcon } from '../icons';
|
||||||
import { FormProvider } from '../utility/FormProvider';
|
import { FormProvider, useForm } from '../utility/FormProvider';
|
||||||
// import FormikForm from '../utility/FormikForm';
|
// import FormikForm from '../utility/FormikForm';
|
||||||
|
|
||||||
|
function DriverFields({ extensions }) {
|
||||||
|
const { values, setFieldValue } = useForm();
|
||||||
|
const { authType, engine } = values;
|
||||||
|
const driver = extensions.drivers.find(x => x.engine == engine);
|
||||||
|
// const { authTypes } = driver || {};
|
||||||
|
const [authTypes, setAuthTypes] = React.useState(null);
|
||||||
|
const currentAuthType = authTypes && authTypes.find(x => x.name == authType);
|
||||||
|
|
||||||
|
const loadAuthTypes = async () => {
|
||||||
|
const resp = await axios.post('plugins/auth-types', { engine });
|
||||||
|
setAuthTypes(resp.data);
|
||||||
|
if (resp.data && !currentAuthType) {
|
||||||
|
setFieldValue('authType', resp.data[0].name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
setAuthTypes(null);
|
||||||
|
loadAuthTypes()
|
||||||
|
}, [values.engine]);
|
||||||
|
|
||||||
|
if (!driver) return null;
|
||||||
|
const disabledFields = (currentAuthType ? currentAuthType.disabledFields : null) || [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{!!authTypes && (
|
||||||
|
<FormSelectField label="Authentication" name="authType">
|
||||||
|
{authTypes.map(auth => (
|
||||||
|
<option value={auth.name} key={auth.name}>
|
||||||
|
{auth.title}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</FormSelectField>
|
||||||
|
)}
|
||||||
|
<FormTextField label="Server" name="server" disabled={disabledFields.includes('server')} />
|
||||||
|
<FormTextField label="Port" name="port" disabled={disabledFields.includes('port')} />
|
||||||
|
<FormTextField label="User" name="user" disabled={disabledFields.includes('user')} />
|
||||||
|
<FormPasswordField label="Password" name="password" disabled={disabledFields.includes('password')} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function ConnectionModal({ modalState, connection = undefined }) {
|
export default function ConnectionModal({ modalState, connection = undefined }) {
|
||||||
const [sqlConnectResult, setSqlConnectResult] = React.useState(null);
|
const [sqlConnectResult, setSqlConnectResult] = React.useState(null);
|
||||||
const extensions = useExtensions();
|
const extensions = useExtensions();
|
||||||
@@ -40,7 +83,7 @@ export default function ConnectionModal({ modalState, connection = undefined })
|
|||||||
return (
|
return (
|
||||||
<ModalBase modalState={modalState}>
|
<ModalBase modalState={modalState}>
|
||||||
<ModalHeader modalState={modalState}>{connection ? 'Edit connection' : 'Add connection'}</ModalHeader>
|
<ModalHeader modalState={modalState}>{connection ? 'Edit connection' : 'Add connection'}</ModalHeader>
|
||||||
<FormProvider initialValues={connection || { server: 'localhost', engine: 'mssql' }}>
|
<FormProvider initialValues={connection || { server: 'localhost', engine: 'mssql@dbgate-plugin-mssql' }}>
|
||||||
<ModalContent>
|
<ModalContent>
|
||||||
<FormSelectField label="Database engine" name="engine">
|
<FormSelectField label="Database engine" name="engine">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
@@ -53,16 +96,7 @@ export default function ConnectionModal({ modalState, connection = undefined })
|
|||||||
<option value="mysql">MySQL</option>
|
<option value="mysql">MySQL</option>
|
||||||
<option value="postgres">Postgre SQL</option> */}
|
<option value="postgres">Postgre SQL</option> */}
|
||||||
</FormSelectField>
|
</FormSelectField>
|
||||||
<FormSelectField label="Authentication" name="authType">
|
<DriverFields extensions={extensions} />
|
||||||
<option value=""></option>
|
|
||||||
<option value="sspi">Windows Authentication</option>
|
|
||||||
<option value="sql">SQL Server Authentication</option>
|
|
||||||
<option value="tedious">Use "tedious" driver</option>
|
|
||||||
</FormSelectField>
|
|
||||||
<FormTextField label="Server" name="server" />
|
|
||||||
<FormTextField label="Port" name="port" />
|
|
||||||
<FormTextField label="User" name="user" />
|
|
||||||
<FormPasswordField label="Password" name="password" />
|
|
||||||
<FormTextField label="Display name" name="displayName" />
|
<FormTextField label="Display name" name="displayName" />
|
||||||
{!isTesting && sqlConnectResult && sqlConnectResult.msgtype == 'connected' && (
|
{!isTesting && sqlConnectResult && sqlConnectResult.msgtype == 'connected' && (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -39,7 +39,11 @@ export default function ThemeHelmet() {
|
|||||||
color: ${theme.input_font1};
|
color: ${theme.input_font1};
|
||||||
border: 1px solid ${theme.border};
|
border: 1px solid ${theme.border};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[disabled] {
|
||||||
|
background-color: ${theme.input_background2};
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
background-color: ${theme.input_background};
|
background-color: ${theme.input_background};
|
||||||
color: ${theme.input_font1};
|
color: ${theme.input_font1};
|
||||||
|
|||||||
Reference in New Issue
Block a user