Skip to content

Commit a07ab13

Browse files
authored
Merge pull request #413 from jgilbert01/enhancement-eem-as-function
Enhancement: eem as function
2 parents 4865661 + 5365fdb commit a07ab13

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aws-lambda-stream",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "Create stream processors with AWS Lambda functions.",
55
"keywords": [
66
"aws",

src/utils/encryption.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ export const encryptData = ({
166166
regions = (process.env.KMS_REGIONS && process.env.KMS_REGIONS.split(',')),
167167
AES = true,
168168
} = {}) => async (data) => {
169+
const eemMetadata = typeof eem === 'function' ? eem(data) : eem;
169170
const result = await encryptObject(data, {
170171
masterKeyAlias,
171172
regions,
172-
...eem, // fields and overrides
173+
...eemMetadata, // fields and overrides
173174
AES,
174175
})
175176
// .tap(debug)

test/unit/utils/encryption.test.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,99 @@ describe('utils/encryption.js', () => {
252252
.done(done);
253253
});
254254

255+
it('should encrypt data - listener function w/ eem as function', (done) => {
256+
const rule1 = {
257+
id: 'e1',
258+
flavor: materialize,
259+
eventType: 'thing-created',
260+
toUpdateRequest: async (uow, rule) => ({
261+
Key: {
262+
pk: uow.event.thing.id,
263+
sk: 'thing',
264+
},
265+
...updateExpression(await rule.encrypt({
266+
...uow.event.thing,
267+
discriminator: 'thing',
268+
timestamp: uow.event.timestamp,
269+
})),
270+
}),
271+
eem: (data) => {
272+
if (data.discriminator === 'thing') {
273+
return {
274+
fields: [
275+
'name',
276+
'description',
277+
],
278+
};
279+
} else {
280+
return {
281+
fields: [],
282+
};
283+
}
284+
},
285+
masterKeyAlias: 'alias/aws-kms-ee',
286+
AES: false,
287+
};
288+
289+
const events = toKinesisRecords([{
290+
id: '0',
291+
type: 'thing-created',
292+
timestamp: 1572832690000,
293+
thing: {
294+
id: '1',
295+
name: 'n1',
296+
description: 'd1',
297+
status: 's1',
298+
},
299+
}]);
300+
301+
initialize({
302+
...initializeFrom([rule1]),
303+
})
304+
.assemble(fromKinesis(events), false)
305+
.collect()
306+
.tap((collected) => {
307+
// console.log(JSON.stringify(collected, null, 2));
308+
expect(collected.length).to.equal(1);
309+
expect(collected[0].updateRequest).to.deep.equal({
310+
Key: {
311+
pk: '1',
312+
sk: 'thing',
313+
},
314+
ExpressionAttributeNames: {
315+
'#id': 'id',
316+
'#name': 'name',
317+
'#description': 'description',
318+
'#status': 'status',
319+
'#discriminator': 'discriminator',
320+
'#timestamp': 'timestamp',
321+
'#eem': 'eem',
322+
},
323+
ExpressionAttributeValues: {
324+
':id': '1',
325+
':name': 'Im4xIg==',
326+
':description': 'ImQxIg==',
327+
':status': 's1',
328+
':discriminator': 'thing',
329+
':timestamp': 1572832690000,
330+
':eem': {
331+
dataKeys: {
332+
'us-west-2': MOCK_GEN_DK_RESPONSE.CiphertextBlob.toString('base64'),
333+
},
334+
masterKeyAlias: 'alias/aws-kms-ee',
335+
fields: [
336+
'name',
337+
'description',
338+
],
339+
},
340+
},
341+
UpdateExpression: 'SET #id = :id, #name = :name, #description = :description, #status = :status, #discriminator = :discriminator, #timestamp = :timestamp, #eem = :eem',
342+
ReturnValues: 'ALL_NEW',
343+
});
344+
})
345+
.done(done);
346+
});
347+
255348
it('should decrypt data - query function', async () => {
256349
const encryptedQueryResults = [{
257350
id: '1',

0 commit comments

Comments
 (0)