node-opcua-hostname
Advanced tools
Comparing version 2.105.0 to 2.118.0
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -39,4 +10,4 @@ exports.resolveFullyQualifiedDomainName = exports.getHostname = exports.getFullyQualifiedDomainName = exports.prepareFQDN = exports.extractFullyQualifiedDomainName = void 0; | ||
*/ | ||
const dns = __importStar(require("dns")); | ||
const os = __importStar(require("os")); | ||
const dns_1 = __importDefault(require("dns")); | ||
const os_1 = __importDefault(require("os")); | ||
const util_1 = require("util"); | ||
@@ -50,8 +21,8 @@ function trim(str, length) { | ||
function fqdn(callback) { | ||
const uqdn = os.hostname(); | ||
dns.lookup(uqdn, { hints: dns.ADDRCONFIG }, (err1, ip) => { | ||
const uqdn = os_1.default.hostname(); | ||
dns_1.default.lookup(uqdn, { hints: dns_1.default.ADDRCONFIG }, (err1, ip) => { | ||
if (err1) { | ||
return callback(err1); | ||
} | ||
dns.lookupService(ip, 0, (err2, _fqdn) => { | ||
dns_1.default.lookupService(ip, 0, (err2, _fqdn) => { | ||
if (err2) { | ||
@@ -69,36 +40,32 @@ return callback(err2); | ||
*/ | ||
function extractFullyQualifiedDomainName() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (_fullyQualifiedDomainNameInCache) { | ||
return _fullyQualifiedDomainNameInCache; | ||
} | ||
if (process.platform === "win32") { | ||
// http://serverfault.com/a/73643/251863 | ||
const env = process.env; | ||
_fullyQualifiedDomainNameInCache = | ||
env.COMPUTERNAME + (env.USERDNSDOMAIN && env.USERDNSDOMAIN.length > 0 ? "." + env.USERDNSDOMAIN : ""); | ||
} | ||
else { | ||
try { | ||
_fullyQualifiedDomainNameInCache = yield (0, util_1.promisify)(fqdn)(); | ||
if (_fullyQualifiedDomainNameInCache === "localhost") { | ||
throw new Error("localhost not expected"); | ||
} | ||
if (/sethostname/.test(_fullyQualifiedDomainNameInCache)) { | ||
throw new Error("Detecting fqdn on windows !!!"); | ||
} | ||
async function extractFullyQualifiedDomainName() { | ||
if (_fullyQualifiedDomainNameInCache) { | ||
return _fullyQualifiedDomainNameInCache; | ||
} | ||
if (process.platform === "win32") { | ||
// http://serverfault.com/a/73643/251863 | ||
const env = process.env; | ||
_fullyQualifiedDomainNameInCache = | ||
env.COMPUTERNAME + (env.USERDNSDOMAIN && env.USERDNSDOMAIN.length > 0 ? "." + env.USERDNSDOMAIN : ""); | ||
} | ||
else { | ||
try { | ||
_fullyQualifiedDomainNameInCache = await (0, util_1.promisify)(fqdn)(); | ||
if (_fullyQualifiedDomainNameInCache === "localhost") { | ||
throw new Error("localhost not expected"); | ||
} | ||
catch (err) { | ||
// fall back to old method | ||
_fullyQualifiedDomainNameInCache = os.hostname(); | ||
if (/sethostname/.test(_fullyQualifiedDomainNameInCache)) { | ||
throw new Error("Detecting fqdn on windows !!!"); | ||
} | ||
} | ||
return _fullyQualifiedDomainNameInCache; | ||
}); | ||
catch (err) { | ||
// fall back to old method | ||
_fullyQualifiedDomainNameInCache = os_1.default.hostname(); | ||
} | ||
} | ||
return _fullyQualifiedDomainNameInCache; | ||
} | ||
exports.extractFullyQualifiedDomainName = extractFullyQualifiedDomainName; | ||
function prepareFQDN() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
_fullyQualifiedDomainNameInCache = yield extractFullyQualifiedDomainName(); | ||
}); | ||
async function prepareFQDN() { | ||
_fullyQualifiedDomainNameInCache = await extractFullyQualifiedDomainName(); | ||
} | ||
@@ -114,3 +81,3 @@ exports.prepareFQDN = prepareFQDN; | ||
function getHostname() { | ||
return os.hostname(); | ||
return os_1.default.hostname(); | ||
} | ||
@@ -117,0 +84,0 @@ exports.getHostname = getHostname; |
@@ -5,3 +5,3 @@ { | ||
"types": "./dist/index.d.ts", | ||
"version": "2.105.0", | ||
"version": "2.118.0", | ||
"description": "pure nodejs OPCUA SDK - module hostname", | ||
@@ -32,3 +32,3 @@ "scripts": { | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "41c30f321debfe92128905d97a52426b9d7f9b9e", | ||
"gitHead": "6210aaa97b43554e3982113041963b2720e50a95", | ||
"files": [ | ||
@@ -35,0 +35,0 @@ "dist", |
/** | ||
* @module node-opcua-hostname | ||
*/ | ||
import * as dns from "dns"; | ||
import * as os from "os"; | ||
import dns from "dns"; | ||
import os from "os"; | ||
import { promisify } from "util"; | ||
@@ -7,0 +7,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11
13520
227