Skip to content

Commit

Permalink
chore: updated to object for settings parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jens-peterolsson committed Mar 25, 2020
1 parent 909747c commit 8aed996
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mhlabs/lambda-local",
"version": "1.1.1",
"version": "2.0.0",
"description": "A package for mapping AWS env to local env",
"main": "index.js",
"jest": {
Expand Down
22 changes: 12 additions & 10 deletions src/lambdaEnvironment.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
const aws = require('aws-sdk');
const ssoAuth = require('@mhlabs/aws-sso-client-auth');

async function mapToLocal(
stackName,
region = 'eu-west-1',
apiProxyLogicalId = 'ApiProxy',
ssoStartUrl = null,
ssoAccountId = null,
ssoRole = null
) {
async function mapToLocal(settings) {
const {
region = 'eu-west-1',
apiProxyLogicalId = 'ApiProxy',
stackName = null,
ssoStartUrl = null,
ssoAccountId = null,
ssoRole = null
} = settings;

process.env.AWS_DEFAULT_REGION = region;
process.env.AWS_REGION = region;

if (ssoStartUrl) {
await ssoAuth.configure({
clientName: 'evb-cli',
clientName: stackName,
startUrl: ssoStartUrl,
accountId: ssoAccountId,
region: region
region
});

aws.config.update({
Expand Down
2 changes: 1 addition & 1 deletion src/lambdaEnvironment.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const tested = require('./lambdaEnvironment');

test('Should map env variables', async () => {
await tested.mapToLocal('virtual-test-stack');
await tested.mapToLocal({ stackName: 'virtual-test-stack' });
expect(process.env.AWS_REGION).toBe('eu-west-1');
expect(process.env.AWS_DEFAULT_REGION).toBe('eu-west-1');
expect(process.env.CODE_LIMIT).toBe('5');
Expand Down

0 comments on commit 8aed996

Please sign in to comment.