Skip to content

merge dev to main (v1.8.0) #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
@@ -90,7 +90,6 @@
"langium": "1.2.0",
"lower-case-first": "^2.0.2",
"mixpanel": "^0.17.0",
"node-machine-id": "^1.1.12",
"ora": "^5.4.1",
"pluralize": "^8.0.0",
"pretty-repl": "^4.0.0",
2 changes: 1 addition & 1 deletion packages/schema/src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ import sleep from 'sleep-promise';
import { CliError } from './cli/cli-error';
import { TELEMETRY_TRACKING_TOKEN } from './constants';
import isDocker from './utils/is-docker';
import { getVersion } from './utils/version-utils';
import { getMachineId } from './utils/machine-id-utils';
import { getVersion } from './utils/version-utils';

/**
* Telemetry events
69 changes: 66 additions & 3 deletions packages/schema/src/utils/machine-id-utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,73 @@
import { machineIdSync } from "node-machine-id";
// modified from https://github.com/automation-stack/node-machine-id

import { execSync } from 'child_process';
import { createHash } from 'crypto';
import { v4 as uuid } from 'uuid';

const { platform } = process;
const win32RegBinPath = {
native: '%windir%\\System32',
mixed: '%windir%\\sysnative\\cmd.exe /c %windir%\\System32',
};
const guid = {
darwin: 'ioreg -rd1 -c IOPlatformExpertDevice',
win32:
`${win32RegBinPath[isWindowsProcessMixedOrNativeArchitecture()]}\\REG.exe ` +
'QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography ' +
'/v MachineGuid',
linux: '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname 2> /dev/null) | head -n 1 || :',
freebsd: 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid',
};

function isWindowsProcessMixedOrNativeArchitecture() {
// eslint-disable-next-line no-prototype-builtins
if (process.arch === 'ia32' && process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432')) {
return 'mixed';
}
return 'native';
}

function hash(guid: string): string {
return createHash('sha256').update(guid).digest('hex');
}

function expose(result: string): string {
switch (platform) {
case 'darwin':
return result
.split('IOPlatformUUID')[1]
.split('\n')[0]
.replace(/=|\s+|"/gi, '')
.toLowerCase();
case 'win32':
return result
.toString()
.split('REG_SZ')[1]
.replace(/\r+|\n+|\s+/gi, '')
.toLowerCase();
case 'linux':
return result
.toString()
.replace(/\r+|\n+|\s+/gi, '')
.toLowerCase();
case 'freebsd':
return result
.toString()
.replace(/\r+|\n+|\s+/gi, '')
.toLowerCase();
default:
throw new Error(`Unsupported platform: ${process.platform}`);
}
}

export function getMachineId() {
// machineIdSync() is not compatible with non-shell hosts such as Vercel
if (!(platform in guid)) {
return uuid();
}
try {
return machineIdSync();
const value = execSync(guid[platform as keyof typeof guid]);
const id = expose(value.toString());
return hash(id);
} catch {
return uuid();
}
9 changes: 1 addition & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.