@cloudbase/manager-node 4.2.0 → 4.2.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/CHANGELOG.md +0 -4
- package/lib/constant.js +1 -5
- package/lib/env/index.js +209 -10
- package/lib/function/index.js +21 -3
- package/lib/storage/index.js +3 -19
- package/lib/utils/cloud-api-request.js +0 -7
- package/lib/utils/http-request.js +3 -3
- package/package.json +3 -4
- package/src/access/index.ts +168 -0
- package/src/access/types.ts +55 -0
- package/src/billing/index.ts +43 -0
- package/src/cam/index.ts +106 -0
- package/src/cloudBaseRun/index.ts +40 -0
- package/src/cloudBaseRun/types.ts +24 -0
- package/src/common/index.ts +54 -0
- package/src/constant.ts +56 -0
- package/src/context.ts +18 -0
- package/src/database/index.ts +369 -0
- package/src/debug.ts +34 -0
- package/src/env/index.ts +614 -0
- package/src/environment.ts +156 -0
- package/src/environmentManager.ts +50 -0
- package/src/error.ts +27 -0
- package/src/function/index.ts +1378 -0
- package/src/function/packer.ts +164 -0
- package/src/function/types.ts +165 -0
- package/src/hosting/index.ts +698 -0
- package/src/index.ts +127 -0
- package/src/interfaces/base.interface.ts +8 -0
- package/src/interfaces/billing.interface.ts +21 -0
- package/src/interfaces/cam.interface.ts +28 -0
- package/src/interfaces/flexdb.interface.ts +104 -0
- package/src/interfaces/function.interface.ts +75 -0
- package/src/interfaces/index.ts +7 -0
- package/src/interfaces/storage.interface.ts +29 -0
- package/src/interfaces/tcb.interface.ts +642 -0
- package/src/storage/index.ts +1281 -0
- package/src/third/index.ts +24 -0
- package/src/user/index.ts +174 -0
- package/src/user/types.ts +21 -0
- package/src/utils/auth.ts +112 -0
- package/src/utils/cloud-api-request.ts +252 -0
- package/src/utils/cloudbase-request.ts +109 -0
- package/src/utils/envLazy.ts +15 -0
- package/src/utils/fs.ts +57 -0
- package/src/utils/http-request.ts +37 -0
- package/src/utils/index.ts +103 -0
- package/src/utils/parallel.ts +82 -0
- package/src/utils/uuid.ts +14 -0
- package/types/constant.d.ts +0 -7
- package/types/env/index.d.ts +17 -0
- package/types/function/index.d.ts +6 -1
- package/types/function/types.d.ts +2 -0
- package/types/interfaces/tcb.interface.d.ts +6 -0
- package/lib/utils/runenv.js +0 -8
- package/types/utils/runenv.d.ts +0 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { DatabaseService } from './database'
|
|
2
|
+
import { FunctionService } from './function'
|
|
3
|
+
import { StorageService } from './storage'
|
|
4
|
+
|
|
5
|
+
import { EnvService } from './env'
|
|
6
|
+
import { CommonService } from './common'
|
|
7
|
+
|
|
8
|
+
import { CloudBaseContext } from './context'
|
|
9
|
+
import { CloudBaseError } from './error'
|
|
10
|
+
import { RUN_ENV, ENV_NAME, ERROR } from './constant'
|
|
11
|
+
import { getRuntime, getEnvVar } from './utils'
|
|
12
|
+
import { HostingService } from './hosting'
|
|
13
|
+
import { ThirdService } from './third'
|
|
14
|
+
import { AccessService } from './access'
|
|
15
|
+
import { UserService } from './user'
|
|
16
|
+
import { CloudBaseRunService } from './cloudBaseRun'
|
|
17
|
+
import { EnvInfo } from './interfaces'
|
|
18
|
+
|
|
19
|
+
export class Environment {
|
|
20
|
+
public inited = false
|
|
21
|
+
public cloudBaseContext: CloudBaseContext
|
|
22
|
+
public lazyEnvironmentConfig: EnvInfo
|
|
23
|
+
private envId: string
|
|
24
|
+
private envType?: string
|
|
25
|
+
|
|
26
|
+
private functionService: FunctionService
|
|
27
|
+
private databaseService: DatabaseService
|
|
28
|
+
private storageService: StorageService
|
|
29
|
+
private envService: EnvService
|
|
30
|
+
private hostingService: HostingService
|
|
31
|
+
private thirdService: ThirdService
|
|
32
|
+
private accessService: AccessService
|
|
33
|
+
private userService: UserService
|
|
34
|
+
private cloudBaseRunService: CloudBaseRunService
|
|
35
|
+
|
|
36
|
+
constructor(context: CloudBaseContext, envId: string) {
|
|
37
|
+
this.envId = envId
|
|
38
|
+
this.cloudBaseContext = context
|
|
39
|
+
this.envType = context.envType
|
|
40
|
+
|
|
41
|
+
// 拉取当前环境 的环境信息 todo
|
|
42
|
+
this.functionService = new FunctionService(this)
|
|
43
|
+
this.databaseService = new DatabaseService(this)
|
|
44
|
+
this.storageService = new StorageService(this)
|
|
45
|
+
this.envService = new EnvService(this)
|
|
46
|
+
this.hostingService = new HostingService(this)
|
|
47
|
+
this.thirdService = new ThirdService(this)
|
|
48
|
+
this.accessService = new AccessService(this)
|
|
49
|
+
this.userService = new UserService(this)
|
|
50
|
+
this.cloudBaseRunService = new CloudBaseRunService(this)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async lazyInit(): Promise<any> {
|
|
54
|
+
if (!this.inited) {
|
|
55
|
+
const envConfig = this.envService
|
|
56
|
+
return envConfig.getEnvInfo().then(envInfo => {
|
|
57
|
+
this.lazyEnvironmentConfig = envInfo.EnvInfo
|
|
58
|
+
if (!this.lazyEnvironmentConfig.EnvId) {
|
|
59
|
+
throw new CloudBaseError(`Environment ${this.envId} not found`)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.inited = true
|
|
63
|
+
return this.lazyEnvironmentConfig
|
|
64
|
+
})
|
|
65
|
+
} else {
|
|
66
|
+
return this.lazyEnvironmentConfig
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public getEnvId(): string {
|
|
71
|
+
return this.envId
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public getEnvType(): string {
|
|
75
|
+
return this.envType
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public getStorageService(): StorageService {
|
|
79
|
+
return this.storageService
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public getDatabaseService(): DatabaseService {
|
|
83
|
+
return this.databaseService
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public getFunctionService(): FunctionService {
|
|
87
|
+
return this.functionService
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public getEnvService(): EnvService {
|
|
91
|
+
return this.envService
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public getHostingService(): HostingService {
|
|
95
|
+
return this.hostingService
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public getThirdService(): ThirdService {
|
|
99
|
+
return this.thirdService
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public getAccessService(): AccessService {
|
|
103
|
+
return this.accessService
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public getUserService(): UserService {
|
|
107
|
+
return this.userService
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public getCloudBaseRunService(): CloudBaseRunService {
|
|
111
|
+
return this.cloudBaseRunService
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public getCommonService(serviceType = 'tcb', serviceVersion): CommonService {
|
|
115
|
+
return new CommonService(this, serviceType, serviceVersion)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public getServicesEnvInfo(): Promise<any> {
|
|
119
|
+
const envConfig = this.envService
|
|
120
|
+
return envConfig.getEnvInfo().then(envInfo => {
|
|
121
|
+
return envInfo.EnvInfo
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public getAuthConfig() {
|
|
126
|
+
let { secretId, secretKey, token, proxy, region } = this.cloudBaseContext
|
|
127
|
+
const envId = this.getEnvId()
|
|
128
|
+
|
|
129
|
+
if (!secretId || !secretKey) {
|
|
130
|
+
// 未主动传入密钥,从环境变量中读取
|
|
131
|
+
const envSecretId = getEnvVar(ENV_NAME.ENV_SECRETID)
|
|
132
|
+
const envSecretKey = getEnvVar(ENV_NAME.ENV_SECRETKEY)
|
|
133
|
+
const envToken = getEnvVar(ENV_NAME.ENV_SESSIONTOKEN)
|
|
134
|
+
if (!envSecretId || !envSecretKey) {
|
|
135
|
+
if (getRuntime() === RUN_ENV.SCF) {
|
|
136
|
+
throw new Error('missing authoration key, redeploy the function')
|
|
137
|
+
} else {
|
|
138
|
+
throw new Error('missing secretId or secretKey of tencent cloud')
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
secretId = envSecretId
|
|
142
|
+
secretKey = envSecretKey
|
|
143
|
+
token = envToken
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
envId,
|
|
149
|
+
secretId,
|
|
150
|
+
secretKey,
|
|
151
|
+
token,
|
|
152
|
+
proxy,
|
|
153
|
+
region
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Environment } from './environment'
|
|
2
|
+
import { ERROR } from './constant'
|
|
3
|
+
import { CloudBaseContext } from './context'
|
|
4
|
+
|
|
5
|
+
export class EnvironmentManager {
|
|
6
|
+
private cloudBaseContext: CloudBaseContext
|
|
7
|
+
|
|
8
|
+
private envs: object = {}
|
|
9
|
+
|
|
10
|
+
private currentEnv: Environment = null
|
|
11
|
+
|
|
12
|
+
constructor(context: CloudBaseContext) {
|
|
13
|
+
this.cloudBaseContext = context
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public getCurrentEnv(): Environment {
|
|
17
|
+
if (!this.currentEnv) {
|
|
18
|
+
throw new Error(ERROR.CURRENT_ENVIRONMENT_IS_NULL)
|
|
19
|
+
}
|
|
20
|
+
return this.currentEnv
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public add(envId: string): void {
|
|
24
|
+
if (!this.envs[envId]) {
|
|
25
|
+
this.envs[envId] = new Environment(this.cloudBaseContext, envId)
|
|
26
|
+
}
|
|
27
|
+
if (!this.currentEnv) {
|
|
28
|
+
this.currentEnv = this.envs[envId]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public remove(envId: string): void {
|
|
33
|
+
this.envs[envId] = null
|
|
34
|
+
delete this.envs[envId]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public get(envId: string): Environment | null {
|
|
38
|
+
return this.envs[envId] || null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public switchEnv(envId: string): boolean {
|
|
42
|
+
const env = this.envs[envId]
|
|
43
|
+
if (env) {
|
|
44
|
+
this.currentEnv = env
|
|
45
|
+
return true
|
|
46
|
+
} else {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
exit?: number
|
|
3
|
+
original?: Error | undefined
|
|
4
|
+
code?: string | number
|
|
5
|
+
requestId?: string
|
|
6
|
+
action?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class CloudBaseError extends Error {
|
|
10
|
+
readonly exit: number
|
|
11
|
+
readonly message: string
|
|
12
|
+
readonly name = 'CloudBaseError'
|
|
13
|
+
readonly original: Error | undefined
|
|
14
|
+
readonly code: string | number
|
|
15
|
+
readonly requestId: string
|
|
16
|
+
readonly action: string
|
|
17
|
+
|
|
18
|
+
constructor(message: string, options: Options = {}) {
|
|
19
|
+
super()
|
|
20
|
+
const { code = '', action = '', original = null, requestId = '' } = options
|
|
21
|
+
this.message = action ? `[${action}] ${message}` : message
|
|
22
|
+
this.original = original
|
|
23
|
+
this.code = code
|
|
24
|
+
this.requestId = requestId
|
|
25
|
+
this.action = action
|
|
26
|
+
}
|
|
27
|
+
}
|