mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 17:16:01 +00:00
SYNC: Merge branch 'feature/firestore'
This commit is contained in:
committed by
Diflow
parent
b12587626d
commit
ca145967dc
@@ -25,3 +25,4 @@ DEVWEB=1
|
|||||||
# LOGIN_PASSWORD_test=test
|
# LOGIN_PASSWORD_test=test
|
||||||
# LOGIN_PERMISSIONS_test=~*, widgets/database
|
# LOGIN_PERMISSIONS_test=~*, widgets/database
|
||||||
# WORKSPACE_DIR=/home/jena/dbgate-data-2
|
# WORKSPACE_DIR=/home/jena/dbgate-data-2
|
||||||
|
DBGATE_LICENSE=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InNhbGVzQGRiZ2F0ZS5ldSIsIm5hbWUiOiJEYkdhdGUgdGVzdCIsImxpY2Vuc2VJZCI6Ijk2ODJhODhiLTkwOWYtNDhiMS1hZGJmLWMwMzYyMjg4NDQyMSIsImNyZWF0ZWQiOiIyMDI1LTA2LTEyVDE1OjQ0OjAwLjY0NloiLCJlbmQiOjE3ODEyNzkwNDEsImV4cCI6MTc4MTg4Mzg0MSwiaWF0IjoxNzQ5NzQzMDQwfQ.h-pYymeb8ivJMo695PLo-tKxqfr3ZBiyZA4GllnAZbLDwBtxKY54BKfI2j70AtckuohAhn4i6VZn7UG_MIQSZVE7z8pwZyP4Jj8NUt9fYpCOFUfJMl_3iP6WOQ0eb9cyHfNsbKkXbi9wEuXoblLDCi2ve76ODqByPwA7FfCuY97zrxe9Zzth09Z4M0KjfeX7L50tQzMBVqW2rQAH1yc48fsaRbX8IABUqpvIjmhQBAgKlNltZlQrUfd1Egyi8TBSqvXhgqDz-gnJW_oe5eb2-emWZln38p7QwQy4smvvtOVZuUozv0boLS3wfzp9JaDZ4SXjWpBx-la7vm8L6wQYBQ
|
||||||
|
|||||||
@@ -101,24 +101,26 @@ function decryptObjectPasswordField(obj, field, encryptor = null) {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fieldsToEncrypt = ['password', 'sshPassword', 'sshKeyfilePassword', 'connectionDefinition'];
|
||||||
|
|
||||||
function encryptConnection(connection, encryptor = null) {
|
function encryptConnection(connection, encryptor = null) {
|
||||||
if (connection.passwordMode != 'saveRaw') {
|
if (connection.passwordMode != 'saveRaw') {
|
||||||
connection = encryptObjectPasswordField(connection, 'password', encryptor);
|
for (const field of fieldsToEncrypt) {
|
||||||
connection = encryptObjectPasswordField(connection, 'sshPassword', encryptor);
|
connection = encryptObjectPasswordField(connection, field, encryptor);
|
||||||
connection = encryptObjectPasswordField(connection, 'sshKeyfilePassword', encryptor);
|
}
|
||||||
}
|
}
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
function maskConnection(connection) {
|
function maskConnection(connection) {
|
||||||
if (!connection) return connection;
|
if (!connection) return connection;
|
||||||
return _.omit(connection, ['password', 'sshPassword', 'sshKeyfilePassword']);
|
return _.omit(connection, fieldsToEncrypt);
|
||||||
}
|
}
|
||||||
|
|
||||||
function decryptConnection(connection, encryptor = null) {
|
function decryptConnection(connection) {
|
||||||
connection = decryptObjectPasswordField(connection, 'password', encryptor);
|
for (const field of fieldsToEncrypt) {
|
||||||
connection = decryptObjectPasswordField(connection, 'sshPassword', encryptor);
|
connection = decryptObjectPasswordField(connection, field);
|
||||||
connection = decryptObjectPasswordField(connection, 'sshKeyfilePassword', encryptor);
|
}
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,9 +190,9 @@ function recryptObjectPasswordFieldInPlace(obj, field, decryptEncryptor, encrypt
|
|||||||
}
|
}
|
||||||
|
|
||||||
function recryptConnection(connection, decryptEncryptor, encryptEncryptor) {
|
function recryptConnection(connection, decryptEncryptor, encryptEncryptor) {
|
||||||
connection = recryptObjectPasswordField(connection, 'password', decryptEncryptor, encryptEncryptor);
|
for (const field of fieldsToEncrypt) {
|
||||||
connection = recryptObjectPasswordField(connection, 'sshPassword', decryptEncryptor, encryptEncryptor);
|
connection = recryptObjectPasswordField(connection, field, decryptEncryptor, encryptEncryptor);
|
||||||
connection = recryptObjectPasswordField(connection, 'sshKeyfilePassword', decryptEncryptor, encryptEncryptor);
|
}
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
packages/types/engines.d.ts
vendored
2
packages/types/engines.d.ts
vendored
@@ -241,7 +241,7 @@ export interface EngineDriver<TClient = any> extends FilterBehaviourProvider {
|
|||||||
defaultSocketPath?: string;
|
defaultSocketPath?: string;
|
||||||
authTypeLabel?: string;
|
authTypeLabel?: string;
|
||||||
importExportArgs?: any[];
|
importExportArgs?: any[];
|
||||||
connect({ server, port, user, password, database, certificateJson }): Promise<DatabaseHandle<TClient>>;
|
connect({ server, port, user, password, database, connectionDefinition }): Promise<DatabaseHandle<TClient>>;
|
||||||
close(dbhan: DatabaseHandle<TClient>): Promise<any>;
|
close(dbhan: DatabaseHandle<TClient>): Promise<any>;
|
||||||
query(dbhan: DatabaseHandle<TClient>, sql: string, options?: QueryOptions): Promise<QueryResult>;
|
query(dbhan: DatabaseHandle<TClient>, sql: string, options?: QueryOptions): Promise<QueryResult>;
|
||||||
stream(dbhan: DatabaseHandle<TClient>, sql: string, options: StreamOptions);
|
stream(dbhan: DatabaseHandle<TClient>, sql: string, options: StreamOptions);
|
||||||
|
|||||||
58
packages/web/src/forms/FormFileInputField.svelte
Normal file
58
packages/web/src/forms/FormFileInputField.svelte
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import SimpleFilesInput, { ProcessedFile } from '../impexp/SimpleFilesInput.svelte';
|
||||||
|
import { parseFileAsString } from '../utility/parseFileAsString';
|
||||||
|
import { getFormContext } from './FormProviderCore.svelte';
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
export let label: string;
|
||||||
|
export let buttonLabel: string = 'Choose File';
|
||||||
|
export let name: string;
|
||||||
|
export let disabled: boolean = false;
|
||||||
|
export let accept: string = '.json,application/json';
|
||||||
|
export let templateProps = {};
|
||||||
|
|
||||||
|
const { template, setFieldValue, values } = getFormContext();
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let fileName: string | null = null;
|
||||||
|
$: hasValue = $values?.[name] != null;
|
||||||
|
$: displayLabel = getDisplayLabel(buttonLabel, hasValue, fileName);
|
||||||
|
|
||||||
|
async function handleFileChange(fileData: ProcessedFile): Promise<void> {
|
||||||
|
const parseResult = await parseFileAsString(fileData.file);
|
||||||
|
|
||||||
|
if (parseResult.success) {
|
||||||
|
fileName = fileData.name;
|
||||||
|
setFieldValue(name, parseResult.data);
|
||||||
|
dispatch('change', {
|
||||||
|
success: true,
|
||||||
|
data: parseResult.data,
|
||||||
|
fileName: fileData.name,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fileName = null;
|
||||||
|
setFieldValue(name, null);
|
||||||
|
dispatch('change', {
|
||||||
|
success: false,
|
||||||
|
error: parseResult.error,
|
||||||
|
fileName: fileData.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDisplayLabel(baseLabel: string, hasValue: boolean, fileName: string | null): string {
|
||||||
|
if (!hasValue) {
|
||||||
|
return baseLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileName) {
|
||||||
|
return `${baseLabel} (${fileName})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${baseLabel} (JSON loaded)`;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:component this={template} type="file" {label} {disabled} {...templateProps}>
|
||||||
|
<SimpleFilesInput label={displayLabel} {accept} {disabled} onChange={handleFileChange} {...$$restProps} />
|
||||||
|
</svelte:component>
|
||||||
@@ -18,9 +18,7 @@
|
|||||||
import FormDropDownTextField from '../forms/FormDropDownTextField.svelte';
|
import FormDropDownTextField from '../forms/FormDropDownTextField.svelte';
|
||||||
import { getConnectionLabel } from 'dbgate-tools';
|
import { getConnectionLabel } from 'dbgate-tools';
|
||||||
import { _t } from '../translations';
|
import { _t } from '../translations';
|
||||||
import FilesInput from '../impexp/FilesInput.svelte';
|
import FormFileInputField from '../forms/FormFileInputField.svelte';
|
||||||
import SimpleFilesInput from '../impexp/SimpleFilesInput.svelte';
|
|
||||||
import FormJsonFileInputField from '../forms/FormJsonFileInputField.svelte';
|
|
||||||
|
|
||||||
export let getDatabaseList;
|
export let getDatabaseList;
|
||||||
export let currentConnection;
|
export let currentConnection;
|
||||||
@@ -465,8 +463,8 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if driver?.showConnectionField('certificateJson', $values, showConnectionFieldArgs)}
|
{#if driver?.showConnectionField('connectionDefinition', $values, showConnectionFieldArgs)}
|
||||||
<FormJsonFileInputField disabled={isConnected} label="Service account key JSON" name="certificateJson" />
|
<FormFileInputField disabled={isConnected} label="Service account key JSON" name="connectionDefinition" />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if driver}
|
{#if driver}
|
||||||
|
|||||||
@@ -1,26 +1,3 @@
|
|||||||
/**
|
|
||||||
* @template [T = any]
|
|
||||||
* @typedef {Object} FileParseResultSuccess
|
|
||||||
* @property {true} success
|
|
||||||
* @property {T} data
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} FileParseResultError
|
|
||||||
* @property {false} success
|
|
||||||
* @property {string} error
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @template [T = any]
|
|
||||||
* @typedef {FileParseResultSuccess<T> | FileParseResultError} FileParseResult
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @template [T = any]
|
|
||||||
* @param {File} file
|
|
||||||
* @returns {Promise<FileParseResult<T>>}
|
|
||||||
*/
|
|
||||||
export async function parseFileAsJson(file) {
|
export async function parseFileAsJson(file) {
|
||||||
try {
|
try {
|
||||||
const text = await file.text();
|
const text = await file.text();
|
||||||
|
|||||||
15
packages/web/src/utility/parseFileAsString.js
Normal file
15
packages/web/src/utility/parseFileAsString.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export async function parseFileAsString(file) {
|
||||||
|
try {
|
||||||
|
const text = await file.text();
|
||||||
|
const data = text;
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : 'Unknown parsing error',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user