Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy proxy function automatically (wip) #742

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"mocha-multi-reporters": "1.5.1",
"nock": "13.5.5",
"semantic-release": "24.1.1",
"xml2js": "0.6.2",
"yauzl": "3.1.3"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* governing permissions and limitations under the License.
*/
/* eslint-disable no-console */
// eslint-disable-next-line import/no-unresolved
import { LambdaClient, InvokeCommand, InvocationType } from '@aws-sdk/client-lambda';

/**
Expand All @@ -21,13 +20,11 @@ import { LambdaClient, InvokeCommand, InvocationType } from '@aws-sdk/client-lam
* ANY /helix-services/{action}/{version}
* ANY /helix-services/{action}/{version}/{path+}
*
* ANY /helix-observation/{action}/{version}
* ANY /helix-observation/{action}/{version}/{path+}
*
* Note that the package cannot be a path parameter, as it would clash with the pages proxy
* ANY /helix3/{action}/{version}
* ANY /helix3/{action}/{version}/{path+}
*
* @param event
* @returns {Promise<{body, statusCode}|any>}
* @returns {Promise<{body, headers, statusCode}|any>}
*/
export const handler = async (event) => {
const { action, version } = event.pathParameters;
Expand All @@ -43,14 +40,13 @@ export const handler = async (event) => {
Payload: JSON.stringify(event),
}),
);
const data = JSON.parse(new TextDecoder('utf8').decode(ret.Payload));
console.log(`statusCode: ${data.statusCode}`);
return data;
return JSON.parse(new TextDecoder('utf8').decode(ret.Payload));
} catch (err) {
console.error(err);
return {
statusCode: err.statusCode,
body: err.message,
statusCode: err.$metadata?.httpStatusCode ?? err.statusCode,
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ message: err.message }),
};
}
};
43 changes: 43 additions & 0 deletions test/aws.deployer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@
/* eslint-env mocha */
import assert from 'assert';
import nock from 'nock';
import xml2js from 'xml2js';
import BaseConfig from '../src/BaseConfig.js';
import AWSConfig from '../src/deploy/AWSConfig.js';
import AWSDeployer from '../src/deploy/AWSDeployer.js';
import ActionBuilder from '../src/ActionBuilder.js';

describe('AWS Deployer Test', () => {
beforeEach(() => {
process.env.AWS_ACCESS_KEY_ID = 'fake';
process.env.AWS_SECRET_ACCESS_KEY = 'fake';
process.env.AWS_REGION = 'us-east-1';
Comment on lines +24 to +26
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise leads to errors in tests that invoke GetCallerIdentity (Missing credentials)

});

afterEach(() => {
delete process.env.AWS_ACCESS_KEY_ID;
delete process.env.AWS_SECRET_ACCESS_KEY;
delete process.env.AWS_REGION;
});

it('sets the default lambda name', async () => {
const cfg = new BaseConfig()
.withName('/helix-services/[email protected]');
Expand Down Expand Up @@ -57,6 +70,16 @@ describe('AWS Deployer Test', () => {
});

it('sets the default deploy bucket', async () => {
nock('https://sts.us-east-1.amazonaws.com/')
.post('/')
.reply(() => [200, new xml2js.Builder().buildObject({
GetCallerIdentityResponse: {
GetCallerIdentityResult: {
Account: '118435662149',
},
},
})]);

const cfg = new BaseConfig()
.withVersion('1.18.2')
// eslint-disable-next-line no-template-curly-in-string
Expand All @@ -72,6 +95,16 @@ describe('AWS Deployer Test', () => {
});

it('sets the default deploy bucket with region', async () => {
nock('https://sts.eu-central-1.amazonaws.com/')
.post('/')
.reply(() => [200, new xml2js.Builder().buildObject({
GetCallerIdentityResponse: {
GetCallerIdentityResult: {
Account: '118435662149',
},
},
})]);

const cfg = new BaseConfig()
.withVersion('1.18.2')
// eslint-disable-next-line no-template-curly-in-string
Expand All @@ -86,6 +119,16 @@ describe('AWS Deployer Test', () => {
});

it('sets the custom deploy bucket', async () => {
nock('https://sts.eu-central-1.amazonaws.com/')
.post('/')
.reply(() => [200, new xml2js.Builder().buildObject({
GetCallerIdentityResponse: {
GetCallerIdentityResult: {
Account: '118435662149',
},
},
})]);

const cfg = new BaseConfig()
.withVersion('1.18.2')
// eslint-disable-next-line no-template-curly-in-string
Expand Down
Loading