-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonkey.js
81 lines (65 loc) · 1.61 KB
/
monkey.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
function monkey(AWS, actionMap) {
actionMap = actionMap || {};
//
// wrap SNS:
//
var OriginalSNS = AWS.SNS;
AWS.SNS = function () {
var sns = new OriginalSNS(arguments);
var originalPublish = sns.publish;
sns.publish = function () {
if (actionMap.sns) {
actionMap.sns.apply(this, arguments);
}
originalPublish.apply(this, arguments);
};
return sns;
};
//
// wrap Lambda:
//
var originalLambda = AWS.Lambda;
AWS.Lambda = function () {
var lambda = new originalLambda(arguments);
var originalInvoke = lambda.invoke;
lambda.invoke = function () {
if (actionMap.lambda) {
actionMap.lambda.apply(this, arguments);
}
originalInvoke.apply(this, arguments);
};
return lambda;
};
//
// wrap S3:
//
var originalS3 = AWS.S3;
AWS.S3 = function () {
var s3 = new originalS3(arguments);
var originalUpload = s3.upload;
var originalGetObject = s3.getObject;
var originalPutObject = s3.putObject;
s3.upload = function () {
if (actionMap.s3) {
actionMap.s3.apply(this, arguments);
}
originalUpload.apply(this, arguments);
};
s3.getObject = function () {
if (actionMap.s3) {
actionMap.s3.apply(this, arguments);
}
originalGetObject.apply(this, arguments);
};
s3.putObject = function () {
if (actionMap.s3) {
actionMap.s3.apply(this, arguments);
}
originalPutObject.apply(this, arguments);
};
return s3;
};
AWS.S3.ManagedUpload = originalS3.ManagedUpload;
return AWS;
}
module.exports = monkey;