dbgate-api-premium 7.0.6 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -6
- package/src/controllers/connections.js +2 -2
- package/src/controllers/databaseConnections.js +5 -0
- package/src/controllers/restConnections.js +316 -0
- package/src/controllers/runners.js +10 -10
- package/src/controllers/storage.js +4 -4
- package/src/currentVersion.js +2 -2
- package/src/main.js +2 -0
- package/src/proc/connectProcess.js +4 -1
- package/src/proc/index.js +2 -0
- package/src/proc/restConnectionProcess.js +771 -0
- package/src/shell/requirePlugin.js +9 -3
- package/src/storageModel.js +78 -78
- package/src/utility/connectUtility.js +29 -1
- package/src/utility/crypting.js +21 -1
- package/src/utility/envtools.js +13 -2
|
@@ -4,7 +4,8 @@ const { pluginsdir, packagedPluginsDir, getPluginBackendPath } = require('../uti
|
|
|
4
4
|
const platformInfo = require('../utility/platformInfo');
|
|
5
5
|
const authProxy = require('../utility/authProxy');
|
|
6
6
|
const { getLogger } = require('dbgate-tools');
|
|
7
|
-
|
|
7
|
+
const { openApiDriver, graphQlDriver, oDataDriver } = require('dbgate-rest');
|
|
8
|
+
//
|
|
8
9
|
const logger = getLogger('requirePlugin');
|
|
9
10
|
|
|
10
11
|
const loadedPlugins = {};
|
|
@@ -13,16 +14,21 @@ const dbgateEnv = {
|
|
|
13
14
|
dbgateApi: null,
|
|
14
15
|
platformInfo,
|
|
15
16
|
authProxy,
|
|
16
|
-
isProApp: () =>{
|
|
17
|
+
isProApp: () => {
|
|
17
18
|
const { isProApp } = require('../utility/checkLicense');
|
|
18
19
|
return isProApp();
|
|
19
|
-
}
|
|
20
|
+
},
|
|
20
21
|
};
|
|
21
22
|
function requirePlugin(packageName, requiredPlugin = null) {
|
|
22
23
|
if (!packageName) throw new Error('Missing packageName in plugin');
|
|
23
24
|
if (loadedPlugins[packageName]) return loadedPlugins[packageName];
|
|
24
25
|
|
|
25
26
|
if (requiredPlugin == null) {
|
|
27
|
+
if (packageName.endsWith('@rest') || packageName === 'rest') {
|
|
28
|
+
return {
|
|
29
|
+
drivers: [openApiDriver, graphQlDriver, oDataDriver],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
26
32
|
let module;
|
|
27
33
|
const modulePath = getPluginBackendPath(packageName);
|
|
28
34
|
logger.info(`DBGM-00062 Loading module ${packageName} from ${modulePath}`);
|
package/src/storageModel.js
CHANGED
|
@@ -850,84 +850,6 @@ module.exports = {
|
|
|
850
850
|
}
|
|
851
851
|
]
|
|
852
852
|
},
|
|
853
|
-
{
|
|
854
|
-
"pureName": "password_reset_tokens",
|
|
855
|
-
"columns": [
|
|
856
|
-
{
|
|
857
|
-
"pureName": "password_reset_tokens",
|
|
858
|
-
"columnName": "id",
|
|
859
|
-
"dataType": "int",
|
|
860
|
-
"autoIncrement": true,
|
|
861
|
-
"notNull": true
|
|
862
|
-
},
|
|
863
|
-
{
|
|
864
|
-
"pureName": "password_reset_tokens",
|
|
865
|
-
"columnName": "user_id",
|
|
866
|
-
"dataType": "int",
|
|
867
|
-
"notNull": true
|
|
868
|
-
},
|
|
869
|
-
{
|
|
870
|
-
"pureName": "password_reset_tokens",
|
|
871
|
-
"columnName": "token",
|
|
872
|
-
"dataType": "varchar(500)",
|
|
873
|
-
"notNull": true
|
|
874
|
-
},
|
|
875
|
-
{
|
|
876
|
-
"pureName": "password_reset_tokens",
|
|
877
|
-
"columnName": "created_at",
|
|
878
|
-
"dataType": "datetime",
|
|
879
|
-
"notNull": true
|
|
880
|
-
},
|
|
881
|
-
{
|
|
882
|
-
"pureName": "password_reset_tokens",
|
|
883
|
-
"columnName": "expires_at",
|
|
884
|
-
"dataType": "datetime",
|
|
885
|
-
"notNull": true
|
|
886
|
-
},
|
|
887
|
-
{
|
|
888
|
-
"pureName": "password_reset_tokens",
|
|
889
|
-
"columnName": "used_at",
|
|
890
|
-
"dataType": "datetime",
|
|
891
|
-
"notNull": false
|
|
892
|
-
}
|
|
893
|
-
],
|
|
894
|
-
"foreignKeys": [
|
|
895
|
-
{
|
|
896
|
-
"constraintType": "foreignKey",
|
|
897
|
-
"constraintName": "FK_password_reset_tokens_user_id",
|
|
898
|
-
"pureName": "password_reset_tokens",
|
|
899
|
-
"refTableName": "users",
|
|
900
|
-
"columns": [
|
|
901
|
-
{
|
|
902
|
-
"columnName": "user_id",
|
|
903
|
-
"refColumnName": "id"
|
|
904
|
-
}
|
|
905
|
-
]
|
|
906
|
-
}
|
|
907
|
-
],
|
|
908
|
-
"indexes": [
|
|
909
|
-
{
|
|
910
|
-
"constraintName": "idx_token",
|
|
911
|
-
"pureName": "password_reset_tokens",
|
|
912
|
-
"constraintType": "index",
|
|
913
|
-
"columns": [
|
|
914
|
-
{
|
|
915
|
-
"columnName": "token"
|
|
916
|
-
}
|
|
917
|
-
]
|
|
918
|
-
}
|
|
919
|
-
],
|
|
920
|
-
"primaryKey": {
|
|
921
|
-
"pureName": "password_reset_tokens",
|
|
922
|
-
"constraintType": "primaryKey",
|
|
923
|
-
"constraintName": "PK_password_reset_tokens",
|
|
924
|
-
"columns": [
|
|
925
|
-
{
|
|
926
|
-
"columnName": "id"
|
|
927
|
-
}
|
|
928
|
-
]
|
|
929
|
-
}
|
|
930
|
-
},
|
|
931
853
|
{
|
|
932
854
|
"pureName": "roles",
|
|
933
855
|
"columns": [
|
|
@@ -2252,6 +2174,84 @@ module.exports = {
|
|
|
2252
2174
|
]
|
|
2253
2175
|
}
|
|
2254
2176
|
},
|
|
2177
|
+
{
|
|
2178
|
+
"pureName": "user_password_reset_tokens",
|
|
2179
|
+
"columns": [
|
|
2180
|
+
{
|
|
2181
|
+
"pureName": "user_password_reset_tokens",
|
|
2182
|
+
"columnName": "id",
|
|
2183
|
+
"dataType": "int",
|
|
2184
|
+
"autoIncrement": true,
|
|
2185
|
+
"notNull": true
|
|
2186
|
+
},
|
|
2187
|
+
{
|
|
2188
|
+
"pureName": "user_password_reset_tokens",
|
|
2189
|
+
"columnName": "user_id",
|
|
2190
|
+
"dataType": "int",
|
|
2191
|
+
"notNull": true
|
|
2192
|
+
},
|
|
2193
|
+
{
|
|
2194
|
+
"pureName": "user_password_reset_tokens",
|
|
2195
|
+
"columnName": "token",
|
|
2196
|
+
"dataType": "varchar(500)",
|
|
2197
|
+
"notNull": true
|
|
2198
|
+
},
|
|
2199
|
+
{
|
|
2200
|
+
"pureName": "user_password_reset_tokens",
|
|
2201
|
+
"columnName": "created_at",
|
|
2202
|
+
"dataType": "varchar(32)",
|
|
2203
|
+
"notNull": true
|
|
2204
|
+
},
|
|
2205
|
+
{
|
|
2206
|
+
"pureName": "user_password_reset_tokens",
|
|
2207
|
+
"columnName": "expires_at",
|
|
2208
|
+
"dataType": "varchar(32)",
|
|
2209
|
+
"notNull": true
|
|
2210
|
+
},
|
|
2211
|
+
{
|
|
2212
|
+
"pureName": "user_password_reset_tokens",
|
|
2213
|
+
"columnName": "used_at",
|
|
2214
|
+
"dataType": "varchar(32)",
|
|
2215
|
+
"notNull": false
|
|
2216
|
+
}
|
|
2217
|
+
],
|
|
2218
|
+
"foreignKeys": [
|
|
2219
|
+
{
|
|
2220
|
+
"constraintType": "foreignKey",
|
|
2221
|
+
"constraintName": "FK_user_password_reset_tokens_user_id",
|
|
2222
|
+
"pureName": "user_password_reset_tokens",
|
|
2223
|
+
"refTableName": "users",
|
|
2224
|
+
"columns": [
|
|
2225
|
+
{
|
|
2226
|
+
"columnName": "user_id",
|
|
2227
|
+
"refColumnName": "id"
|
|
2228
|
+
}
|
|
2229
|
+
]
|
|
2230
|
+
}
|
|
2231
|
+
],
|
|
2232
|
+
"indexes": [
|
|
2233
|
+
{
|
|
2234
|
+
"constraintName": "idx_token",
|
|
2235
|
+
"pureName": "user_password_reset_tokens",
|
|
2236
|
+
"constraintType": "index",
|
|
2237
|
+
"columns": [
|
|
2238
|
+
{
|
|
2239
|
+
"columnName": "token"
|
|
2240
|
+
}
|
|
2241
|
+
]
|
|
2242
|
+
}
|
|
2243
|
+
],
|
|
2244
|
+
"primaryKey": {
|
|
2245
|
+
"pureName": "user_password_reset_tokens",
|
|
2246
|
+
"constraintType": "primaryKey",
|
|
2247
|
+
"constraintName": "PK_user_password_reset_tokens",
|
|
2248
|
+
"columns": [
|
|
2249
|
+
{
|
|
2250
|
+
"columnName": "id"
|
|
2251
|
+
}
|
|
2252
|
+
]
|
|
2253
|
+
}
|
|
2254
|
+
},
|
|
2255
2255
|
{
|
|
2256
2256
|
"pureName": "user_permissions",
|
|
2257
2257
|
"columns": [
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
const fs = require('fs-extra');
|
|
2
|
-
const { decryptConnection } = require('./crypting');
|
|
2
|
+
const { decryptConnection, decryptPasswordString } = require('./crypting');
|
|
3
3
|
const { getSshTunnelProxy } = require('./sshTunnelProxy');
|
|
4
4
|
const platformInfo = require('../utility/platformInfo');
|
|
5
5
|
const connections = require('../controllers/connections');
|
|
6
6
|
const _ = require('lodash');
|
|
7
|
+
const axios = require('axios');
|
|
7
8
|
|
|
8
9
|
async function loadConnection(driver, storedConnection, connectionMode) {
|
|
9
10
|
const { allowShellConnection, allowConnectionFromEnvVariables } = platformInfo;
|
|
@@ -131,12 +132,39 @@ async function connectUtility(driver, storedConnection, connectionMode, addition
|
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
connection.ssl = await extractConnectionSslParams(connection);
|
|
135
|
+
connection.axios = axios.default;
|
|
134
136
|
|
|
135
137
|
const conn = await driver.connect({ conid: connectionLoaded?._id, ...connection, ...additionalOptions });
|
|
136
138
|
return conn;
|
|
137
139
|
}
|
|
138
140
|
|
|
141
|
+
function getRestAuthFromConnection(connection) {
|
|
142
|
+
if (!connection) return null;
|
|
143
|
+
if (connection.authType == 'basic') {
|
|
144
|
+
return {
|
|
145
|
+
type: 'basic',
|
|
146
|
+
user: connection.user,
|
|
147
|
+
password: decryptPasswordString(connection.password),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (connection.authType == 'bearer') {
|
|
151
|
+
return {
|
|
152
|
+
type: 'bearer',
|
|
153
|
+
token: connection.authToken,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (connection.authType == 'apikey') {
|
|
157
|
+
return {
|
|
158
|
+
type: 'apikey',
|
|
159
|
+
header: connection.apiKeyHeader,
|
|
160
|
+
value: connection.apiKeyValue,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
139
166
|
module.exports = {
|
|
140
167
|
extractConnectionSslParams,
|
|
141
168
|
connectUtility,
|
|
169
|
+
getRestAuthFromConnection,
|
|
142
170
|
};
|
package/src/utility/crypting.js
CHANGED
|
@@ -102,6 +102,26 @@ function decryptObjectPasswordField(obj, field, encryptor = null) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
const fieldsToEncrypt = ['password', 'sshPassword', 'sshKeyfilePassword', 'connectionDefinition'];
|
|
105
|
+
const additionalFieldsToMask = [
|
|
106
|
+
'databaseUrl',
|
|
107
|
+
'server',
|
|
108
|
+
'port',
|
|
109
|
+
'user',
|
|
110
|
+
'sshBastionHost',
|
|
111
|
+
'sshHost',
|
|
112
|
+
'sshKeyFile',
|
|
113
|
+
'sshLogin',
|
|
114
|
+
'sshMode',
|
|
115
|
+
'sshPort',
|
|
116
|
+
'sslCaFile',
|
|
117
|
+
'sslCertFilePassword',
|
|
118
|
+
'sslKeyFile',
|
|
119
|
+
'sslRejectUnauthorized',
|
|
120
|
+
'secretAccessKey',
|
|
121
|
+
'accessKeyId',
|
|
122
|
+
'endpoint',
|
|
123
|
+
'endpointKey',
|
|
124
|
+
];
|
|
105
125
|
|
|
106
126
|
function encryptConnection(connection, encryptor = null) {
|
|
107
127
|
if (connection.passwordMode != 'saveRaw') {
|
|
@@ -114,7 +134,7 @@ function encryptConnection(connection, encryptor = null) {
|
|
|
114
134
|
|
|
115
135
|
function maskConnection(connection) {
|
|
116
136
|
if (!connection) return connection;
|
|
117
|
-
return _.omit(connection, fieldsToEncrypt);
|
|
137
|
+
return _.omit(connection, [...fieldsToEncrypt, ...additionalFieldsToMask]);
|
|
118
138
|
}
|
|
119
139
|
|
|
120
140
|
function decryptConnection(connection) {
|
package/src/utility/envtools.js
CHANGED
|
@@ -25,8 +25,14 @@ function extractConnectionsFromEnv(env) {
|
|
|
25
25
|
socketPath: env[`SOCKET_PATH_${id}`],
|
|
26
26
|
serviceName: env[`SERVICE_NAME_${id}`],
|
|
27
27
|
authType: env[`AUTH_TYPE_${id}`] || (env[`SOCKET_PATH_${id}`] ? 'socket' : undefined),
|
|
28
|
-
defaultDatabase:
|
|
29
|
-
|
|
28
|
+
defaultDatabase:
|
|
29
|
+
env[`DATABASE_${id}`] ||
|
|
30
|
+
(env[`FILE_${id}`]
|
|
31
|
+
? getDatabaseFileLabel(env[`FILE_${id}`])
|
|
32
|
+
: env[`APISERVERURL1_${id}`]
|
|
33
|
+
? '_api_database_'
|
|
34
|
+
: null),
|
|
35
|
+
singleDatabase: !!env[`DATABASE_${id}`] || !!env[`FILE_${id}`] || !!env[`APISERVERURL1_${id}`],
|
|
30
36
|
displayName: env[`LABEL_${id}`],
|
|
31
37
|
isReadOnly: env[`READONLY_${id}`],
|
|
32
38
|
databases: env[`DBCONFIG_${id}`] ? safeJsonParse(env[`DBCONFIG_${id}`]) : null,
|
|
@@ -54,6 +60,11 @@ function extractConnectionsFromEnv(env) {
|
|
|
54
60
|
sslKeyFile: env[`SSL_KEY_FILE_${id}`],
|
|
55
61
|
sslRejectUnauthorized: env[`SSL_REJECT_UNAUTHORIZED_${id}`],
|
|
56
62
|
trustServerCertificate: env[`SSL_TRUST_CERTIFICATE_${id}`],
|
|
63
|
+
|
|
64
|
+
apiServerUrl1: env[`APISERVERURL1_${id}`],
|
|
65
|
+
apiServerUrl2: env[`APISERVERURL2_${id}`],
|
|
66
|
+
apiKeyHeader: env[`APIKEYHEADER_${id}`],
|
|
67
|
+
apiKeyValue: env[`APIKEYVALUE_${id}`],
|
|
57
68
|
}));
|
|
58
69
|
|
|
59
70
|
return connections;
|