Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contrast/core

Package Overview
Dependencies
Maintainers
9
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contrast/core - npm Package Compare versions

Comparing version 1.32.3 to 1.33.0

lib/system-info/cloud-resource-identifier.js

8

lib/agent-info.js

@@ -18,6 +18,7 @@ /*

const { randomUUID } = require('crypto');
const { name: agentName, version: agentVersion } = require('../package.json');
module.exports = function init(core) {
// default to version of core
// default to name and version of core
if (!core.agentName) {

@@ -30,3 +31,8 @@ core.agentName = agentName;

// default to a new random UUID
if (!core.reportingInstance) {
core.reportingInstance = randomUUID();
}
return core;
};

2

lib/app-info.js

@@ -170,3 +170,3 @@ /*

try {
packageFile = findPackageJsonSync({ cwd: dir });
packageFile = process.env.npm_package_json ?? findPackageJsonSync({ cwd: dir });
packageData = require(packageFile);

@@ -173,0 +173,0 @@ break;

@@ -16,3 +16,3 @@ /*

import { AppInfo, Messages } from '@contrast/common';
import { AppInfo, Messages, SystemInfo } from '@contrast/common';

@@ -36,2 +36,3 @@ interface Frame {

agentVersion: string;
reportingInstance: string;

@@ -49,3 +50,3 @@ appInfo: AppInfo;

getSystemInfo(): any;
getSystemInfo(): Promise<SystemInfo>;
}

@@ -15,35 +15,27 @@ /*

*/
// @ts-check
'use strict';
const path = require('path');
const fs = require('fs');
const fs = require('fs/promises');
const os = require('os');
const { getResourceID } = require('./cloud-resource-identifier');
function isUsingPM2() {
const used = !!process.env.pmx;
let version;
const MOUNTINFO_REGEX = /\/docker\/containers\/(.*?)\//;
const CGROUP_REGEX = /:\/docker\/([^/]+)$/;
for (const pathVar of ['npm_package_json', 'PWD']) {
const packagePath = process.env[pathVar];
if (packagePath) {
try {
version = require(path.join(packagePath, 'package.json')).dependencies['pm2'];
} catch (err) {
//
}
}
if (version) break;
function isUsingPM2(pkg) {
const result = { used: !!process.env.pmx, version: null };
if (pkg?.dependences?.['pm2']) {
result.version = pkg.dependencies['pm2'];
}
return { used, ...(version && { version }) };
return result;
}
function isDocker() {
const MOUNTINFO_REGEX = /\/docker\/containers\/(.*?)\//;
const CGROUP_REGEX = /:\/docker\/([^/]+)$/;
async function isDocker() {
try {
const results = fs.readFileSync('/proc/self/mountinfo', 'utf8').match(MOUNTINFO_REGEX);
if (results) return { isDocker: true, containerID: results[1] };
const result = await fs.readFile('/proc/self/mountinfo', 'utf8');
const matches = result.match(MOUNTINFO_REGEX);
if (matches) return { isDocker: true, containerID: matches[1] };
} catch (err) {

@@ -54,4 +46,5 @@ // else check /proc/self/cgroup

try {
const results = fs.readFileSync('/proc/self/cgroup', 'utf8').match(CGROUP_REGEX);
if (results) return { isDocker: true, containerID: results[1] };
const result = await fs.readFile('/proc/self/cgroup', 'utf8');
const matches = result.match(CGROUP_REGEX);
if (matches) return { isDocker: true, containerID: matches[1] };
} catch (err) {

@@ -62,3 +55,3 @@ // else check /.dockerenv

try {
const result = fs.statSync('/.dockerenv');
const result = await fs.stat('/.dockerenv');
if (result) return { isDocker: true, containerID: null };

@@ -76,9 +69,15 @@ } catch (err) {

agentVersion,
config
config,
appInfo,
} = core;
// have values default to null so all required keys get serialized
core.getSystemInfo = function() {
const appPath = process.cwd();
core.getSystemInfo = async function getSystemInfo() {
// memoize for subsequent lookups
if (core._systemInfo) return core._systemInfo;
const cpus = os.cpus();
const totalmem = os.totalmem();
const freemem = os.freemem();
const info = {

@@ -110,20 +109,24 @@ ReportDate: new Date().toISOString(),

CPU: {
Type: os.cpus()[0].model,
Count: os.cpus().length,
Type: cpus[0].model,
Count: cpus.length,
}
},
Host: {
Docker: isDocker(),
PM2: isUsingPM2(),
Docker: await isDocker(),
PM2: isUsingPM2(appInfo.pkg),
Memory: {
Total: (os.totalmem() / 1e6).toFixed(0).concat(' MB'),
Free: (os.freemem() / 1e6).toFixed(0).concat(' MB'),
Used: ((os.totalmem() - os.freemem()) / 1e6).toFixed(0).concat(' MB'),
Total: (totalmem / 1e6).toFixed(0).concat(' MB'),
Free: (freemem / 1e6).toFixed(0).concat(' MB'),
Used: ((totalmem - freemem) / 1e6).toFixed(0).concat(' MB'),
}
},
Application: appPath ? require(path.join(appPath, 'package.json')) : null,
Application: appInfo.pkg,
};
return info;
if (config.server.discover_cloud_resource) {
info.ResourceID = await getResourceID(config.inventory.gather_metadata_via);
}
return core._systemInfo = info;
};
};
{
"name": "@contrast/core",
"version": "1.32.3",
"version": "1.33.0",
"description": "Preconfigured Contrast agent core services and models",

@@ -19,6 +19,7 @@ "license": "SEE LICENSE IN LICENSE",

"dependencies": {
"@contrast/common": "1.21.3",
"@contrast/common": "1.22.0",
"@contrast/find-package-json": "^1.0.0",
"@contrast/fn-inspect": "^4.0.0"
"@contrast/fn-inspect": "^4.0.0",
"axios": "^1.6.8"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc