-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOpenApiClient.js
More file actions
176 lines (159 loc) · 7.07 KB
/
Copy pathOpenApiClient.js
File metadata and controls
176 lines (159 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
10BC0
div>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
const CloudAPI20160714 = require('@alicloud/cloudapi20160714');
const $OpenApi = require('@alicloud/openapi-client');
const $Util = require('@alicloud/tea-util');
const tea = require('@alicloud/tea-typescript');
class OpenApiClient {
/** Endpoint https://api.aliyun.com/product/CloudAPI */
static getEndpoint(regionId = 'cn-shanghai') {
return `apigateway.${regionId}.aliyuncs.com`;
}
/**
* use ak and sk to init a client
* @param regionId
*/
static createClient(regionId) {
// please use security sts way to auth: https://help.aliyun.com/document_detail/378664.html
let config = new $OpenApi.Config({
// AccessKey ID
accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
// AccessKey Secret
accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
});
config.endpoint = OpenApiClient.getEndpoint(regionId);
return new CloudAPI20160714.default(config);
}
static async DescribeApiGroupsRequest(regionId = 'cn-shanghai', pageNumber = 1, pageSize = 50) {
const client = OpenApiClient.createClient(regionId);
const describeApiGroupsRequest = new CloudAPI20160714.DescribeApiGroupsRequest({ pageNumber, pageSize });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.describeApiGroupsWithOptions(describeApiGroupsRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async DescribeDeployedApisRequest(regionId = 'cn-shanghai', apiName, apiPath, pageNumber = 1, pageSize = 10) {
const client = OpenApiClient.createClient(regionId);
const describeDeployedApisRequest = new CloudAPI20160714.DescribeDeployedApisRequest({ apiName, apiPath, pageNumber, pageSize });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.describeDeployedApisWithOptions(describeDeployedApisRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async DescribeApiRequest(regionId = 'cn-shanghai', apiId) {
const client = OpenApiClient.createClient(regionId);
const describeApiRequest = new CloudAPI20160714.DescribeApiRequest({ apiId });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.describeApiWithOptions(describeApiRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async DescribeApisByApp(regionId = 'cn-shanghai', appId, apiName, apiPath, pageNumber = 1, pageSize = 10) {
const client = OpenApiClient.createClient(regionId);
const describeApisByAppRequest = new CloudAPI20160714.DescribeApisByAppRequest({ appId, apiName, apiPath, pageNumber, pageSize });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.describeApisByAppWithOptions(describeApisByAppRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
/** app is cross-site, if appId is empty, return all apps. */
static async DescribeAppAttributesRequest(regionId = 'cn-shanghai', appId, pageNumber = 1, pageSize = 10) {
const client = OpenApiClient.createClient(regionId);
const describeAppAttributesRequest = new CloudAPI20160714.DescribeAppAttributesRequest({ appId, pageNumber, pageSize });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.describeAppAttributesWithOptions(describeAppAttributesRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async DescribeAppSecurityRequest(regionId = 'cn-shanghai', appId) {
const client = OpenApiClient.createClient(regionId);
const describeAppSecurityRequest = new CloudAPI20160714.DescribeAppSecurityRequest({ appId });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.describeAppSecurityWithOptions(describeAppSecurityRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async ResetAppCodeRequest(regionId = 'cn-shanghai', appCode) {
const client = OpenApiClient.createClient(regionId);
const resetAppCodeRequest = new CloudAPI20160714.ResetAppCodeRequest({ appCode });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.resetAppCodeWithOptions(resetAppCodeRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async ResetAppSecretRequest(regionId = 'cn-shanghai', appKey) {
const client = OpenApiClient.createClient(regionId);
const resetAppSecretRequest = new CloudAPI20160714.ResetAppSecretRequest({ appKey });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.resetAppSecretWithOptions(resetAppSecretRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async CreateAppRequest(regionId = 'cn-shanghai', appName) {
const client = OpenApiClient.createClient(regionId);
const createAppRequest = new CloudAPI20160714.CreateAppRequest({ appName });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.createAppWithOptions(createAppRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async DeleteAppRequest(regionId = 'cn-shanghai', appId) {
const client = OpenApiClient.createClient(regionId);
const deleteAppRequest = new CloudAPI20160714.DeleteAppRequest({ appId: Number(appId) });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.deleteAppWithOptions(deleteAppRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async SetApisAuthoritiesRequest(regionId = 'cn-shanghai', appId, groupId, apiIds, stageName = 'RELEASE') {
const client = OpenApiClient.createClient(regionId);
const setApisAuthoritiesRequest = new CloudAPI20160714.SetApisAuthoritiesRequest({ appId: Number(appId), groupId, apiIds: apiIds?.join?.(','), stageName });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.setApisAuthoritiesWithOptions(setApisAuthoritiesRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
static async RemoveApisAuthoritiesRequest(regionId = 'cn-shanghai', appId, groupId, apiIds, stageName = 'RELEASE') {
const client = OpenApiClient.createClient(regionId);
const removeApisAuthoritiesRequest = new CloudAPI20160714.RemoveApisAuthoritiesRequest({ appId: Number(appId), groupId, apiIds: apiIds?.join?.(','), stageName });
const runtime = new $Util.RuntimeOptions({});
try {
return await client.removeApisAuthoritiesWithOptions(removeApisAuthoritiesRequest, runtime);
} catch (error) {
// print error
$Util.default.assertAsString(error.message);
}
}
}
module.exports = OpenApiClient;