Skip to content

Commit 354c4c2

Browse files
committed
fix(apigw): support base64 encode
1 parent b76b768 commit 354c4c2

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

__tests__/apigw.test.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('apigw', () => {
1616
netTypes: ['OUTER'],
1717
// customDomains: [
1818
// {
19-
// domain: 'test.yugasun.com',
19+
// domain: 'test.yuga.chat',
2020
// // TODO: change to your certId
2121
// certificateId: 'cWOJJjax',
2222
// isDefaultMapping: false,
@@ -27,6 +27,7 @@ describe('apigw', () => {
2727
// },
2828
// ],
2929
// protocols: ['http', 'https'],
30+
// isForcedHttps: true
3031
// },
3132
// ],
3233
usagePlan: {
@@ -48,6 +49,18 @@ describe('apigw', () => {
4849
function: {
4950
functionName: 'serverless-unit-test',
5051
},
52+
isBase64Encoded: true,
53+
isBase64Trigger: true,
54+
base64EncodedTriggerRules: [
55+
{
56+
name: 'Accept',
57+
value: ['application/x-vpeg005', 'application/xhtml+xml'],
58+
},
59+
{
60+
name: 'Content_Type',
61+
value: ['application/x-vpeg005', 'application/xhtml+xml'],
62+
},
63+
],
5164
},
5265
{
5366
path: '/mo',
@@ -162,6 +175,7 @@ describe('apigw', () => {
162175
created: true,
163176
authType: 'NONE',
164177
businessType: 'NORMAL',
178+
isBase64Encoded: true,
165179
},
166180
{
167181
path: '/mo',
@@ -172,6 +186,7 @@ describe('apigw', () => {
172186
created: true,
173187
authType: 'NONE',
174188
businessType: 'NORMAL',
189+
isBase64Encoded: false,
175190
},
176191
{
177192
path: '/auto',
@@ -182,6 +197,7 @@ describe('apigw', () => {
182197
created: true,
183198
authType: 'NONE',
184199
businessType: 'NORMAL',
200+
isBase64Encoded: false,
185201
},
186202
{
187203
path: '/ws',
@@ -192,6 +208,7 @@ describe('apigw', () => {
192208
created: true,
193209
authType: 'NONE',
194210
businessType: 'NORMAL',
211+
isBase64Encoded: false,
195212
},
196213
{
197214
path: '/wsf',
@@ -204,6 +221,7 @@ describe('apigw', () => {
204221
created: true,
205222
authType: 'NONE',
206223
businessType: 'NORMAL',
224+
isBase64Encoded: false,
207225
},
208226
{
209227
path: '/oauth',
@@ -214,6 +232,7 @@ describe('apigw', () => {
214232
authType: 'OAUTH',
215233
businessType: 'OAUTH',
216234
internalDomain: expect.any(String),
235+
isBase64Encoded: false,
217236
},
218237
{
219238
path: '/oauthwork',
@@ -225,6 +244,7 @@ describe('apigw', () => {
225244
businessType: 'NORMAL',
226245
authRelationApiId: expect.stringContaining('api-'),
227246
internalDomain: expect.any(String),
247+
isBase64Encoded: false,
228248
},
229249
],
230250
});
@@ -273,6 +293,7 @@ describe('apigw', () => {
273293
},
274294
usagePlanId: expect.stringContaining('usagePlan-'),
275295
},
296+
isBase64Encoded: true,
276297
},
277298
{
278299
path: '/mo',
@@ -283,6 +304,7 @@ describe('apigw', () => {
283304
created: true,
284305
authType: 'NONE',
285306
businessType: 'NORMAL',
307+
isBase64Encoded: false,
286308
},
287309
{
288310
path: '/auto',
@@ -293,6 +315,7 @@ describe('apigw', () => {
293315
created: true,
294316
authType: 'NONE',
295317
businessType: 'NORMAL',
318+
isBase64Encoded: false,
296319
},
297320
{
298321
path: '/ws',
@@ -303,6 +326,7 @@ describe('apigw', () => {
303326
authType: 'NONE',
304327
businessType: 'NORMAL',
305328
created: true,
329+
isBase64Encoded: false,
306330
},
307331
{
308332
path: '/wsf',
@@ -315,6 +339,7 @@ describe('apigw', () => {
315339
authType: 'NONE',
316340
businessType: 'NORMAL',
317341
created: true,
342+
isBase64Encoded: false,
318343
},
319344
{
320345
path: '/oauth',
@@ -325,6 +350,7 @@ describe('apigw', () => {
325350
authType: 'OAUTH',
326351
businessType: 'OAUTH',
327352
internalDomain: expect.any(String),
353+
isBase64Encoded: false,
328354
},
329355
{
330356
path: '/oauthwork',
@@ -336,6 +362,7 @@ describe('apigw', () => {
336362
businessType: 'NORMAL',
337363
authRelationApiId: expect.stringContaining('api-'),
338364
internalDomain: expect.any(String),
365+
isBase64Encoded: false,
339366
},
340367
],
341368
});

__tests__/scf.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('Scf', () => {
5353
cls: {
5454
cls: {
5555
parameters: {
56-
topicId: '31d3ce01-228b-42f5-aab5-7f740cc2fb11',
56+
topicId: '6e60b6c7-a98e-4fc8-8ba8-bdfe4ab9c245',
5757
qualifier: '$DEFAULT',
5858
maxWait: 60,
5959
maxSize: 100,

src/modules/apigw/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ class Apigw {
595595
created: true,
596596
authType: authType,
597597
businessType: businessType,
598+
isBase64Encoded: endpoint.isBase64Encoded === true,
598599
};
599600

600601
const apiInputs = {
@@ -613,6 +614,7 @@ class Apigw {
613614
serviceTimeout: endpoint.serviceTimeout || 15,
614615
responseType: endpoint.responseType || 'HTML',
615616
enableCORS: endpoint.enableCORS === true,
617+
isBase64Encoded: endpoint.isBase64Encoded === true,
616618
};
617619
if (endpoint.oauthConfig) {
618620
apiInputs.oauthConfig = endpoint.oauthConfig;
@@ -641,6 +643,11 @@ class Apigw {
641643
console.log(`Api method ${endpoint.method}, path ${endpoint.path} already exist`);
642644
endpoint.apiId = apiDetail.ApiId;
643645

646+
if (endpoint.isBase64Encoded && endpoint.isBase64Trigger) {
647+
apiInputs.isBase64Trigger = endpoint.isBase64Trigger;
648+
apiInputs.base64EncodedTriggerRules = endpoint.base64EncodedTriggerRules;
649+
}
650+
644651
await this.request({
645652
Action: 'ModifyApi',
646653
apiId: endpoint.apiId,
@@ -666,6 +673,17 @@ class Apigw {
666673
apiId: output.apiId,
667674
});
668675
output.internalDomain = apiDetail.InternalDomain || '';
676+
677+
if (endpoint.isBase64Encoded && endpoint.isBase64Trigger) {
678+
apiInputs.isBase64Trigger = endpoint.isBase64Trigger;
679+
apiInputs.base64EncodedTriggerRules = endpoint.base64EncodedTriggerRules;
680+
}
681+
682+
await this.request({
683+
Action: 'ModifyApi',
684+
apiId: ApiId,
685+
...apiInputs,
686+
});
669687
}
670688

671689
output.apiName = apiInputs.apiName;

0 commit comments

Comments
 (0)