@cloudbase/manager-node 5.5.4 → 5.5.6-beta.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.
@@ -22,6 +22,7 @@ const cloudApp_1 = require("./cloudApp");
22
22
  const permission_1 = require("./permission");
23
23
  const sandbox_1 = require("./sandbox");
24
24
  const aiModel_1 = require("./aiModel");
25
+ const monitor_1 = require("./monitor");
25
26
  class Environment {
26
27
  constructor(context, envId) {
27
28
  this.inited = false;
@@ -47,6 +48,7 @@ class Environment {
47
48
  this.cloudAppService = new cloudApp_1.CloudAppService(this);
48
49
  this.sandboxService = new sandbox_1.SandboxService(this);
49
50
  this.aiModelService = new aiModel_1.AiModelService(this);
51
+ this.monitorService = new monitor_1.MonitorService(this);
50
52
  }
51
53
  async lazyInit() {
52
54
  if (!this.inited) {
@@ -121,6 +123,9 @@ class Environment {
121
123
  getAiModelService() {
122
124
  return this.aiModelService;
123
125
  }
126
+ getMonitorService() {
127
+ return this.monitorService;
128
+ }
124
129
  getCommonService(serviceType = 'tcb', serviceVersion) {
125
130
  return new common_1.CommonService(this, serviceType, serviceVersion);
126
131
  }
package/lib/index.js CHANGED
@@ -122,6 +122,9 @@ class CloudBase {
122
122
  get aiModel() {
123
123
  return this.currentEnvironment().getAiModelService();
124
124
  }
125
+ get monitor() {
126
+ return this.currentEnvironment().getMonitorService();
127
+ }
125
128
  get docs() {
126
129
  if (!this.docsService) {
127
130
  this.docsService = new docs_1.DocsService();
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.MonitorService = void 0;
18
+ const error_1 = require("../error");
19
+ const utils_1 = require("../utils");
20
+ __exportStar(require("./types"), exports);
21
+ // Period 与时间范围的约束规则
22
+ const ONE_DAY_MS = 24 * 60 * 60 * 1000;
23
+ const THREE_DAYS_MS = 3 * ONE_DAY_MS;
24
+ const PERIOD_RULES = [
25
+ { maxRangeMs: ONE_DAY_MS, allowed: [300, 3600] },
26
+ { maxRangeMs: THREE_DAYS_MS, allowed: [300, 3600, 86400] },
27
+ // 超过3天
28
+ { maxRangeMs: Infinity, allowed: [3600, 86400] }
29
+ ];
30
+ function validatePeriod(startStr, endStr, period) {
31
+ if (period === undefined)
32
+ return;
33
+ const startMs = new Date(startStr).getTime();
34
+ const endMs = new Date(endStr).getTime();
35
+ if (isNaN(startMs) || isNaN(endMs))
36
+ return;
37
+ const rangeMs = endMs - startMs;
38
+ const rule = PERIOD_RULES.find(r => rangeMs <= r.maxRangeMs);
39
+ if (rule && !rule.allowed.includes(period)) {
40
+ throw new error_1.CloudBaseError(`Period=${period} 不适用于当前时间范围。` +
41
+ `时间范围 ${startStr} ~ ${endStr}(约 ${(rangeMs / ONE_DAY_MS).toFixed(1)} 天)` +
42
+ `仅支持 Period: [${rule.allowed.join(', ')}]`);
43
+ }
44
+ }
45
+ class MonitorService {
46
+ constructor(environment) {
47
+ this.envId = environment.getEnvId();
48
+ this.cloudService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
49
+ }
50
+ /**
51
+ * 查询环境监控数据
52
+ *
53
+ * 根据指定指标名称,查询当前环境在指定时间范围内的监控数据,
54
+ * 返回按统计粒度聚合后的时序数据。
55
+ *
56
+ * @param params 查询参数
57
+ * @returns 时序监控数据
58
+ *
59
+ * @example
60
+ * // 查询静态网站存储容量
61
+ * const res = await monitor.describeCurveData({
62
+ * MetricName: 'StaticFsSizePkg',
63
+ * StartTime: '2026-02-05 00:00:00',
64
+ * EndTime: '2026-02-06 23:59:59',
65
+ * Period: 3600
66
+ * })
67
+ *
68
+ * @example
69
+ * // 查询云托管某服务某版本的错误响应
70
+ * const res = await monitor.describeCurveData({
71
+ * MetricName: 'TkeHttpErrorService',
72
+ * StartTime: '2026-03-13 00:00:00',
73
+ * EndTime: '2026-03-16 23:59:59',
74
+ * ResourceID: 'my-service',
75
+ * SubresourceID: 'my-service-001'
76
+ * })
77
+ */
78
+ async describeCurveData(params) {
79
+ // 校验 Period 与时间范围的约束关系
80
+ validatePeriod(params.StartTime, params.EndTime, params.Period);
81
+ const requestParams = {
82
+ EnvId: this.envId,
83
+ MetricName: params.MetricName,
84
+ StartTime: params.StartTime,
85
+ EndTime: params.EndTime
86
+ };
87
+ if (params.ResourceID !== undefined) {
88
+ requestParams.ResourceID = params.ResourceID;
89
+ }
90
+ if (params.WxAppId !== undefined) {
91
+ requestParams.WxAppId = params.WxAppId;
92
+ }
93
+ if (params.SubresourceID !== undefined) {
94
+ requestParams.SubresourceID = params.SubresourceID;
95
+ }
96
+ if (params.ThirdResource !== undefined) {
97
+ requestParams.ThirdResource = params.ThirdResource;
98
+ }
99
+ if (params.Period !== undefined) {
100
+ requestParams.Period = params.Period;
101
+ }
102
+ return this.cloudService.request('DescribeCurveData', requestParams);
103
+ }
104
+ }
105
+ exports.MonitorService = MonitorService;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -18,7 +18,11 @@ class PermissionService {
18
18
  constructor(environment) {
19
19
  this.environment = environment;
20
20
  this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
21
+ this.lowcodeService = new utils_1.CloudService(environment.cloudBaseContext, 'lowcode', '2021-01-08');
21
22
  }
23
+ /**
24
+ * @deprecated 已废弃,网关鉴权策略已由 OPA 接管,请使用 modifyEnvAuthzConfig 替代
25
+ */
22
26
  async modifyResourcePermission(options) {
23
27
  const { EnvId } = this.environment.lazyEnvironmentConfig;
24
28
  const { resourceType, resource, permission, securityRule } = options;
@@ -51,6 +55,9 @@ class PermissionService {
51
55
  }
52
56
  return this.tcbService.request('ModifyResourcePermission', reqData);
53
57
  }
58
+ /**
59
+ * @deprecated 已废弃,网关鉴权策略已由 OPA 接管,请使用 describeResourcePolicyList 或 describeEnvAuthzConfig 替代
60
+ */
54
61
  async describeResourcePermission(options) {
55
62
  const { EnvId } = this.environment.lazyEnvironmentConfig;
56
63
  const { resourceType, resources } = options;
@@ -288,6 +295,104 @@ class PermissionService {
288
295
  RoleIds: roleIds
289
296
  });
290
297
  }
298
+ /**
299
+ * 拉取环境下的所有用户自定义的网关鉴权策略列表
300
+ * 注意:PG 环境无需调用,直接按照无存量策略处理;
301
+ * 若环境 meta 中 authz_engine 值为 opa,则网关策略不生效,无需调用
302
+ */
303
+ async describeResourcePolicyList(options = {}) {
304
+ const { resourceType } = options;
305
+ if (resourceType !== undefined && (typeof resourceType !== 'string' || resourceType.trim().length === 0)) {
306
+ throw new Error('Invalid resourceType');
307
+ }
308
+ // PG 环境无需调用,直接返回空策略列表
309
+ if (await this.isPostgresqlEnv()) {
310
+ const emptyData = { PolicyList: [], Total: '0' };
311
+ return {
312
+ Data: emptyData,
313
+ RequestId: ''
314
+ };
315
+ }
316
+ // authz_engine 为 opa 时网关策略不生效,无需调用,直接返回空策略列表
317
+ if (await this.isOpaAuthzEngine()) {
318
+ const emptyData = { PolicyList: [], Total: '0' };
319
+ return {
320
+ Data: emptyData,
321
+ RequestId: ''
322
+ };
323
+ }
324
+ const { EnvId } = this.environment.lazyEnvironmentConfig;
325
+ const reqData = {
326
+ EnvId,
327
+ ResourceType: resourceType || 'policy'
328
+ };
329
+ return this.lowcodeService.request('DescribeResourcePolicyList', reqData);
330
+ }
331
+ /**
332
+ * 拉取环境下的鉴权策略配置
333
+ * key: authz.platform.extension.rego - 单独为该环境配置的策略
334
+ * key: authz.user.rego - 用户配置的策略
335
+ */
336
+ async describeEnvAuthzConfig(options) {
337
+ const { key } = options;
338
+ if (!key || (key !== 'authz.platform.extension.rego' && key !== 'authz.user.rego')) {
339
+ throw new Error('key must be "authz.platform.extension.rego" or "authz.user.rego"');
340
+ }
341
+ const { EnvId } = this.environment.lazyEnvironmentConfig;
342
+ return this.tcbService.request('DescribeEnvConfig', {
343
+ EnvId,
344
+ Key: key
345
+ });
346
+ }
347
+ /**
348
+ * 保存用户编写的 rego 策略,保存后旧网关鉴权将直接失效
349
+ */
350
+ async modifyEnvAuthzConfig(options) {
351
+ const { EnvId } = this.environment.lazyEnvironmentConfig;
352
+ const { key, value } = options;
353
+ if (key !== 'authz.user.rego') {
354
+ throw new Error('key must be "authz.user.rego"');
355
+ }
356
+ if (typeof value !== 'string' || value.trim().length === 0) {
357
+ throw new Error('value is required and must be a non-empty string');
358
+ }
359
+ return this.tcbService.request('ModifyEnvConfig', {
360
+ EnvId,
361
+ Key: key,
362
+ Value: value
363
+ });
364
+ }
365
+ /**
366
+ * 获取完整的环境基础信息(含 PostgreSQL、Meta 等字段)
367
+ */
368
+ async getEnvBaseInfo() {
369
+ var _a;
370
+ const { EnvId } = this.environment.lazyEnvironmentConfig;
371
+ const params = { EnvId };
372
+ const res = await this.environment.getEnvService().describeEnvInfo(params);
373
+ return ((_a = res === null || res === void 0 ? void 0 : res.EnvInfo) === null || _a === void 0 ? void 0 : _a.EnvBaseInfo) || {};
374
+ }
375
+ /**
376
+ * 判断当前环境是否为 PostgreSQL 环境
377
+ * PostgreSQL 是数组且长度 > 0 时为 PG 环境
378
+ */
379
+ async isPostgresqlEnv() {
380
+ const envBaseInfo = await this.getEnvBaseInfo();
381
+ return Array.isArray(envBaseInfo.PostgreSQL) && envBaseInfo.PostgreSQL.length > 0;
382
+ }
383
+ /**
384
+ * 判断当前环境的 authz_engine 是否为 opa
385
+ * 从环境 Meta 中查找 Key 为 authz_engine 的标签,Value 为 opa 表示已切到 OPA
386
+ */
387
+ async isOpaAuthzEngine() {
388
+ const envBaseInfo = await this.getEnvBaseInfo();
389
+ const meta = envBaseInfo === null || envBaseInfo === void 0 ? void 0 : envBaseInfo.Meta;
390
+ if (!Array.isArray(meta)) {
391
+ return false;
392
+ }
393
+ const authzEngineTag = meta.find(tag => tag.Key === 'authz_engine');
394
+ return (authzEngineTag === null || authzEngineTag === void 0 ? void 0 : authzEngineTag.Value) === 'opa';
395
+ }
291
396
  }
292
397
  exports.PermissionService = PermissionService;
293
398
  __decorate([
@@ -308,3 +413,12 @@ __decorate([
308
413
  __decorate([
309
414
  (0, utils_1.preLazy)()
310
415
  ], PermissionService.prototype, "deleteRoles", null);
416
+ __decorate([
417
+ (0, utils_1.preLazy)()
418
+ ], PermissionService.prototype, "describeResourcePolicyList", null);
419
+ __decorate([
420
+ (0, utils_1.preLazy)()
421
+ ], PermissionService.prototype, "describeEnvAuthzConfig", null);
422
+ __decorate([
423
+ (0, utils_1.preLazy)()
424
+ ], PermissionService.prototype, "modifyEnvAuthzConfig", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "5.5.4",
3
+ "version": "5.5.6-beta.0",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -18,6 +18,7 @@ import { EnvInfo } from './interfaces';
18
18
  import { PermissionService } from './permission';
19
19
  import { SandboxService } from './sandbox';
20
20
  import { AiModelService } from './aiModel';
21
+ import { MonitorService } from './monitor';
21
22
  export declare class Environment {
22
23
  inited: boolean;
23
24
  cloudBaseContext: CloudBaseContext;
@@ -41,6 +42,7 @@ export declare class Environment {
41
42
  private cloudAppService;
42
43
  private sandboxService;
43
44
  private aiModelService;
45
+ private monitorService;
44
46
  constructor(context: CloudBaseContext, envId: string);
45
47
  lazyInit(): Promise<any>;
46
48
  getEnvId(): string;
@@ -62,6 +64,7 @@ export declare class Environment {
62
64
  getPermissionService(): PermissionService;
63
65
  getSandboxService(): SandboxService;
64
66
  getAiModelService(): AiModelService;
67
+ getMonitorService(): MonitorService;
65
68
  getCommonService(serviceType: string, serviceVersion: any): CommonService;
66
69
  getServicesEnvInfo(): Promise<any>;
67
70
  getAuthConfig(): {
package/types/index.d.ts CHANGED
@@ -19,6 +19,7 @@ import { PermissionService } from './permission';
19
19
  import { SandboxService } from './sandbox';
20
20
  import { CloudAppService } from './cloudApp';
21
21
  import { AiModelService } from './aiModel';
22
+ import { MonitorService } from './monitor';
22
23
  interface CloudBaseConfig {
23
24
  secretId?: string;
24
25
  secretKey?: string;
@@ -84,6 +85,7 @@ declare class CloudBase {
84
85
  get permission(): PermissionService;
85
86
  get sandbox(): SandboxService;
86
87
  get aiModel(): AiModelService;
88
+ get monitor(): MonitorService;
87
89
  get docs(): DocsService;
88
90
  getEnvironmentManager(): EnvironmentManager;
89
91
  getManagerConfig(): CloudBaseConfig;
@@ -484,6 +484,10 @@ export interface EnvBaseInfo {
484
484
  Key: string;
485
485
  Value: string;
486
486
  }>;
487
+ Meta?: Array<{
488
+ Key: string;
489
+ Value: string;
490
+ }>;
487
491
  CreateTime?: string;
488
492
  UpdateTime?: string;
489
493
  EnvPreferences?: Record<string, any>;
@@ -0,0 +1,37 @@
1
+ import { Environment } from '../environment';
2
+ import { IDescribeCurveDataParams, IDescribeCurveDataResponse } from './types';
3
+ export * from './types';
4
+ export declare class MonitorService {
5
+ private envId;
6
+ private cloudService;
7
+ constructor(environment: Environment);
8
+ /**
9
+ * 查询环境监控数据
10
+ *
11
+ * 根据指定指标名称,查询当前环境在指定时间范围内的监控数据,
12
+ * 返回按统计粒度聚合后的时序数据。
13
+ *
14
+ * @param params 查询参数
15
+ * @returns 时序监控数据
16
+ *
17
+ * @example
18
+ * // 查询静态网站存储容量
19
+ * const res = await monitor.describeCurveData({
20
+ * MetricName: 'StaticFsSizePkg',
21
+ * StartTime: '2026-02-05 00:00:00',
22
+ * EndTime: '2026-02-06 23:59:59',
23
+ * Period: 3600
24
+ * })
25
+ *
26
+ * @example
27
+ * // 查询云托管某服务某版本的错误响应
28
+ * const res = await monitor.describeCurveData({
29
+ * MetricName: 'TkeHttpErrorService',
30
+ * StartTime: '2026-03-13 00:00:00',
31
+ * EndTime: '2026-03-16 23:59:59',
32
+ * ResourceID: 'my-service',
33
+ * SubresourceID: 'my-service-001'
34
+ * })
35
+ */
36
+ describeCurveData(params: IDescribeCurveDataParams): Promise<IDescribeCurveDataResponse>;
37
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * 监控指标名称
3
+ *
4
+ * 文档型数据库 / SQL型数据库 / 云函数 / 云托管 / 静态网站 / 身份认证 / API调用 / HTTP网关 / 大模型 / 知识库 / 用户登录 / 环境QPS / 数据库连接器 / 网关
5
+ */
6
+ export type MetricName = 'DbRead' | 'DbWrite' | 'DbCostTime10ms' | 'DbCostTime50ms' | 'DbCostTime100ms' | 'DbSizepkg' | 'MysqlStorageUsage' | 'MysqlCCU' | 'MysqlCpuUsageRate' | 'MysqlDbConnections' | 'MysqlMemoryUse' | 'MysqlSlowQueries' | 'MysqlTps' | 'MysqlQps' | 'FunctionCU' | 'FunctionInvocation' | 'FunctionFlux' | 'FunctionThrottle' | 'FunctionConcurrentExecutions' | 'FunctionTimeout' | 'FunctionGBs' | 'FunctionError' | 'FunctionDuration' | 'FunctionConcurrencyMemoryMB' | 'FunctionMemOverFlow' | 'FunctionIdleProvisioned' | 'FunctionProvisionedConcurrency' | 'TkeRspTimeService' | 'TkeCpuUsedService' | 'TkeMemUsedService' | 'TkeQPSService' | 'TkePodNumService' | 'TkeHttpServiceNatPkg' | 'TkeCUUsedService' | 'TkeInvokeNumService' | 'TkeHttpErrorService' | 'StaticFsFluxPkg' | 'StaticFsSizePkg' | 'AuthInvocationNumPkg' | 'GwCloudDevelopmentSecureCallsInvocation' | 'GwWXInvocation' | 'GwCloudDevelopmentStandardCallsInvocation' | 'AIPromptTokenNumPkg' | 'AICompletionTokenNumPkg' | 'AITotalTokenNumPkg' | 'KnowledgeBaseCapacity' | 'DayActiveLoginAnonymousUser' | 'DayActiveLoginAllUser' | 'DayActiveLoginExternalUser' | 'DayActiveLoginInternalUser' | 'EnvQPSAll' | 'MongoConnectorRead' | 'MongoConnectorWrite' | 'MongoConnectorCostTime10ms' | 'MongoConnectorCostTime50ms' | 'MongoConnectorCostTime100ms' | 'MongoConnectorInvokeNum' | 'GatewayTraceEnvQPS' | 'GatewayShowAPIInvokeNum' | 'GatewayShowAPICostTotal' | 'GatewayShowAPIHTTP2XX' | 'GatewayShowAPIHTTPError' | 'GatewayTraceAccessSourceQPS' | 'GatewayShowHttpInvokeNum' | 'GatewayShowHttpCostTotal' | 'GatewayShowHttpHTTP2XX' | 'GatewayShowHttpHTTPError' | 'GatewayTraceResourceQPS' | (string & {});
7
+ /** 统计周期(秒) */
8
+ export type MetricPeriod = 300 | 3600 | 86400;
9
+ /** DescribeCurveData 请求参数 */
10
+ export interface IDescribeCurveDataParams {
11
+ /** 指标名称 */
12
+ MetricName: MetricName;
13
+ /** 开始时间,格式 'YYYY-MM-DD HH:mm:ss',需早于结束时间至少5分钟 */
14
+ StartTime: string;
15
+ /** 结束时间,格式 'YYYY-MM-DD HH:mm:ss',需晚于开始时间至少5分钟 */
16
+ EndTime: string;
17
+ /**
18
+ * 资源ID(可选)
19
+ * - 文档型数据库:集合名称
20
+ * - 云函数:函数名称
21
+ * - 云托管:服务名称(必传)
22
+ * - 数据库连接器:实例id(必传)
23
+ * - 网关-调用链路维度:小程序API传'wx',云开发API传'http_openapi'(必传)
24
+ * - 网关-环境/资源维度:必传
25
+ * - 留空则查询整个 namespace 的指标
26
+ */
27
+ ResourceID?: string;
28
+ /** 微信AppId,微信场景必传 */
29
+ WxAppId?: string;
30
+ /** 子资源信息,查询云托管相关指标的具体版本的监控数据,需传入 */
31
+ SubresourceID?: string;
32
+ /** 网关路由 */
33
+ ThirdResource?: string;
34
+ /**
35
+ * 统计周期(秒),仅支持 300 / 3600 / 86400
36
+ * 不传则根据时间范围自动选择:
37
+ * - 1天内:300
38
+ * - 1天~15天:3600
39
+ * - 15天~180天:86400
40
+ *
41
+ * 传入时需遵循以下约束:
42
+ * - 时间范围 ≤ 1天:可取 300 或 3600
43
+ * - 时间范围 > 1天且 ≤ 3天:可取 300、3600 或 86400
44
+ * - 时间范围 > 3天:可取 3600 或 86400
45
+ */
46
+ Period?: MetricPeriod;
47
+ }
48
+ /** DescribeCurveData 响应结果 */
49
+ export interface IDescribeCurveDataResponse {
50
+ /** 开始时间(会根据统计周期取整) */
51
+ StartTime: string;
52
+ /** 结束时间(会根据统计周期取整) */
53
+ EndTime: string;
54
+ /** 指标名 */
55
+ MetricName: string;
56
+ /** 统计周期(秒) */
57
+ Period: number;
58
+ /** 监控数据(整数),与 Time 一一对应 */
59
+ Values: number[];
60
+ /** 时间戳数组(Unix 时间戳,秒级),与 Values 一一对应 */
61
+ Time: number[];
62
+ /** 监控数据(浮点数),与 Time 一一对应 */
63
+ NewValues: number[];
64
+ /** 聚合方式:'last' | 'max' | 'avg' | 'sum' */
65
+ Statistics: string;
66
+ /** 请求ID */
67
+ RequestId: string;
68
+ }
@@ -1,13 +1,20 @@
1
1
  import { Environment } from '../environment';
2
- import { ModifyResourcePermissionOptions, ModifyResourcePermissionResp, DescribeResourcePermissionOptions, DescribeResourcePermissionResp, CreateRoleOptions, CreateRoleResp, DescribeRoleListOptions, DescribeRoleListResp, ModifyRoleOptions, ModifyRoleResp, DeleteRolesOptions, DeleteRolesResp } from './types';
2
+ import { ModifyResourcePermissionOptions, ModifyResourcePermissionResp, DescribeResourcePermissionOptions, DescribeResourcePermissionResp, CreateRoleOptions, CreateRoleResp, DescribeRoleListOptions, DescribeRoleListResp, ModifyRoleOptions, ModifyRoleResp, DeleteRolesOptions, DeleteRolesResp, DescribeResourcePolicyListOptions, DescribeResourcePolicyListResp, DescribeEnvAuthzConfigOptions, DescribeEnvAuthzConfigResp, ModifyEnvAuthzConfigOptions } from './types';
3
3
  export declare class PermissionService {
4
4
  private environment;
5
5
  private tcbService;
6
+ private lowcodeService;
6
7
  constructor(environment: Environment);
8
+ /**
9
+ * @deprecated 已废弃,网关鉴权策略已由 OPA 接管,请使用 modifyEnvAuthzConfig 替代
10
+ */
7
11
  modifyResourcePermission(options: ModifyResourcePermissionOptions): Promise<{
8
12
  Data: ModifyResourcePermissionResp;
9
13
  RequestId: string;
10
14
  }>;
15
+ /**
16
+ * @deprecated 已废弃,网关鉴权策略已由 OPA 接管,请使用 describeResourcePolicyList 或 describeEnvAuthzConfig 替代
17
+ */
11
18
  describeResourcePermission(options: DescribeResourcePermissionOptions): Promise<{
12
19
  Data: DescribeResourcePermissionResp;
13
20
  RequestId: string;
@@ -28,4 +35,43 @@ export declare class PermissionService {
28
35
  Data: DeleteRolesResp;
29
36
  RequestId: string;
30
37
  }>;
38
+ /**
39
+ * 拉取环境下的所有用户自定义的网关鉴权策略列表
40
+ * 注意:PG 环境无需调用,直接按照无存量策略处理;
41
+ * 若环境 meta 中 authz_engine 值为 opa,则网关策略不生效,无需调用
42
+ */
43
+ describeResourcePolicyList(options?: DescribeResourcePolicyListOptions): Promise<{
44
+ Data: DescribeResourcePolicyListResp;
45
+ RequestId: string;
46
+ }>;
47
+ /**
48
+ * 拉取环境下的鉴权策略配置
49
+ * key: authz.platform.extension.rego - 单独为该环境配置的策略
50
+ * key: authz.user.rego - 用户配置的策略
51
+ */
52
+ describeEnvAuthzConfig(options: DescribeEnvAuthzConfigOptions): Promise<{
53
+ Item: DescribeEnvAuthzConfigResp;
54
+ RequestId: string;
55
+ }>;
56
+ /**
57
+ * 保存用户编写的 rego 策略,保存后旧网关鉴权将直接失效
58
+ */
59
+ modifyEnvAuthzConfig(options: ModifyEnvAuthzConfigOptions): Promise<{
60
+ AffectedRows: number;
61
+ RequestId: string;
62
+ }>;
63
+ /**
64
+ * 获取完整的环境基础信息(含 PostgreSQL、Meta 等字段)
65
+ */
66
+ private getEnvBaseInfo;
67
+ /**
68
+ * 判断当前环境是否为 PostgreSQL 环境
69
+ * PostgreSQL 是数组且长度 > 0 时为 PG 环境
70
+ */
71
+ private isPostgresqlEnv;
72
+ /**
73
+ * 判断当前环境的 authz_engine 是否为 opa
74
+ * 从环境 Meta 中查找 Key 为 authz_engine 的标签,Value 为 opa 表示已切到 OPA
75
+ */
76
+ private isOpaAuthzEngine;
31
77
  }
@@ -125,3 +125,37 @@ export interface DeleteRolesResp {
125
125
  SuccessCount?: number;
126
126
  FailedCount?: number;
127
127
  }
128
+ export interface ResourcePolicyItem {
129
+ Effect?: string;
130
+ IsAccess?: boolean;
131
+ PolicyId?: string;
132
+ ResourceId?: string;
133
+ ResourceName?: string;
134
+ ResourceTitle?: string;
135
+ ResourceType?: string;
136
+ RoleId?: string;
137
+ RoleIdentity?: string;
138
+ RoleName?: string;
139
+ SafeRule?: string;
140
+ }
141
+ export interface DescribeResourcePolicyListOptions {
142
+ resourceType?: string;
143
+ }
144
+ export interface DescribeResourcePolicyListResp {
145
+ PolicyList: ResourcePolicyItem[];
146
+ Total: string;
147
+ }
148
+ export interface DescribeEnvAuthzConfigOptions {
149
+ key: 'authz.platform.extension.rego' | 'authz.user.rego';
150
+ }
151
+ export interface DescribeEnvAuthzConfigResp {
152
+ Key: string;
153
+ Value: string;
154
+ }
155
+ export interface ModifyEnvAuthzConfigOptions {
156
+ key: 'authz.user.rego';
157
+ value: string;
158
+ }
159
+ export interface ModifyEnvAuthzConfigResp {
160
+ AffectedRows: number;
161
+ }