Skip to content

Commit f4f748a

Browse files
committed
fix(apigw): support app remove
1 parent c3ea89f commit f4f748a

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

__tests__/apigw/app.test.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { sleep } from '@ygkit/request';
12
import { ApigwDeployInputs, ApigwDeployOutputs } from '../../src/modules/apigw/interface';
23
import { Apigw } from '../../src';
34
import { deepClone } from '../../src/utils';
@@ -7,6 +8,10 @@ describe('apigw app', () => {
78
SecretId: process.env.TENCENT_SECRET_ID,
89
SecretKey: process.env.TENCENT_SECRET_KEY,
910
};
11+
const appConfig = {
12+
name: 'serverless_app_test',
13+
description: 'Created by serverless test',
14+
};
1015
const inputs: ApigwDeployInputs = {
1116
protocols: ['http', 'https'],
1217
serviceName: 'serverless_test',
@@ -19,10 +24,7 @@ describe('apigw app', () => {
1924
method: 'POST',
2025
apiName: 'appauth',
2126
authType: 'APP',
22-
app: {
23-
name: 'serverless_app_test',
24-
description: 'Created by serverless test',
25-
},
27+
app: appConfig,
2628
function: {
2729
functionName: 'serverless-unit-test',
2830
},
@@ -31,7 +33,7 @@ describe('apigw app', () => {
3133
};
3234
const apigw = new Apigw(credentials, process.env.REGION);
3335
let outputs: ApigwDeployOutputs;
34-
36+
let appId: string = '';
3537
// 由于自定义域名必须 ICP 备案,所以这里测试域名不会通过,具体测试请使用
3638
test('create apigw with app auth success', async () => {
3739
const apigwInputs = deepClone(inputs);
@@ -56,6 +58,7 @@ describe('apigw app', () => {
5658
},
5759
},
5860
]);
61+
appId = outputs.apiList[0].app.id;
5962
});
6063

6164
test('update apigw without app auth success', async () => {
@@ -95,4 +98,24 @@ describe('apigw app', () => {
9598

9699
expect(detail).toBeNull();
97100
});
101+
102+
test('get apigw app', async () => {
103+
const { app } = apigw.api;
104+
const exist = await app.get(appId);
105+
expect(exist).toEqual({
106+
id: appId,
107+
name: appConfig.name,
108+
description: expect.any(String),
109+
key: expect.any(String),
110+
secret: expect.any(String),
111+
});
112+
});
113+
114+
test('delete apigw app', async () => {
115+
const { app } = apigw.api;
116+
await app.delete(appId);
117+
await sleep(2000);
118+
const detail = await app.get(appId);
119+
expect(detail).toEqual(undefined);
120+
});
98121
});

src/modules/apigw/apis.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ const ACTIONS = [
3636
'UnBindSubDomain',
3737
'DescribeServicesStatus',
3838
'DescribeServiceEnvironmentList',
39+
'DescribeApiApp',
3940
'CreateApiApp',
41+
'DeleteApiApp',
4042
'ModifyApiApp',
4143
'BindApiApp',
4244
'UnbindApiApp',

src/modules/apigw/entities/application.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiAppCreateOptions } from './../interface';
1+
import { ApiAppCreateOptions, ApiAppItem, ApiAppDetail } from './../interface';
22
import { Capi } from '@tencent-sdk/capi';
33
import APIS, { ActionType } from '../apis';
44
import { pascalCaseProps } from '../../../utils';
@@ -36,6 +36,24 @@ export default class AppEntity {
3636
return true;
3737
}
3838

39+
async get(id: string): Promise<ApiAppDetail | undefined> {
40+
const { ApiAppSet = [] }: { ApiAppSet: ApiAppItem[] } = await this.request({
41+
Action: 'DescribeApiApp',
42+
ApiAppId: id,
43+
});
44+
if (ApiAppSet[0] && ApiAppSet[0].ApiAppId === id) {
45+
const [current] = ApiAppSet;
46+
return {
47+
id,
48+
name: current.ApiAppName,
49+
description: current.ApiAppDesc,
50+
key: current.ApiAppKey,
51+
secret: current.ApiAppSecret,
52+
};
53+
}
54+
return undefined;
55+
}
56+
3957
// bind api to application, if not config app id just create it
4058
async bind({ serviceId, environment, apiId, appConfig }: AppBindOptions) {
4159
// 1. create app
@@ -108,4 +126,13 @@ export default class AppEntity {
108126
description,
109127
};
110128
}
129+
async delete(id: string) {
130+
console.log(`Removing apigw application ${id}`);
131+
await this.removeRequest({
132+
Action: 'DeleteApiApp',
133+
ApiAppId: id,
134+
});
135+
136+
return true;
137+
}
111138
}

src/modules/apigw/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
ApigwDeployOutputs,
1111
ApigwRemoveInputs,
1212
ApigwCreateOrUpdateServiceOutputs,
13-
ApigwUpdateServiceInputs,
1413
ApigwDeployWithServiceIdInputs,
1514
} from './interface';
1615
import { getProtocolString, getUrlProtocol } from './utils';

src/modules/apigw/interface.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,21 @@ export interface ApiAppCreateOptions {
286286
name: string;
287287
description?: string;
288288
}
289+
290+
export interface ApiAppItem {
291+
ApiAppName: string;
292+
ApiAppId: string;
293+
ApiAppKey: string;
294+
ApiAppSecret: string;
295+
CreatedTime: string;
296+
ModifiedTime: string;
297+
ApiAppDesc: string;
298+
}
299+
300+
export interface ApiAppDetail {
301+
id: string;
302+
name: string;
303+
key: string;
304+
secret: string;
305+
description: string;
306+
}

0 commit comments

Comments
 (0)