File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 11import { packageInfo } from "../packageInfo.js" ;
22import { type CommonStaticProperties } from "./types.js" ;
3+ import { getDeviceId } from "./device-id.js" ;
34/**
45 * Machine-specific metadata formatted for telemetry
56 */
Original file line number Diff line number Diff line change 1+ import { createHmac } from "crypto" ;
2+ import nodeMachineId from "node-machine-id" ;
3+ import logger , { LogId } from "../logger.js" ;
4+
5+ export function getDeviceId ( ) : string {
6+ try {
7+ const originalId = nodeMachineId . machineIdSync ( true ) ;
8+ // Create a hashed format from the all uppercase version of the machine ID
9+ // to match it exactly with the denisbrodbeck/machineid library that Atlas CLI uses.
10+ const hmac = createHmac ( "sha256" , originalId . toUpperCase ( ) ) ;
11+
12+ /** This matches the message used to create the hashes in Atlas CLI */
13+ const DEVICE_ID_HASH_MESSAGE = "atlascli" ;
14+
15+ hmac . update ( DEVICE_ID_HASH_MESSAGE ) ;
16+ return hmac . digest ( "hex" ) ;
17+ } catch ( error ) {
18+ logger . debug ( LogId . telemetryDeviceIdFailure , "telemetry" , String ( error ) ) ;
19+ return "unknown" ;
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments