Skip to content

Commit 0ab5de0

Browse files
committed
fix(asw): remove auto create role feature
1 parent c42d6de commit 0ab5de0

File tree

3 files changed

+21
-58
lines changed

3 files changed

+21
-58
lines changed

__tests__/asw.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ describe('Account', () => {
1313
key: 'value',
1414
});
1515

16+
const roleArn = 'qcs::cam::uin/100015854621:roleName/serverless-test-aws';
17+
1618
const options: {
1719
definition: string;
1820
name: string;
1921
resourceId?: string;
20-
role?: string;
21-
uin: string;
22-
appId: string;
22+
roleArn: string;
2323
input?: string;
2424
} = {
2525
definition: JSON.stringify({
@@ -31,8 +31,7 @@ describe('Account', () => {
3131
},
3232
}),
3333
name: 'serverless-test',
34-
uin: process.env.TENCENT_UIN,
35-
appId: process.env.TENCENT_APP_ID,
34+
roleArn,
3635
input,
3736
};
3837

@@ -44,8 +43,7 @@ describe('Account', () => {
4443
expect(res).toEqual({
4544
requestId: expect.any(String),
4645
resourceId: expect.any(String),
47-
isNewRole: expect.any(Boolean),
48-
roleName: expect.stringContaining('serverless-test_'),
46+
roleArn,
4947
});
5048
createResult = res;
5149
});
@@ -60,13 +58,12 @@ describe('Account', () => {
6058

6159
test('update', async () => {
6260
options.resourceId = createResult.resourceId;
63-
options.role = createResult.roleName;
61+
options.roleArn = createResult.roleArn;
6462
const res = await client.update(options as UpdateOptions);
6563
expect(res).toEqual({
6664
requestId: expect.any(String),
6765
resourceId: createResult.resourceId,
68-
isNewRole: expect.any(Boolean),
69-
roleName: expect.stringContaining('serverless-test_'),
66+
roleArn,
7067
});
7168
});
7269

@@ -102,8 +99,5 @@ describe('Account', () => {
10299
requestId: expect.any(String),
103100
resourceId: createResult.resourceId,
104101
});
105-
106-
// 删除测试创建的角色
107-
await client.cam.DeleteRole(createResult.roleName);
108102
});
109103
});

src/modules/asw/index.ts

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ import {
1717
import APIS, { ActionType } from './apis';
1818
import { pascalCaseProps, randomId } from '../../utils/index';
1919
import { CapiCredentials, RegionType } from '../interface';
20-
import { Account, Cam } from '../../';
20+
import { Cam } from '../../';
2121

2222
export default class Asw {
2323
credentials: CapiCredentials;
2424
capi: Capi;
2525
region: RegionType;
26-
account: Account;
2726
cam: Cam;
2827

2928
constructor(credentials: CapiCredentials, region: RegionType = 'ap-guangzhou') {
@@ -38,8 +37,6 @@ export default class Asw {
3837
Token: this.credentials.Token,
3938
});
4039

41-
this.account = new Account(credentials);
42-
4340
this.cam = new Cam(credentials);
4441
}
4542

@@ -70,8 +67,7 @@ export default class Asw {
7067
const {
7168
definition,
7269
name,
73-
role,
74-
uin,
70+
roleArn,
7571
type = 'STANDARD',
7672
chineseName = 'serverless',
7773
description = 'Created By Serverless',
@@ -82,22 +78,14 @@ export default class Asw {
8278
const reqParams: CreateApiOptions = {
8379
Definition: definition,
8480
FlowServiceName: name,
85-
IsNewRole: !!role,
81+
IsNewRole: false,
8682
Type: type,
8783
FlowServiceChineseName: chineseName,
8884
Description: description,
8985
EnableCLS: enableCls,
86+
RoleResource: roleArn,
9087
};
9188

92-
let roleName = role;
93-
94-
if (!roleName) {
95-
// 如果上层传入 appId 直接使用上层 appId,如果没有尝试通过 accountInfo 中来获取
96-
const { appId } = options;
97-
roleName = await this.createRole(name, appId!);
98-
}
99-
reqParams.RoleResource = `qcs::cam::uin/${uin}:roleName/${roleName}`;
100-
10189
if (input) {
10290
reqParams.Input = input;
10391
}
@@ -109,8 +97,7 @@ export default class Asw {
10997
return {
11098
requestId: RequestId,
11199
resourceId: FlowServiceResource,
112-
isNewRole: reqParams.IsNewRole,
113-
roleName,
100+
roleArn,
114101
};
115102
}
116103

@@ -124,8 +111,7 @@ export default class Asw {
124111
resourceId,
125112
definition,
126113
name,
127-
role,
128-
uin,
114+
roleArn,
129115
type = 'STANDARD',
130116
chineseName = 'serverless',
131117
description = 'Created By Serverless',
@@ -136,23 +122,14 @@ export default class Asw {
136122
FlowServiceResource: resourceId,
137123
Definition: definition,
138124
FlowServiceName: name,
139-
IsNewRole: !role,
125+
IsNewRole: false,
140126
Type: type,
141127
FlowServiceChineseName: chineseName,
142128
Description: description,
143129
EnableCLS: enableCls,
130+
RoleResource: roleArn,
144131
};
145132

146-
let roleName = role;
147-
148-
if (!roleName) {
149-
// 如果上层传入 appId 直接使用上层 appId,如果没有尝试通过 accountInfo 中来获取
150-
const { appId } = options;
151-
roleName = await this.createRole(name, appId!);
152-
}
153-
154-
reqParams.RoleResource = `qcs::cam::uin/${uin}:roleName/${roleName}`;
155-
156133
const { RequestId, FlowServiceResource } = await this.request({
157134
...reqParams,
158135
Action: 'ModifyFlowService',
@@ -161,8 +138,7 @@ export default class Asw {
161138
return {
162139
requestId: RequestId,
163140
resourceId: FlowServiceResource,
164-
isNewRole: reqParams.IsNewRole,
165-
roleName,
141+
roleArn,
166142
};
167143
}
168144

src/modules/asw/interface.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ export interface CreateOptions {
2929
definition: string;
3030
// 状态机服务名称,必须唯一
3131
name: string;
32-
// 用户主账号 UIN
33-
uin: string;
3432
// 是否是新创建角色
3533
isNewRole?: boolean;
3634
// 角色名称
37-
role?: string;
35+
roleArn: string;
3836
// 状态机类型,EXPRESS,STANDARD
3937
type?: string;
4038
// 状态机服务中文名称
@@ -45,9 +43,6 @@ export interface CreateOptions {
4543
enableCls?: boolean;
4644
// 状态机默认输入参数
4745
input?: string;
48-
49-
// app id
50-
appId?: string;
5146
}
5247

5348
export type UpdateOptions = Omit<CreateOptions, 'input'> & {
@@ -63,14 +58,12 @@ export interface BaseResult {
6358
}
6459

6560
export interface CreateResult extends BaseResult {
66-
// 是否是新建角色
67-
isNewRole: boolean;
68-
// 角色名称
69-
roleName: string;
61+
// 角色 arn
62+
roleArn: string;
7063
}
7164
export type UpdateResult = BaseResult & {
72-
isNewRole: boolean;
73-
roleName: string;
65+
// 角色 arn
66+
roleArn: string;
7467
};
7568
export type DeleteResult = BaseResult;
7669

0 commit comments

Comments
 (0)