@cloudbase/manager-node 4.1.0 → 4.1.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/.vscode/settings.json +3 -0
- package/lib/constant.js +5 -1
- package/lib/env/index.js +9 -3
- package/lib/storage/index.js +9 -3
- package/lib/utils/cloud-api-request.js +2 -3
- package/package.json +3 -2
- package/types/constant.d.ts +6 -0
- package/src/access/index.ts +0 -168
- package/src/access/types.ts +0 -55
- package/src/billing/index.ts +0 -43
- package/src/cam/index.ts +0 -106
- package/src/cloudBaseRun/index.ts +0 -40
- package/src/cloudBaseRun/types.ts +0 -24
- package/src/common/index.ts +0 -54
- package/src/constant.ts +0 -56
- package/src/context.ts +0 -18
- package/src/database/index.ts +0 -369
- package/src/debug.ts +0 -34
- package/src/env/index.ts +0 -362
- package/src/environment.ts +0 -156
- package/src/environmentManager.ts +0 -50
- package/src/error.ts +0 -27
- package/src/function/index.ts +0 -1338
- package/src/function/packer.ts +0 -164
- package/src/function/types.ts +0 -164
- package/src/hosting/index.ts +0 -698
- package/src/index.ts +0 -127
- package/src/interfaces/base.interface.ts +0 -8
- package/src/interfaces/billing.interface.ts +0 -21
- package/src/interfaces/cam.interface.ts +0 -28
- package/src/interfaces/flexdb.interface.ts +0 -104
- package/src/interfaces/function.interface.ts +0 -75
- package/src/interfaces/index.ts +0 -7
- package/src/interfaces/storage.interface.ts +0 -29
- package/src/interfaces/tcb.interface.ts +0 -636
- package/src/storage/index.ts +0 -1281
- package/src/third/index.ts +0 -24
- package/src/user/index.ts +0 -174
- package/src/user/types.ts +0 -21
- package/src/utils/auth.ts +0 -112
- package/src/utils/cloud-api-request.ts +0 -264
- package/src/utils/cloudbase-request.ts +0 -109
- package/src/utils/envLazy.ts +0 -15
- package/src/utils/fs.ts +0 -57
- package/src/utils/http-request.ts +0 -37
- package/src/utils/index.ts +0 -103
- package/src/utils/parallel.ts +0 -82
- package/src/utils/uuid.ts +0 -14
package/lib/constant.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// static credentail = 'credential'
|
|
5
5
|
// }
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
|
|
7
|
+
exports.COS_SDK_PROTOCOL = exports.USE_INTERNAL_ENDPOINT = exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
|
|
8
8
|
exports.ENV_NAME = {
|
|
9
9
|
ENV_SECRETID: 'TENCENTCLOUD_SECRETID',
|
|
10
10
|
ENV_SECRETKEY: 'TENCENTCLOUD_SECRETKEY',
|
|
@@ -49,3 +49,7 @@ exports.SCF_STATUS = {
|
|
|
49
49
|
UPDATING: 'Updating',
|
|
50
50
|
CREATE_FAILED: 'CreateFailed'
|
|
51
51
|
};
|
|
52
|
+
// 是否使用内网域名
|
|
53
|
+
exports.USE_INTERNAL_ENDPOINT = "USE_INTERNAL_ENDPOINT" in process.env;
|
|
54
|
+
// 允许通过环境变量指定 COS SDK 的协议为 HTTPS 或 HTTP
|
|
55
|
+
exports.COS_SDK_PROTOCOL = "COS_SDK_PROTOCOL";
|
package/lib/env/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
|
14
14
|
const util_1 = __importDefault(require("util"));
|
|
15
15
|
const error_1 = require("../error");
|
|
16
16
|
const utils_1 = require("../utils");
|
|
17
|
+
const constant_1 = require("../constant");
|
|
17
18
|
class EnvService {
|
|
18
19
|
constructor(environment) {
|
|
19
20
|
this.environment = environment;
|
|
@@ -254,11 +255,16 @@ class EnvService {
|
|
|
254
255
|
}
|
|
255
256
|
getCos() {
|
|
256
257
|
const { secretId, secretKey, token } = this.environment.getAuthConfig();
|
|
257
|
-
|
|
258
|
+
const cosConfig = {
|
|
258
259
|
SecretId: secretId,
|
|
259
260
|
SecretKey: secretKey,
|
|
260
|
-
SecurityToken: token
|
|
261
|
-
|
|
261
|
+
SecurityToken: token,
|
|
262
|
+
Domain: constant_1.USE_INTERNAL_ENDPOINT ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* PUBLIC */
|
|
263
|
+
};
|
|
264
|
+
if (constant_1.COS_SDK_PROTOCOL in process.env && process.env.COS_SDK_PROTOCOL.toLowerCase().startsWith('http')) {
|
|
265
|
+
cosConfig.Protocol = process.env.COS_SDK_PROTOCOL.toLowerCase() + ":";
|
|
266
|
+
}
|
|
267
|
+
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
|
262
268
|
}
|
|
263
269
|
getStorageConfig() {
|
|
264
270
|
var _a;
|
package/lib/storage/index.js
CHANGED
|
@@ -20,6 +20,7 @@ const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
|
20
20
|
const utils_1 = require("../utils");
|
|
21
21
|
const error_1 = require("../error");
|
|
22
22
|
const parallel_1 = require("../utils/parallel");
|
|
23
|
+
const constant_1 = require("../constant");
|
|
23
24
|
const BIG_FILE_SIZE = 5242880; // 5MB 1024*1024*5
|
|
24
25
|
class StorageService {
|
|
25
26
|
constructor(environment) {
|
|
@@ -839,13 +840,18 @@ class StorageService {
|
|
|
839
840
|
getCos(parallel = 20) {
|
|
840
841
|
const { secretId, secretKey, token, proxy } = this.environment.getAuthConfig();
|
|
841
842
|
const cosProxy = process.env.TCB_COS_PROXY;
|
|
842
|
-
|
|
843
|
+
const cosConfig = {
|
|
843
844
|
FileParallelLimit: parallel,
|
|
844
845
|
SecretId: secretId,
|
|
845
846
|
SecretKey: secretKey,
|
|
846
847
|
Proxy: cosProxy || proxy,
|
|
847
|
-
SecurityToken: token
|
|
848
|
-
|
|
848
|
+
SecurityToken: token,
|
|
849
|
+
Domain: constant_1.USE_INTERNAL_ENDPOINT ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* PUBLIC */
|
|
850
|
+
};
|
|
851
|
+
if (constant_1.COS_SDK_PROTOCOL in process.env && process.env.COS_SDK_PROTOCOL.toLowerCase().startsWith('http')) {
|
|
852
|
+
cosConfig.Protocol = process.env.COS_SDK_PROTOCOL.toLowerCase() + ":";
|
|
853
|
+
}
|
|
854
|
+
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
|
849
855
|
}
|
|
850
856
|
/**
|
|
851
857
|
* 将 cloudPath 转换成 cloudPath/ 形式
|
|
@@ -70,12 +70,11 @@ class CloudService {
|
|
|
70
70
|
cam: 'https://cam.tencentcloudapi.com',
|
|
71
71
|
cdn: 'https://cdn.tencentcloudapi.com'
|
|
72
72
|
};
|
|
73
|
-
//
|
|
74
|
-
const USE_INTERNAL_ENDPOINT = "USE_INTERNAL_ENDPOINT";
|
|
73
|
+
// 云梯账号走内网域名
|
|
75
74
|
const intranetUrlMap = Object.keys(urlMap).map((service) => ({
|
|
76
75
|
[service]: `https://${service}.internal.tencentcloudapi.com`,
|
|
77
76
|
})).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
|
|
78
|
-
if (USE_INTERNAL_ENDPOINT
|
|
77
|
+
if (constant_1.USE_INTERNAL_ENDPOINT) {
|
|
79
78
|
return intranetUrlMap[this.service];
|
|
80
79
|
}
|
|
81
80
|
if (urlMap[this.service]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/manager-node",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "The node manage service api for cloudbase.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"test": "jest --runInBand --detectOpenHandles --coverage --testTimeout=50000",
|
|
9
9
|
"lint": "eslint \"./**/*.ts\"",
|
|
10
10
|
"lint:fix": "eslint --fix \"./**/*.ts\"",
|
|
11
|
-
"prepublishOnly": "npm run build"
|
|
11
|
+
"prepublishOnly": "npm run build",
|
|
12
|
+
"watch": "rimraf lib types && tsc -w"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
package/types/constant.d.ts
CHANGED
|
@@ -35,3 +35,9 @@ export declare const SCF_STATUS: {
|
|
|
35
35
|
UPDATING: string;
|
|
36
36
|
CREATE_FAILED: string;
|
|
37
37
|
};
|
|
38
|
+
export declare const USE_INTERNAL_ENDPOINT: boolean;
|
|
39
|
+
export declare const enum COS_ENDPOINT {
|
|
40
|
+
INTERNAL = "{Bucket}.cos-internal.{Region}.tencentcos.cn",
|
|
41
|
+
PUBLIC = "{Bucket}.cos.{Region}.tencentcos.cn"
|
|
42
|
+
}
|
|
43
|
+
export declare const COS_SDK_PROTOCOL = "COS_SDK_PROTOCOL";
|
package/src/access/index.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { Environment } from '../environment'
|
|
2
|
-
import { CloudService, preLazy } from '../utils'
|
|
3
|
-
import {
|
|
4
|
-
ICreateAccessOptions,
|
|
5
|
-
IApi,
|
|
6
|
-
IUpdateOptions,
|
|
7
|
-
IService,
|
|
8
|
-
IDeleteOptions,
|
|
9
|
-
IGetOptions,
|
|
10
|
-
IDomainOptions
|
|
11
|
-
} from './types'
|
|
12
|
-
import { IResponseInfo } from '../interfaces'
|
|
13
|
-
|
|
14
|
-
export class AccessService {
|
|
15
|
-
private tcbService: CloudService
|
|
16
|
-
private environment: Environment
|
|
17
|
-
|
|
18
|
-
constructor(environment: Environment) {
|
|
19
|
-
this.environment = environment
|
|
20
|
-
this.tcbService = new CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// 创建云接入路径
|
|
24
|
-
@preLazy()
|
|
25
|
-
public async createAccess(options: ICreateAccessOptions) {
|
|
26
|
-
const { path, name, type = 1, auth } = options
|
|
27
|
-
const { envId } = this.getEnvInfo()
|
|
28
|
-
|
|
29
|
-
return this.tcbService.request<{
|
|
30
|
-
APIId: string
|
|
31
|
-
RequestId: string
|
|
32
|
-
}>('CreateCloudBaseGWAPI', {
|
|
33
|
-
ServiceId: envId,
|
|
34
|
-
Path: path,
|
|
35
|
-
Type: type,
|
|
36
|
-
Name: name,
|
|
37
|
-
AuthSwitch: auth ? 1 : 2
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 获取云接入自定义域名列表
|
|
42
|
-
@preLazy()
|
|
43
|
-
public async getDomainList() {
|
|
44
|
-
const { envId } = this.getEnvInfo()
|
|
45
|
-
return this.tcbService.request<{
|
|
46
|
-
RequestId: string
|
|
47
|
-
// 云接入默认域名
|
|
48
|
-
DefaultDomain: string
|
|
49
|
-
// 是否开启了云接入服务
|
|
50
|
-
EnableService: boolean
|
|
51
|
-
// 云接入服务列表
|
|
52
|
-
ServiceSet: IService[]
|
|
53
|
-
}>('DescribeCloudBaseGWService', {
|
|
54
|
-
ServiceId: envId
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 获取云接入服务列表
|
|
59
|
-
@preLazy()
|
|
60
|
-
public async getAccessList(options: IGetOptions = {}) {
|
|
61
|
-
const { path, name, offset, limit } = options
|
|
62
|
-
const { envId } = this.getEnvInfo()
|
|
63
|
-
|
|
64
|
-
return this.tcbService.request<{
|
|
65
|
-
RequestId: string
|
|
66
|
-
APISet: IApi[]
|
|
67
|
-
Total: number
|
|
68
|
-
Limit: number
|
|
69
|
-
Offset: number
|
|
70
|
-
EnableService: boolean
|
|
71
|
-
}>('DescribeCloudBaseGWAPI', {
|
|
72
|
-
ServiceId: envId,
|
|
73
|
-
Path: path,
|
|
74
|
-
Name: name,
|
|
75
|
-
Offset: offset,
|
|
76
|
-
limit: limit
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 切换云接入服务开关:开启/关闭
|
|
81
|
-
@preLazy()
|
|
82
|
-
public async switchAuth(auth: boolean) {
|
|
83
|
-
const { envId } = this.getEnvInfo()
|
|
84
|
-
return this.tcbService.request<{
|
|
85
|
-
Count: number
|
|
86
|
-
RequestId: string
|
|
87
|
-
}>('ModifyCloudBaseGWPrivilege', {
|
|
88
|
-
ServiceId: envId,
|
|
89
|
-
EnableService: auth,
|
|
90
|
-
Options: [
|
|
91
|
-
{
|
|
92
|
-
Key: 'serviceswitch',
|
|
93
|
-
Value: auth ? 'true' : 'false'
|
|
94
|
-
}
|
|
95
|
-
]
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 更新云接入路径鉴权
|
|
100
|
-
@preLazy()
|
|
101
|
-
public async switchPathAuth(options: IUpdateOptions) {
|
|
102
|
-
const { apiIds, auth } = options
|
|
103
|
-
const { envId } = this.getEnvInfo()
|
|
104
|
-
return this.tcbService.request<{
|
|
105
|
-
Count: number
|
|
106
|
-
RequestId: string
|
|
107
|
-
}>('ModifyCloudBaseGWAPIPrivilegeBatch', {
|
|
108
|
-
ServiceId: envId,
|
|
109
|
-
APIIdSet: apiIds,
|
|
110
|
-
Options: [
|
|
111
|
-
{
|
|
112
|
-
Key: 'authswitch',
|
|
113
|
-
Value: auth ? 'true' : 'false'
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// 删除云接入服务
|
|
120
|
-
@preLazy()
|
|
121
|
-
public async deleteAccess(options: IDeleteOptions) {
|
|
122
|
-
const { name, type = 1, apiId } = options
|
|
123
|
-
const { envId } = this.getEnvInfo()
|
|
124
|
-
|
|
125
|
-
return this.tcbService.request<IResponseInfo>('DeleteCloudBaseGWAPI', {
|
|
126
|
-
ServiceId: envId,
|
|
127
|
-
Name: name,
|
|
128
|
-
Type: type,
|
|
129
|
-
APIId: apiId
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// 添加自定义域名
|
|
134
|
-
@preLazy()
|
|
135
|
-
public async addCustomDomain(options: IDomainOptions) {
|
|
136
|
-
const { domain, certId } = options
|
|
137
|
-
const { envId } = this.getEnvInfo()
|
|
138
|
-
|
|
139
|
-
return this.tcbService.request<IResponseInfo>('BindCloudBaseGWDomain', {
|
|
140
|
-
Domain: domain,
|
|
141
|
-
ServiceId: envId,
|
|
142
|
-
CertId: certId
|
|
143
|
-
})
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 删除自定义域名
|
|
147
|
-
@preLazy()
|
|
148
|
-
public async deleteCustomDomain(domain: string) {
|
|
149
|
-
const { envId } = this.getEnvInfo()
|
|
150
|
-
|
|
151
|
-
return this.tcbService.request<IResponseInfo>('DeleteCloudBaseGWDomain', {
|
|
152
|
-
Domain: domain,
|
|
153
|
-
ServiceId: envId
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private getEnvInfo() {
|
|
158
|
-
const envConfig = this.environment.lazyEnvironmentConfig
|
|
159
|
-
const appId = envConfig.Storages[0]?.AppId
|
|
160
|
-
const { proxy } = this.environment.cloudBaseContext
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
appId,
|
|
164
|
-
proxy,
|
|
165
|
-
envId: envConfig.EnvId
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
package/src/access/types.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export interface ICreateAccessOptions {
|
|
2
|
-
path: string
|
|
3
|
-
// 云函数名或云应用名称
|
|
4
|
-
name: string
|
|
5
|
-
// 1 表示云函数,2 表示云应用
|
|
6
|
-
type?: 1 | 2
|
|
7
|
-
// 鉴权开关
|
|
8
|
-
auth?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface IApi {
|
|
12
|
-
ServiceId: string
|
|
13
|
-
APIId: string
|
|
14
|
-
Path: string
|
|
15
|
-
Type: number
|
|
16
|
-
Name: string
|
|
17
|
-
CreateTime: number
|
|
18
|
-
EnvId: string
|
|
19
|
-
EnableAuth: boolean
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface IUpdateOptions {
|
|
23
|
-
// APIId
|
|
24
|
-
apiIds: string[]
|
|
25
|
-
// true 为开启,false 为关闭
|
|
26
|
-
auth: boolean
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface IService {
|
|
30
|
-
ServiceId: string
|
|
31
|
-
Domain: string
|
|
32
|
-
OpenTime: number
|
|
33
|
-
Status?: number
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface IDeleteOptions {
|
|
37
|
-
name?: string
|
|
38
|
-
type?: number
|
|
39
|
-
apiId?: string
|
|
40
|
-
path?: string
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface IGetOptions {
|
|
44
|
-
path?: string
|
|
45
|
-
name?: string
|
|
46
|
-
limit?: number
|
|
47
|
-
offset?: number
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface IDomainOptions {
|
|
51
|
-
// 域名
|
|
52
|
-
domain: string
|
|
53
|
-
// 腾讯云 SSL 证书 Id
|
|
54
|
-
certId?: string
|
|
55
|
-
}
|
package/src/billing/index.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { CloudService } from '../utils'
|
|
2
|
-
import { CloudBaseContext } from '../context'
|
|
3
|
-
import { IServiceVersion, IGoodItem, IGenerateDealsRes, IPayDealsRes } from '../interfaces'
|
|
4
|
-
|
|
5
|
-
export class BillingService {
|
|
6
|
-
static billServiceVersion: IServiceVersion = {
|
|
7
|
-
service: 'billing',
|
|
8
|
-
version: '2018-07-09'
|
|
9
|
-
}
|
|
10
|
-
private billService: CloudService
|
|
11
|
-
|
|
12
|
-
constructor(context: CloudBaseContext) {
|
|
13
|
-
this.billService = new CloudService(
|
|
14
|
-
context,
|
|
15
|
-
BillingService.billServiceVersion.service,
|
|
16
|
-
BillingService.billServiceVersion.version
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 创建订单
|
|
22
|
-
* @param {Array<IGoodItem>} goods
|
|
23
|
-
* @returns {Promise<IGenerateDealsRes>}
|
|
24
|
-
* @memberof BillingService
|
|
25
|
-
*/
|
|
26
|
-
public async GenerateDeals(goods: Array<IGoodItem>): Promise<IGenerateDealsRes> {
|
|
27
|
-
return this.billService.request<IGenerateDealsRes>('GenerateDeals', {
|
|
28
|
-
Goods: goods
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 支付订单
|
|
34
|
-
* @param {Array<string>} orderIds
|
|
35
|
-
* @returns {Promise<IPayDealsRes>}
|
|
36
|
-
* @memberof BillingService
|
|
37
|
-
*/
|
|
38
|
-
public async PayDeals(orderIds: Array<string>): Promise<IPayDealsRes> {
|
|
39
|
-
return this.billService.request<IPayDealsRes>('PayDeals', {
|
|
40
|
-
OrderIds: orderIds
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/cam/index.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { CloudService } from '../utils'
|
|
2
|
-
import { CloudBaseContext } from '../context'
|
|
3
|
-
import {
|
|
4
|
-
IServiceVersion,
|
|
5
|
-
IRoleListRes,
|
|
6
|
-
ICreateRoleRes,
|
|
7
|
-
IResponseInfo,
|
|
8
|
-
IGetRoleRes
|
|
9
|
-
} from '../interfaces'
|
|
10
|
-
|
|
11
|
-
export class CamService {
|
|
12
|
-
static camServiceVersion: IServiceVersion = {
|
|
13
|
-
service: 'cam',
|
|
14
|
-
version: '2019-01-16'
|
|
15
|
-
}
|
|
16
|
-
private camService: CloudService
|
|
17
|
-
|
|
18
|
-
constructor(context: CloudBaseContext) {
|
|
19
|
-
this.camService = new CloudService(
|
|
20
|
-
context,
|
|
21
|
-
CamService.camServiceVersion.service,
|
|
22
|
-
CamService.camServiceVersion.version
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 查询账户角色列表
|
|
28
|
-
* @param {number} page
|
|
29
|
-
* @param {number} rp
|
|
30
|
-
* @returns {Promise<IRoleListRes>}
|
|
31
|
-
* @memberof CamService
|
|
32
|
-
*/
|
|
33
|
-
public async describeRoleList(page: number, rp: number): Promise<IRoleListRes> {
|
|
34
|
-
return this.camService.request<IRoleListRes>('DescribeRoleList', {
|
|
35
|
-
Page: page,
|
|
36
|
-
Rp: rp
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 获取角色详情
|
|
42
|
-
* @param {string} roleName
|
|
43
|
-
* @returns {Promise<IGetRoleRes>}
|
|
44
|
-
* @memberof CamService
|
|
45
|
-
*/
|
|
46
|
-
public async getRole(roleName: string): Promise<IGetRoleRes> {
|
|
47
|
-
return this.camService.request<IGetRoleRes>('GetRole', {
|
|
48
|
-
RoleName: roleName
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 创建角色
|
|
54
|
-
* @param {{
|
|
55
|
-
* RoleName: string
|
|
56
|
-
* PolicyDocument: string
|
|
57
|
-
* Description: string
|
|
58
|
-
* }} param
|
|
59
|
-
* @returns {Promise<ICreateRoleRes>}
|
|
60
|
-
* @memberof CamService
|
|
61
|
-
*/
|
|
62
|
-
public async createRole(param: {
|
|
63
|
-
RoleName: string
|
|
64
|
-
PolicyDocument: string
|
|
65
|
-
Description: string
|
|
66
|
-
}): Promise<ICreateRoleRes> {
|
|
67
|
-
return this.camService.request<ICreateRoleRes>('CreateRole', param)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 绑定角色策略
|
|
72
|
-
* @param {{
|
|
73
|
-
* PolicyId: number
|
|
74
|
-
* AttachRoleName: string
|
|
75
|
-
* }} param
|
|
76
|
-
* @returns {Promise<IResponseInfo>}
|
|
77
|
-
* @memberof CamService
|
|
78
|
-
*/
|
|
79
|
-
public async attachRolePolicy(param: {
|
|
80
|
-
PolicyId: number
|
|
81
|
-
AttachRoleName: string
|
|
82
|
-
}): Promise<IResponseInfo> {
|
|
83
|
-
return this.camService.request<IResponseInfo>('AttachRolePolicy', param)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public async attachRolePolicies(param: {
|
|
87
|
-
RoleId?: number
|
|
88
|
-
RoleName?: string
|
|
89
|
-
PolicyId?: number[]
|
|
90
|
-
PolicyName?: string[]
|
|
91
|
-
}): Promise<IResponseInfo> {
|
|
92
|
-
return this.camService.request<IResponseInfo>('AttachRolePolicies', param)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 删除角色
|
|
97
|
-
* @param {string} roleName
|
|
98
|
-
* @returns {Promise<IResponseInfo>}
|
|
99
|
-
* @memberof CamService
|
|
100
|
-
*/
|
|
101
|
-
public async deleteRole(roleName: string): Promise<IResponseInfo> {
|
|
102
|
-
return this.camService.request<IResponseInfo>('DeleteRole', {
|
|
103
|
-
RoleName: roleName
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Environment } from '../environment'
|
|
2
|
-
import { CloudService, preLazy, upperCaseObjKey } from '../utils'
|
|
3
|
-
import { IModifyServerFlowOption } from './types'
|
|
4
|
-
import { IResponseInfo } from '../interfaces'
|
|
5
|
-
|
|
6
|
-
export class CloudBaseRunService {
|
|
7
|
-
private tcbService: CloudService
|
|
8
|
-
private environment: Environment
|
|
9
|
-
|
|
10
|
-
constructor(environment: Environment) {
|
|
11
|
-
this.environment = environment
|
|
12
|
-
this.tcbService = new CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// 修改容器内版本流量配置
|
|
16
|
-
@preLazy()
|
|
17
|
-
public async modifyServerFlow(
|
|
18
|
-
options: IModifyServerFlowOption
|
|
19
|
-
): Promise<{
|
|
20
|
-
Result: string // succ代表成功
|
|
21
|
-
RequestId: string // 请求ID
|
|
22
|
-
}> {
|
|
23
|
-
const { envId } = this.getEnvInfo()
|
|
24
|
-
|
|
25
|
-
return this.tcbService.request('ModifyCloudBaseRunServerFlowConf', {
|
|
26
|
-
EnvId: envId,
|
|
27
|
-
ServerName: options.serverName,
|
|
28
|
-
VersionFlowItems: upperCaseObjKey(options.versionFlowItems)
|
|
29
|
-
// TrafficType: options.trafficType
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private getEnvInfo() {
|
|
34
|
-
const envConfig = this.environment.lazyEnvironmentConfig
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
envId: envConfig.EnvId
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export interface IModifyServerFlowOption {
|
|
2
|
-
serverName: string
|
|
3
|
-
versionFlowItems?: ICloudBaseRunVersionFlowItem[]
|
|
4
|
-
trafficType?: string
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface ICloudBaseRunVersionFlowItem {
|
|
8
|
-
versionName: string // 版本名称
|
|
9
|
-
flowRatio: number // 流量占比
|
|
10
|
-
urlParam?: IObjectKV // 流量参数
|
|
11
|
-
priority?: number // 优先级(数值越小,优先级越高)
|
|
12
|
-
isDefaultPriority?: boolean // 是否是默认兜底版本
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface IObjectKV {
|
|
16
|
-
key: string
|
|
17
|
-
value: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface IClouBaseRunKVPriority {
|
|
21
|
-
key: string
|
|
22
|
-
value: string
|
|
23
|
-
priority: number
|
|
24
|
-
}
|
package/src/common/index.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { CloudService, preLazy } from '../utils'
|
|
2
|
-
import { CloudBaseContext } from '../context'
|
|
3
|
-
import { CloudBaseError } from '../error'
|
|
4
|
-
import { Environment } from '../environment'
|
|
5
|
-
|
|
6
|
-
interface ICommonApiServiceOption {
|
|
7
|
-
Action: string // 接口名称
|
|
8
|
-
Param: Record<string, any> // 接口传参
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* 公共的云api调用方法 透传用户参数 无业务逻辑处理
|
|
12
|
-
* @export
|
|
13
|
-
* @class CommonService
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const ActionVersionMap = {
|
|
17
|
-
tcb: '2018-06-08',
|
|
18
|
-
flexdb: '2018-11-27',
|
|
19
|
-
scf: '2018-04-16',
|
|
20
|
-
sts: '2018-04-16',
|
|
21
|
-
cam: '2018-04-16',
|
|
22
|
-
lowcode: '2021-01-08'
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class CommonService {
|
|
26
|
-
private commonService: CloudService
|
|
27
|
-
private environment: Environment
|
|
28
|
-
|
|
29
|
-
constructor(environment: Environment, serviceType: string, serviceVersion: string) {
|
|
30
|
-
this.environment = environment
|
|
31
|
-
this.commonService = new CloudService(
|
|
32
|
-
environment.cloudBaseContext,
|
|
33
|
-
serviceType,
|
|
34
|
-
serviceVersion || ActionVersionMap[serviceType]
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 公共方法调用
|
|
40
|
-
* @param {ICommonApiServiceParam} param
|
|
41
|
-
* @returns {Promise<any>}
|
|
42
|
-
* @memberof CommonService
|
|
43
|
-
*/
|
|
44
|
-
public async call(options: ICommonApiServiceOption): Promise<any> {
|
|
45
|
-
const { Action, Param = {} } = options
|
|
46
|
-
if (!Action) {
|
|
47
|
-
throw new CloudBaseError('缺少必填参数 Action')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const res = await this.commonService.request(Action, { ...Param })
|
|
51
|
-
|
|
52
|
-
return res
|
|
53
|
-
}
|
|
54
|
-
}
|
package/src/constant.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// // cloudbase cli 配置的字段名
|
|
2
|
-
// export class ConfigItems {
|
|
3
|
-
// static credentail = 'credential'
|
|
4
|
-
// }
|
|
5
|
-
|
|
6
|
-
export const ENV_NAME = {
|
|
7
|
-
ENV_SECRETID: 'TENCENTCLOUD_SECRETID',
|
|
8
|
-
ENV_SECRETKEY: 'TENCENTCLOUD_SECRETKEY',
|
|
9
|
-
ENV_SESSIONTOKEN: 'TENCENTCLOUD_SESSIONTOKEN',
|
|
10
|
-
ENV_TCB_ENV_ID: 'TENCENTCLOUD_TCB_ENVID',
|
|
11
|
-
ENV_RUNENV: 'TENCENTCLOUD_RUNENV',
|
|
12
|
-
ENV_RUNENV_SCF: 'TENCENTCLOUD_RUNENV=SCF'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const SDK_VERSION = 'TCB-NODE-MANAGER/1.0.O'
|
|
16
|
-
|
|
17
|
-
export const RUN_ENV = {
|
|
18
|
-
SCF: 'SCF'
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const ENDPOINT = {
|
|
22
|
-
TCB: 'tcb.tencentcloudapi.com',
|
|
23
|
-
SCF: 'scf.tencentcloudapi.com',
|
|
24
|
-
COS: 'cos.tencentcloudapi.com',
|
|
25
|
-
FLEXDB: 'flexdb.tencentcloudapi.com'
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const SERVICE_TYPE = {
|
|
29
|
-
TCB: 'tcb'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const ERROR = {
|
|
33
|
-
MISS_SECRET_INFO_IN_ENV: 'MISS_SECRET_INFO_IN_ENV',
|
|
34
|
-
MISS_SECRET_INFO_IN_ARGS: 'MISS_SECRET_INFO_IN_ARGS',
|
|
35
|
-
CURRENT_ENVIRONMENT_IS_NULL: 'CURRENT_ENVIRONMENT_IS_NULL',
|
|
36
|
-
ENV_ID_NOT_EXISTS: 'ENV_ID_NOT_EXISTS'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const PUBLIC_RSA_KEY = `
|
|
40
|
-
-----BEGIN PUBLIC KEY-----
|
|
41
|
-
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0ZLB0ZpWWFsHPnDDw++Nc2wI3
|
|
42
|
-
nl2uyOrIJ5FUfxt4GAmt1Faf5pgMxAnL9exEUrrUDUX8Ri1R0KyfnHQQwCvKt8T8
|
|
43
|
-
bgILIJe9UB8e9dvFqgqH2oA8Vqwi0YqDcvFLFJk2BJbm/0QYtZ563FumW8LEXAgu
|
|
44
|
-
UeHi/0OZN9vQ33jWMQIDAQAB
|
|
45
|
-
-----END PUBLIC KEY-----
|
|
46
|
-
`
|
|
47
|
-
export const ROLE_NAME = {
|
|
48
|
-
TCB: 'TCB_QcsRole'
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const SCF_STATUS = {
|
|
52
|
-
ACTIVE: 'Active',
|
|
53
|
-
CREATING: 'Creating',
|
|
54
|
-
UPDATING: 'Updating',
|
|
55
|
-
CREATE_FAILED: 'CreateFailed'
|
|
56
|
-
}
|