az-iot-bi/lib/machineId.js

41 строка
907 B
JavaScript
Исходник Обычный вид История

/**
* This module is inspired by https://github.com/sindresorhus/username/blob/master/index.js .
*/
'use strict';
var execa = require('execa');
var os = require('os');
2016-10-27 09:49:40 +03:00
var utils = require('./utils.js');
function getEnvVar() {
var env = process.env;
return env.LOGNAME ||
env.USER ||
env.LNAME ||
env.USERNAME;
}
function cleanWinCmd(x) {
return x.replace(/^.*\\/, '');
}
function getUsername () {
var envVar = getEnvVar();
if (envVar) {
return envVar;
}
try {
if (process.platform === 'darwin' || process.platform === 'linux') {
return execa.sync('id', ['-un']).stdout;
} else if (process.platform === 'win32') {
return cleanWinCmd(execa.sync('whoami').stdout);
}
} catch (err) { } // eslint-disable-line
}
module.exports = function () {
2016-10-27 09:49:40 +03:00
return utils.getSha256Hash(os.hostname() + getUsername());
};