@contrast/instrumentation 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/index.js +33 -0
- package/lib/mongodb.js +53 -0
- package/lib/utils.js +26 -0
- package/package.json +19 -0
package/README.md
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2022 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
'use strict';
|
|
17
|
+
module.exports = function(core) {
|
|
18
|
+
const installers = {
|
|
19
|
+
...require('./mongodb')(core)
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return core.instrumentation = {
|
|
23
|
+
instrument(opts) {
|
|
24
|
+
const { moduleName } = opts;
|
|
25
|
+
if (!moduleName || !installers[moduleName]) {
|
|
26
|
+
core.logger.error('Unable to instrument non-existent hook: %s', moduleName);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
installers[moduleName](opts);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
};
|
package/lib/mongodb.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2022 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const { get } = require('./utils');
|
|
18
|
+
|
|
19
|
+
module.exports = function(core) {
|
|
20
|
+
const {
|
|
21
|
+
patcher,
|
|
22
|
+
depHooks
|
|
23
|
+
} = core;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
'mongodb'(opts) {
|
|
27
|
+
const { file, version, patchObjects } = opts;
|
|
28
|
+
const module = {
|
|
29
|
+
name: 'mongodb',
|
|
30
|
+
version
|
|
31
|
+
};
|
|
32
|
+
if (file) {
|
|
33
|
+
module.file = file;
|
|
34
|
+
}
|
|
35
|
+
depHooks.resolve(module, (mongodb, { version: semVer }) => {
|
|
36
|
+
patchObjects.forEach((obj) => {
|
|
37
|
+
const { name, methods, patchName, ...patcherOpts } = obj;
|
|
38
|
+
methods.forEach((method) => {
|
|
39
|
+
const patchObj = get(mongodb, patchName || name);
|
|
40
|
+
const { preHookFn } = patcherOpts;
|
|
41
|
+
patcher.patch(patchObj, method, {
|
|
42
|
+
name: name ? `mongodb.${name}.${method}` : `mongodb.${method}`,
|
|
43
|
+
pre: (ctx) => {
|
|
44
|
+
preHookFn(ctx, semVer);
|
|
45
|
+
},
|
|
46
|
+
...patcherOpts
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2022 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
function get(obj, name) {
|
|
18
|
+
if (!name) return obj;
|
|
19
|
+
let nest = obj;
|
|
20
|
+
name.split('.').forEach((prop) => {
|
|
21
|
+
nest = nest[prop];
|
|
22
|
+
});
|
|
23
|
+
return nest;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = { get };
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contrast/instrumentation",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Shared hooks and patches between Protect and Assess components",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/"
|
|
9
|
+
],
|
|
10
|
+
"main": "lib/index.js",
|
|
11
|
+
"types": "lib/index.d.ts",
|
|
12
|
+
"engines": {
|
|
13
|
+
"npm": ">=6.13.7 <7 || >= 8.3.1",
|
|
14
|
+
"node": ">= 14.15.0"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "../scripts/test.sh"
|
|
18
|
+
}
|
|
19
|
+
}
|