dbgate-api-premium 6.1.4 → 6.1.5
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api-premium",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "6.1.
|
|
4
|
+
"version": "6.1.5",
|
|
5
5
|
"homepage": "https://dbgate.org/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"compare-versions": "^3.6.0",
|
|
30
30
|
"cors": "^2.8.5",
|
|
31
31
|
"cross-env": "^6.0.3",
|
|
32
|
-
"dbgate-datalib": "^6.1.
|
|
32
|
+
"dbgate-datalib": "^6.1.5",
|
|
33
33
|
"dbgate-query-splitter": "^4.11.3",
|
|
34
|
-
"dbgate-sqltree": "^6.1.
|
|
35
|
-
"dbgate-tools": "^6.1.
|
|
34
|
+
"dbgate-sqltree": "^6.1.5",
|
|
35
|
+
"dbgate-tools": "^6.1.5",
|
|
36
36
|
"debug": "^4.3.4",
|
|
37
37
|
"diff": "^5.0.0",
|
|
38
38
|
"diff2html": "^3.4.13",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@types/fs-extra": "^9.0.11",
|
|
83
83
|
"@types/lodash": "^4.14.149",
|
|
84
|
-
"dbgate-types": "^6.1.
|
|
84
|
+
"dbgate-types": "^6.1.5",
|
|
85
85
|
"env-cmd": "^10.1.0",
|
|
86
86
|
"jsdoc-to-markdown": "^9.0.5",
|
|
87
87
|
"node-loader": "^1.0.2",
|
package/src/auth/authProvider.js
CHANGED
|
@@ -3,12 +3,14 @@ const {
|
|
|
3
3
|
getPredefinedPermissions,
|
|
4
4
|
getLogger,
|
|
5
5
|
getConnectionLabel,
|
|
6
|
+
runQueryFmt,
|
|
6
7
|
} = require('dbgate-tools');
|
|
7
8
|
const {
|
|
8
9
|
storageSelectFmt,
|
|
9
10
|
storageReadUserRolePermissions,
|
|
10
11
|
storageReadUserPermissions,
|
|
11
12
|
storageReadRolePermissions,
|
|
13
|
+
storageSqlCommandFmt,
|
|
12
14
|
} = require('../controllers/storageDb');
|
|
13
15
|
const { getTokenSecret, getTokenLifetime } = require('./authCommon');
|
|
14
16
|
const { AuthProviderBase } = require('./authProvider');
|
|
@@ -143,10 +145,13 @@ class OauthProvider extends StorageProviderBase {
|
|
|
143
145
|
const loginRows = await storageSelectFmt('select * from ~users where ~login = %v', login);
|
|
144
146
|
const permissions = await loadPermissionsForUserId(loginRows[0]?.id ?? -1);
|
|
145
147
|
|
|
146
|
-
if (this.config.oauthOnlyDefinedLogins == 1) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
if (this.config.oauthOnlyDefinedLogins == 1 && loginRows.length == 0) {
|
|
149
|
+
return { error: `Username ${login} not allowed to log in` };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (this.config.oauthSaveNotDefinedLogins == 1 && loginRows.length == 0) {
|
|
153
|
+
const email = payload[this.config.oauthEmailField || 'email'] ?? null;
|
|
154
|
+
await storageSqlCommandFmt('insert into ~users (~login, ~email) values (%v, %v)', login, email);
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
let groups =
|
|
@@ -17,7 +17,7 @@ const { hasPermission } = require('../utility/hasPermission');
|
|
|
17
17
|
const { changeSetToSql, removeSchemaFromChangeSet } = require('dbgate-datalib');
|
|
18
18
|
const storageModel = require('../storageModel');
|
|
19
19
|
const { dumpSqlCommand } = require('dbgate-sqltree');
|
|
20
|
-
const { runCommandOnDriver, getLogger } = require('dbgate-tools');
|
|
20
|
+
const { runCommandOnDriver, getLogger, runQueryFmt } = require('dbgate-tools');
|
|
21
21
|
const socket = require('../utility/socket');
|
|
22
22
|
const { obtainRefreshedLicense } = require('../utility/authProxy');
|
|
23
23
|
const { datadir } = require('../utility/directories');
|
|
@@ -31,11 +31,6 @@ function mapConnection(connnection) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
async function runQueryFmt(driver, conn, query, ...args) {
|
|
35
|
-
const dmp = driver.createDumper();
|
|
36
|
-
dmp.put(query, ...args);
|
|
37
|
-
await driver.query(conn, dmp.s);
|
|
38
|
-
}
|
|
39
34
|
|
|
40
35
|
let refreshLicenseStarted = false;
|
|
41
36
|
|
|
@@ -140,7 +135,7 @@ module.exports = {
|
|
|
140
135
|
displayName: 'Internal storage',
|
|
141
136
|
defaultDatabase: process.env.STORAGE_DATABASE,
|
|
142
137
|
singleDatabase: true,
|
|
143
|
-
...getDbConnectionParams(),
|
|
138
|
+
...await getDbConnectionParams(),
|
|
144
139
|
};
|
|
145
140
|
}
|
|
146
141
|
|
|
@@ -4,8 +4,9 @@ const dbgateApi = require('../shell');
|
|
|
4
4
|
const { getPredefinedPermissions, getLogger, extractErrorLogData } = require('dbgate-tools');
|
|
5
5
|
const _ = require('lodash');
|
|
6
6
|
const logger = getLogger('storageDb');
|
|
7
|
+
const { extractConnectionSslParams } = require('../utility/connectUtility');
|
|
7
8
|
|
|
8
|
-
function getDbConnectionParams() {
|
|
9
|
+
async function getDbConnectionParams() {
|
|
9
10
|
const server = process.env.STORAGE_SERVER;
|
|
10
11
|
const port = process.env.STORAGE_PORT;
|
|
11
12
|
const user = process.env.STORAGE_USER;
|
|
@@ -13,6 +14,18 @@ function getDbConnectionParams() {
|
|
|
13
14
|
const database = process.env.STORAGE_DATABASE;
|
|
14
15
|
const engine = process.env.STORAGE_ENGINE;
|
|
15
16
|
const serviceName = process.env.STORAGE_SERVICE_NAME;
|
|
17
|
+
const socketPath = process.env.STORAGE_SOCKET_PATH;
|
|
18
|
+
const databaseUrl = process.env.STORAGE_DATABASE_URL;
|
|
19
|
+
const useDatabaseUrl = !!process.env.STORAGE_DATABASE_URL;
|
|
20
|
+
const authType = process.env.STORAGE_AUTH_TYPE;
|
|
21
|
+
|
|
22
|
+
const useSsl = process.env.STORAGE_USE_SSL;
|
|
23
|
+
const sslCaFile = process.env.STORAGE_SSL_CA_FILE;
|
|
24
|
+
const sslCertFile = process.env.STORAGE_SSL_CERT_FILE;
|
|
25
|
+
const sslCertFilePassword = process.env.STORAGE_SSL_CERT_FILE_PASSWORD;
|
|
26
|
+
const sslKeyFile = process.env.STORAGE_SSL_KEY_FILE;
|
|
27
|
+
const sslRejectUnauthorized = process.env.STORAGE_SSL_REJECT_UNAUTHORIZED;
|
|
28
|
+
const trustServerCertificate = process.env.STORAGE_SSL_TRUST_CERTIFICATE;
|
|
16
29
|
|
|
17
30
|
if (!server || !user || !password || !database || !engine) {
|
|
18
31
|
if (database) {
|
|
@@ -35,7 +48,30 @@ function getDbConnectionParams() {
|
|
|
35
48
|
return null;
|
|
36
49
|
}
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
const res = {
|
|
52
|
+
server,
|
|
53
|
+
port,
|
|
54
|
+
user,
|
|
55
|
+
password,
|
|
56
|
+
database,
|
|
57
|
+
engine,
|
|
58
|
+
serviceName,
|
|
59
|
+
socketPath,
|
|
60
|
+
databaseUrl,
|
|
61
|
+
useDatabaseUrl,
|
|
62
|
+
authType,
|
|
63
|
+
useSsl,
|
|
64
|
+
sslCaFile,
|
|
65
|
+
sslCertFile,
|
|
66
|
+
sslCertFilePassword,
|
|
67
|
+
sslKeyFile,
|
|
68
|
+
sslRejectUnauthorized,
|
|
69
|
+
trustServerCertificate,
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
...res,
|
|
73
|
+
ssl: await extractConnectionSslParams(res),
|
|
74
|
+
};
|
|
39
75
|
}
|
|
40
76
|
|
|
41
77
|
let storageConnection = null;
|
|
@@ -47,7 +83,7 @@ async function getStorageConnectionCore() {
|
|
|
47
83
|
return [storageConnection, storageDriver];
|
|
48
84
|
}
|
|
49
85
|
|
|
50
|
-
const dbConnectionParams = getDbConnectionParams();
|
|
86
|
+
const dbConnectionParams = await getDbConnectionParams();
|
|
51
87
|
|
|
52
88
|
if (!dbConnectionParams) {
|
|
53
89
|
return [null, null];
|
|
@@ -125,6 +161,10 @@ async function storageSelectFmt(sql, ...params) {
|
|
|
125
161
|
return resp.rows;
|
|
126
162
|
}
|
|
127
163
|
|
|
164
|
+
async function storageSqlCommandFmt(sql, ...params) {
|
|
165
|
+
await storageSelectFmt(sql, ...params);
|
|
166
|
+
}
|
|
167
|
+
|
|
128
168
|
async function storageReadUserRolePermissions(userId) {
|
|
129
169
|
const resp = await storageSelectFmt(
|
|
130
170
|
`
|
|
@@ -213,4 +253,5 @@ module.exports = {
|
|
|
213
253
|
storageReadConfig,
|
|
214
254
|
storageWriteConfig,
|
|
215
255
|
getStorageConnectionError,
|
|
256
|
+
storageSqlCommandFmt,
|
|
216
257
|
};
|
package/src/currentVersion.js
CHANGED
|
@@ -9,6 +9,7 @@ const { setAuthProxyLicense } = require('./authProxy');
|
|
|
9
9
|
const axios = require('axios');
|
|
10
10
|
const crypto = require('crypto');
|
|
11
11
|
const platformInfo = require('./platformInfo');
|
|
12
|
+
const processArgs = require('./processArgs');
|
|
12
13
|
|
|
13
14
|
const logger = getLogger('checkLicense');
|
|
14
15
|
|
|
@@ -107,6 +108,13 @@ async function getAwsMetadata() {
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
function checkLicenseKey(licenseKey) {
|
|
111
|
+
if (processArgs.runE2eTests) {
|
|
112
|
+
return {
|
|
113
|
+
status: 'ok',
|
|
114
|
+
type: 'premium',
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
110
118
|
try {
|
|
111
119
|
const decoded = jwt.verify(licenseKey, publicKey, {
|
|
112
120
|
algorithms: ['RS256'],
|
|
@@ -176,6 +184,13 @@ function getAwsToken() {
|
|
|
176
184
|
}
|
|
177
185
|
|
|
178
186
|
async function checkLicense() {
|
|
187
|
+
if (processArgs.runE2eTests) {
|
|
188
|
+
return {
|
|
189
|
+
status: 'ok',
|
|
190
|
+
type: 'premium',
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
179
194
|
if (process.env.DBGATE_LICENSE) {
|
|
180
195
|
return checkLicenseKey(process.env.DBGATE_LICENSE);
|
|
181
196
|
}
|