@certd/lib-server 1.39.0 → 1.39.2
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/dist/basic/base-controller.js +8 -3
- package/dist/basic/base-service.js +2 -1
- package/dist/basic/constants.d.ts +2 -0
- package/dist/basic/constants.js +2 -0
- package/dist/system/settings/service/models.d.ts +1 -0
- package/dist/system/settings/service/models.js +1 -0
- package/dist/system/settings/service/sys-settings-service.d.ts +1 -0
- package/dist/system/settings/service/sys-settings-service.js +38 -2
- package/dist/user/access/entity/access.d.ts +1 -0
- package/dist/user/access/entity/access.js +5 -0
- package/dist/user/access/service/access-service.d.ts +6 -0
- package/dist/user/access/service/access-service.js +34 -0
- package/dist/user/addon/entity/addon.d.ts +1 -0
- package/dist/user/addon/entity/addon.js +5 -0
- package/dist/user/addon/service/addon-service.d.ts +1 -0
- package/dist/user/addon/service/addon-service.js +6 -0
- package/package.json +7 -7
|
@@ -111,11 +111,16 @@ export class BaseController {
|
|
|
111
111
|
await authService.checkProjectId(service, id, projectId);
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
114
|
-
if (
|
|
115
|
-
|
|
114
|
+
if (userId === Constants.systemUserId) {
|
|
115
|
+
//系统级别,不检查权限
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
118
|
-
|
|
118
|
+
if (allowAdmin) {
|
|
119
|
+
await authService.checkUserIdButAllowAdmin(this.ctx, service, id);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
await authService.checkUserId(service, id, userId);
|
|
123
|
+
}
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
return { projectId, userId };
|
|
@@ -11,6 +11,7 @@ import { PermissionException, ValidateException } from './exception/index.js';
|
|
|
11
11
|
import { In } from 'typeorm';
|
|
12
12
|
import { Inject } from '@midwayjs/core';
|
|
13
13
|
import { TypeORMDataSourceManager } from '@midwayjs/typeorm';
|
|
14
|
+
import { Constants } from './constants.js';
|
|
14
15
|
/**
|
|
15
16
|
* 服务基类
|
|
16
17
|
*/
|
|
@@ -232,7 +233,7 @@ __decorate([
|
|
|
232
233
|
], BaseService.prototype, "dataSourceManager", void 0);
|
|
233
234
|
export function checkUserProjectParam(userId, projectId) {
|
|
234
235
|
if (projectId != null) {
|
|
235
|
-
if (userId !==
|
|
236
|
+
if (userId !== Constants.enterpriseUserId) {
|
|
236
237
|
throw new ValidateException('userId projectId 错误');
|
|
237
238
|
}
|
|
238
239
|
return true;
|
package/dist/basic/constants.js
CHANGED
|
@@ -21,6 +21,7 @@ export declare class SysSettingsService extends BaseService<SysSettingsEntity> {
|
|
|
21
21
|
reloadSettings(): Promise<void>;
|
|
22
22
|
reloadPublicSettings(): Promise<void>;
|
|
23
23
|
reloadPrivateSettings(): Promise<void>;
|
|
24
|
+
setEnvironmentVars(vars: string): void;
|
|
24
25
|
updateByKey(key: string, setting: any): Promise<void>;
|
|
25
26
|
backupSecret(): Promise<void>;
|
|
26
27
|
getSecret(): Promise<SysSecret>;
|
|
@@ -17,8 +17,9 @@ import { cache, logger, mergeUtils, setGlobalProxy } from '@certd/basic';
|
|
|
17
17
|
import * as dns from 'node:dns';
|
|
18
18
|
import { BaseService, setAdminMode } from '../../../basic/index.js';
|
|
19
19
|
import { executorQueue } from '../../basic/service/executor-queue.js';
|
|
20
|
-
import { isComm } from '@certd/plus-core';
|
|
20
|
+
import { isComm, isPlus } from '@certd/plus-core';
|
|
21
21
|
const { merge } = mergeUtils;
|
|
22
|
+
let lastSaveEnvVars = {};
|
|
22
23
|
/**
|
|
23
24
|
* 设置
|
|
24
25
|
*/
|
|
@@ -142,7 +143,9 @@ let SysSettingsService = class SysSettingsService extends BaseService {
|
|
|
142
143
|
}
|
|
143
144
|
async reloadPublicSettings() {
|
|
144
145
|
const publicSetting = await this.getPublicSettings();
|
|
145
|
-
|
|
146
|
+
if (isPlus()) {
|
|
147
|
+
setAdminMode(publicSetting.adminMode);
|
|
148
|
+
}
|
|
146
149
|
}
|
|
147
150
|
async reloadPrivateSettings() {
|
|
148
151
|
const privateSetting = await this.getPrivateSettings();
|
|
@@ -158,6 +161,39 @@ let SysSettingsService = class SysSettingsService extends BaseService {
|
|
|
158
161
|
executorQueue.setMaxRunningCount(privateSetting.pipelineMaxRunningCount);
|
|
159
162
|
}
|
|
160
163
|
setSslProviderReverseProxies(privateSetting.reverseProxies);
|
|
164
|
+
//加载环境变量
|
|
165
|
+
this.setEnvironmentVars(privateSetting.environmentVars);
|
|
166
|
+
}
|
|
167
|
+
setEnvironmentVars(vars) {
|
|
168
|
+
const envVars = {};
|
|
169
|
+
if (typeof vars !== 'string') {
|
|
170
|
+
vars = "";
|
|
171
|
+
}
|
|
172
|
+
vars.split('\n').forEach(line => {
|
|
173
|
+
line = line.trim();
|
|
174
|
+
if (!line || line.startsWith('#')) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const arr = line.split("#");
|
|
178
|
+
if (arr.length > 0) {
|
|
179
|
+
line = arr[0].trim();
|
|
180
|
+
}
|
|
181
|
+
if (!line.includes("=")) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const [key, value] = line.split('=');
|
|
185
|
+
if (key && value) {
|
|
186
|
+
envVars[key.trim()] = value.trim();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
//先删除旧环境变量
|
|
190
|
+
if (lastSaveEnvVars) {
|
|
191
|
+
for (const key in lastSaveEnvVars) {
|
|
192
|
+
delete process.env[key];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
merge(process.env, envVars);
|
|
196
|
+
lastSaveEnvVars = envVars;
|
|
161
197
|
}
|
|
162
198
|
async updateByKey(key, setting) {
|
|
163
199
|
const entity = await this.getByKey(key);
|
|
@@ -13,6 +13,7 @@ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
|
13
13
|
*/
|
|
14
14
|
let AccessEntity = class AccessEntity {
|
|
15
15
|
id;
|
|
16
|
+
keyId;
|
|
16
17
|
userId; // 0为系统级别, -1为企业,大于1为用户
|
|
17
18
|
name;
|
|
18
19
|
type;
|
|
@@ -26,6 +27,10 @@ __decorate([
|
|
|
26
27
|
PrimaryGeneratedColumn(),
|
|
27
28
|
__metadata("design:type", Number)
|
|
28
29
|
], AccessEntity.prototype, "id", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
Column({ name: 'key_id', comment: 'key_id', length: 100 }),
|
|
32
|
+
__metadata("design:type", String)
|
|
33
|
+
], AccessEntity.prototype, "keyId", void 0);
|
|
29
34
|
__decorate([
|
|
30
35
|
Column({ name: 'user_id', comment: '用户id' }),
|
|
31
36
|
__metadata("design:type", Number)
|
|
@@ -44,4 +44,10 @@ export declare class AccessService extends BaseService<AccessEntity> {
|
|
|
44
44
|
}[];
|
|
45
45
|
getDefineByType(type: string): import("@certd/pipeline").Registrable;
|
|
46
46
|
getSimpleByIds(ids: number[], userId: any, projectId?: number): Promise<AccessEntity[]>;
|
|
47
|
+
/**
|
|
48
|
+
* 复制授权到其他项目
|
|
49
|
+
* @param accessId
|
|
50
|
+
* @param projectId
|
|
51
|
+
*/
|
|
52
|
+
copyTo(accessId: number, projectId?: number): Promise<any>;
|
|
47
53
|
}
|
|
@@ -14,6 +14,7 @@ import { AccessGetter, BaseService, PermissionException, ValidateException } fro
|
|
|
14
14
|
import { AccessEntity } from '../entity/access.js';
|
|
15
15
|
import { accessRegistry, newAccess } from '@certd/pipeline';
|
|
16
16
|
import { EncryptService } from './encrypt-service.js';
|
|
17
|
+
import { logger, utils } from '@certd/basic';
|
|
17
18
|
/**
|
|
18
19
|
* 授权
|
|
19
20
|
*/
|
|
@@ -46,6 +47,7 @@ let AccessService = class AccessService extends BaseService {
|
|
|
46
47
|
}
|
|
47
48
|
delete param._copyFrom;
|
|
48
49
|
this.encryptSetting(param, oldEntity);
|
|
50
|
+
param.keyId = "ac_" + utils.id.simpleNanoId();
|
|
49
51
|
return await super.add(param);
|
|
50
52
|
}
|
|
51
53
|
encryptSetting(param, oldSettingEntity) {
|
|
@@ -114,6 +116,7 @@ let AccessService = class AccessService extends BaseService {
|
|
|
114
116
|
throw new ValidateException('该授权配置不存在,请确认是否已被删除');
|
|
115
117
|
}
|
|
116
118
|
this.encryptSetting(param, oldEntity);
|
|
119
|
+
delete param.keyId;
|
|
117
120
|
return await super.update(param);
|
|
118
121
|
}
|
|
119
122
|
async getSimpleInfo(id) {
|
|
@@ -203,6 +206,37 @@ let AccessService = class AccessService extends BaseService {
|
|
|
203
206
|
},
|
|
204
207
|
});
|
|
205
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* 复制授权到其他项目
|
|
211
|
+
* @param accessId
|
|
212
|
+
* @param projectId
|
|
213
|
+
*/
|
|
214
|
+
async copyTo(accessId, projectId) {
|
|
215
|
+
const access = await this.info(accessId);
|
|
216
|
+
if (access == null) {
|
|
217
|
+
throw new Error(`该授权配置不存在,请确认是否已被删除:id=${accessId}`);
|
|
218
|
+
}
|
|
219
|
+
const keyId = access.keyId;
|
|
220
|
+
//检查目标项目里是否已经有相同keyId的配置
|
|
221
|
+
const existAccess = await this.repository.findOne({
|
|
222
|
+
where: {
|
|
223
|
+
keyId,
|
|
224
|
+
projectId,
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
if (existAccess) {
|
|
228
|
+
logger.info(`目标项目已存在相同keyId的授权配置,跳过复制:keyId=${keyId}`);
|
|
229
|
+
return existAccess.id;
|
|
230
|
+
}
|
|
231
|
+
const newAccess = {
|
|
232
|
+
...access,
|
|
233
|
+
userId: -1,
|
|
234
|
+
id: undefined,
|
|
235
|
+
projectId,
|
|
236
|
+
};
|
|
237
|
+
await this.repository.save(newAccess);
|
|
238
|
+
return newAccess.id;
|
|
239
|
+
}
|
|
206
240
|
};
|
|
207
241
|
__decorate([
|
|
208
242
|
InjectEntityModel(AccessEntity),
|
|
@@ -12,6 +12,7 @@ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
|
12
12
|
*/
|
|
13
13
|
let AddonEntity = class AddonEntity {
|
|
14
14
|
id;
|
|
15
|
+
keyId;
|
|
15
16
|
userId;
|
|
16
17
|
name;
|
|
17
18
|
addonType;
|
|
@@ -27,6 +28,10 @@ __decorate([
|
|
|
27
28
|
PrimaryGeneratedColumn(),
|
|
28
29
|
__metadata("design:type", Number)
|
|
29
30
|
], AddonEntity.prototype, "id", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
Column({ name: 'key_id', comment: 'key_id', length: 100 }),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], AddonEntity.prototype, "keyId", void 0);
|
|
30
35
|
__decorate([
|
|
31
36
|
Column({ name: 'user_id', comment: '用户id' }),
|
|
32
37
|
__metadata("design:type", Number)
|
|
@@ -13,6 +13,7 @@ import { In, Repository } from "typeorm";
|
|
|
13
13
|
import { BaseService, ValidateException } from "../../../index.js";
|
|
14
14
|
import { addonRegistry } from "../api/index.js";
|
|
15
15
|
import { AddonEntity } from "../entity/addon.js";
|
|
16
|
+
import { utils } from "@certd/basic";
|
|
16
17
|
/**
|
|
17
18
|
* Addon
|
|
18
19
|
*/
|
|
@@ -46,6 +47,7 @@ let AddonService = class AddonService extends BaseService {
|
|
|
46
47
|
else {
|
|
47
48
|
param.isSystem = false;
|
|
48
49
|
}
|
|
50
|
+
param.keyId = "ad_" + utils.id.simpleNanoId();
|
|
49
51
|
delete param._copyFrom;
|
|
50
52
|
return await super.add(param);
|
|
51
53
|
}
|
|
@@ -58,6 +60,7 @@ let AddonService = class AddonService extends BaseService {
|
|
|
58
60
|
if (oldEntity == null) {
|
|
59
61
|
throw new ValidateException("该Addon配置不存在,请确认是否已被删除");
|
|
60
62
|
}
|
|
63
|
+
delete param.keyId;
|
|
61
64
|
return await super.update(param);
|
|
62
65
|
}
|
|
63
66
|
async getSimpleInfo(id) {
|
|
@@ -67,6 +70,7 @@ let AddonService = class AddonService extends BaseService {
|
|
|
67
70
|
}
|
|
68
71
|
return {
|
|
69
72
|
id: entity.id,
|
|
73
|
+
keyId: entity.keyId,
|
|
70
74
|
name: entity.name,
|
|
71
75
|
userId: entity.userId,
|
|
72
76
|
addonType: entity.addonType,
|
|
@@ -95,6 +99,7 @@ let AddonService = class AddonService extends BaseService {
|
|
|
95
99
|
},
|
|
96
100
|
select: {
|
|
97
101
|
id: true,
|
|
102
|
+
keyId: true,
|
|
98
103
|
name: true,
|
|
99
104
|
addonType: true,
|
|
100
105
|
type: true,
|
|
@@ -123,6 +128,7 @@ let AddonService = class AddonService extends BaseService {
|
|
|
123
128
|
const setting = JSON.parse(res.setting);
|
|
124
129
|
return {
|
|
125
130
|
id: res.id,
|
|
131
|
+
keyId: res.keyId,
|
|
126
132
|
addonType: res.addonType,
|
|
127
133
|
type: res.type,
|
|
128
134
|
name: res.name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@certd/lib-server",
|
|
3
|
-
"version": "1.39.
|
|
3
|
+
"version": "1.39.2",
|
|
4
4
|
"description": "midway with flyway, sql upgrade way ",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
],
|
|
29
29
|
"license": "AGPL",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@certd/acme-client": "^1.39.
|
|
32
|
-
"@certd/basic": "^1.39.
|
|
33
|
-
"@certd/pipeline": "^1.39.
|
|
34
|
-
"@certd/plugin-lib": "^1.39.
|
|
35
|
-
"@certd/plus-core": "^1.39.
|
|
31
|
+
"@certd/acme-client": "^1.39.2",
|
|
32
|
+
"@certd/basic": "^1.39.2",
|
|
33
|
+
"@certd/pipeline": "^1.39.2",
|
|
34
|
+
"@certd/plugin-lib": "^1.39.2",
|
|
35
|
+
"@certd/plus-core": "^1.39.2",
|
|
36
36
|
"@midwayjs/cache": "3.14.0",
|
|
37
37
|
"@midwayjs/core": "3.20.11",
|
|
38
38
|
"@midwayjs/i18n": "3.20.13",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"typeorm": "^0.3.11",
|
|
65
65
|
"typescript": "^5.4.2"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "f47773348312d5480b248c02beed9e162f59e3c7"
|
|
68
68
|
}
|