mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 11:25:59 +00:00
cloud connection save
This commit is contained in:
@@ -7,6 +7,7 @@ const {
|
|||||||
getCloudFolderEncryptor,
|
getCloudFolderEncryptor,
|
||||||
getCloudContent,
|
getCloudContent,
|
||||||
putCloudContent,
|
putCloudContent,
|
||||||
|
removeCloudCachedConnection,
|
||||||
} = require('../utility/cloudIntf');
|
} = require('../utility/cloudIntf');
|
||||||
const connections = require('./connections');
|
const connections = require('./connections');
|
||||||
const socket = require('../utility/socket');
|
const socket = require('../utility/socket');
|
||||||
@@ -128,17 +129,32 @@ module.exports = {
|
|||||||
|
|
||||||
saveConnection_meta: true,
|
saveConnection_meta: true,
|
||||||
async saveConnection({ folid, connection }) {
|
async saveConnection({ folid, connection }) {
|
||||||
|
let cntid = undefined;
|
||||||
|
if (connection._id) {
|
||||||
|
const m = connection._id.match(/^cloud\:\/\/(.+)\/(.+)$/);
|
||||||
|
if (!m) {
|
||||||
|
throw new Error('Invalid cloud connection ID format');
|
||||||
|
}
|
||||||
|
folid = m[1];
|
||||||
|
cntid = m[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!folid) {
|
||||||
|
throw new Error('Missing cloud folder ID');
|
||||||
|
}
|
||||||
|
|
||||||
const folderEncryptor = await getCloudFolderEncryptor(folid);
|
const folderEncryptor = await getCloudFolderEncryptor(folid);
|
||||||
const recryptedConn = encryptConnection(connection, folderEncryptor);
|
const recryptedConn = encryptConnection(connection, folderEncryptor);
|
||||||
const resp = await putCloudContent(
|
const resp = await putCloudContent(
|
||||||
folid,
|
folid,
|
||||||
undefined,
|
cntid,
|
||||||
JSON.stringify(recryptedConn),
|
JSON.stringify(recryptedConn),
|
||||||
getConnectionLabel(recryptedConn),
|
getConnectionLabel(recryptedConn),
|
||||||
'connection'
|
'connection'
|
||||||
);
|
);
|
||||||
|
|
||||||
const { cntid } = resp;
|
removeCloudCachedConnection(folid, resp.cntid);
|
||||||
|
cntid = resp.cntid;
|
||||||
socket.emitChanged('cloud-content-changed');
|
socket.emitChanged('cloud-content-changed');
|
||||||
return {
|
return {
|
||||||
...recryptedConn,
|
...recryptedConn,
|
||||||
|
|||||||
@@ -28,14 +28,7 @@ function start() {
|
|||||||
let version = {
|
let version = {
|
||||||
version: 'Unknown',
|
version: 'Unknown',
|
||||||
};
|
};
|
||||||
try {
|
version = await driver.getVersion(dbhan);
|
||||||
version = await driver.getVersion(dbhan);
|
|
||||||
} catch (err) {
|
|
||||||
logger.error(extractErrorLogData(err), 'Error getting DB server version');
|
|
||||||
version = {
|
|
||||||
version: 'Unknown',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
let databases = undefined;
|
let databases = undefined;
|
||||||
if (requestDbList) {
|
if (requestDbList) {
|
||||||
databases = await driver.listDatabases(dbhan);
|
databases = await driver.listDatabases(dbhan);
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ async function callCloudApiPost(endpoint, body, signinHolder = null) {
|
|||||||
async function getCloudFolderEncryptor(folid) {
|
async function getCloudFolderEncryptor(folid) {
|
||||||
const { encryptionKey } = await callCloudApiGet(`folder-key/${folid}`);
|
const { encryptionKey } = await callCloudApiGet(`folder-key/${folid}`);
|
||||||
if (!encryptionKey) {
|
if (!encryptionKey) {
|
||||||
throw new Error('No encryption key');
|
throw new Error('No encryption key for folder: ' + folid);
|
||||||
}
|
}
|
||||||
return simpleEncryptor.createEncryptor(encryptionKey);
|
return simpleEncryptor.createEncryptor(encryptionKey);
|
||||||
}
|
}
|
||||||
@@ -336,6 +336,11 @@ async function loadCachedCloudConnection(folid, cntid) {
|
|||||||
return cloudConnectionCache[cacheKey];
|
return cloudConnectionCache[cacheKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeCloudCachedConnection(folid, cntid) {
|
||||||
|
const cacheKey = `${folid}|${cntid}`;
|
||||||
|
delete cloudConnectionCache[cacheKey];
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createDbGateIdentitySession,
|
createDbGateIdentitySession,
|
||||||
startCloudTokenChecking,
|
startCloudTokenChecking,
|
||||||
@@ -349,4 +354,5 @@ module.exports = {
|
|||||||
getCloudContent,
|
getCloudContent,
|
||||||
loadCachedCloudConnection,
|
loadCachedCloudConnection,
|
||||||
putCloudContent,
|
putCloudContent,
|
||||||
|
removeCloudCachedConnection,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -159,7 +159,7 @@
|
|||||||
$: currentConnection = getCurrentConnectionCore($values, driver);
|
$: currentConnection = getCurrentConnectionCore($values, driver);
|
||||||
|
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
if (saveOnCloud) {
|
if (saveOnCloud && !getCurrentConnection()?._id) {
|
||||||
showModal(ChooseCloudFolderModal, {
|
showModal(ChooseCloudFolderModal, {
|
||||||
requiredRoleVariants: ['write', 'admin'],
|
requiredRoleVariants: ['write', 'admin'],
|
||||||
message: 'Choose cloud folder to saved connection',
|
message: 'Choose cloud folder to saved connection',
|
||||||
@@ -184,6 +184,17 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} else if (
|
||||||
|
// @ts-ignore
|
||||||
|
getCurrentConnection()?._id?.startsWith('cloud://')
|
||||||
|
) {
|
||||||
|
let connection = getCurrentConnection();
|
||||||
|
await apiCall('cloud/save-connection', { connection });
|
||||||
|
showSnackbarSuccess('Connection saved');
|
||||||
|
changeTab(tabid, tab => ({
|
||||||
|
...tab,
|
||||||
|
title: getConnectionLabel(connection),
|
||||||
|
}));
|
||||||
} else {
|
} else {
|
||||||
let connection = getCurrentConnection();
|
let connection = getCurrentConnection();
|
||||||
connection = {
|
connection = {
|
||||||
@@ -210,19 +221,32 @@
|
|||||||
|
|
||||||
async function handleConnect() {
|
async function handleConnect() {
|
||||||
let connection = getCurrentConnection();
|
let connection = getCurrentConnection();
|
||||||
if (!connection._id) {
|
|
||||||
connection = {
|
if (
|
||||||
...connection,
|
// @ts-ignore
|
||||||
unsaved: true,
|
connection?._id?.startsWith('cloud://')
|
||||||
|
) {
|
||||||
|
const saved = await apiCall('cloud/save-connection', { connection });
|
||||||
|
changeTab(tabid, tab => ({
|
||||||
|
...tab,
|
||||||
|
title: getConnectionLabel(connection),
|
||||||
|
}));
|
||||||
|
openConnection(saved);
|
||||||
|
} else {
|
||||||
|
if (!connection._id) {
|
||||||
|
connection = {
|
||||||
|
...connection,
|
||||||
|
unsaved: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const saved = await apiCall('connections/save', connection);
|
||||||
|
$values = {
|
||||||
|
...$values,
|
||||||
|
unsaved: connection.unsaved,
|
||||||
|
_id: saved._id,
|
||||||
};
|
};
|
||||||
|
openConnection(saved);
|
||||||
}
|
}
|
||||||
const saved = await apiCall('connections/save', connection);
|
|
||||||
$values = {
|
|
||||||
...$values,
|
|
||||||
unsaved: connection.unsaved,
|
|
||||||
_id: saved._id,
|
|
||||||
};
|
|
||||||
openConnection(saved);
|
|
||||||
// closeMultipleTabs(x => x.tabid == tabid, true);
|
// closeMultipleTabs(x => x.tabid == tabid, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
currentDatabase,
|
currentDatabase,
|
||||||
expandedConnections,
|
expandedConnections,
|
||||||
openedConnections,
|
openedConnections,
|
||||||
|
openedSingleDatabaseConnections,
|
||||||
} from '../stores';
|
} from '../stores';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { plusExpandIcon } from '../icons/expandIcons';
|
import { plusExpandIcon } from '../icons/expandIcons';
|
||||||
@@ -74,12 +75,26 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
function ensureCloudConnectionsLoaded(...conids) {
|
||||||
const currentConid = $currentDatabase?.connection?._id;
|
_.uniq(conids).forEach(conid => {
|
||||||
if (currentConid?.startsWith('cloud://') && !$cloudConnectionsStore[currentConid]) {
|
if (conid?.startsWith('cloud://') && !$cloudConnectionsStore[conid]) {
|
||||||
loadCloudConnection(currentConid);
|
loadCloudConnection(conid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$: ensureCloudConnectionsLoaded(
|
||||||
|
$currentDatabase?.connection?._id,
|
||||||
|
...$openedSingleDatabaseConnections,
|
||||||
|
...$openedConnections
|
||||||
|
);
|
||||||
|
|
||||||
|
// onMount(() => {
|
||||||
|
// const currentConid = $currentDatabase?.connection?._id;
|
||||||
|
// if (currentConid?.startsWith('cloud://') && !$cloudConnectionsStore[currentConid]) {
|
||||||
|
// loadCloudConnection(currentConid);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
function createAddMenu() {
|
function createAddMenu() {
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user