UNPKG

@mindconnect/mindconnect-nodejs

Version:

MindConnect Library for NodeJS (community based)

59 lines 3.31 kB
"use strict"; 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 }); const console_1 = require("console"); const fs = require("fs"); const path = require("path"); const __1 = require("../.."); const utils_1 = require("../../api/utils"); const command_utils_1 = require("./command-utils"); const color = command_utils_1.getColor("magenta"); exports.default = (program) => { program .command("register-diagnostic") .alias("rd") .option("-c, --config <agentconfig>", "config file with agent configuration", "agentconfig.json") .option("-k, --passkey <passkey>", "passkey") .option("-v, --verbose", "verbose output") .description(color("register agent for diagnostic *")) .action(options => { (() => __awaiter(void 0, void 0, void 0, function* () { try { if (!options.passkey) { command_utils_1.errorLog("you have to provide a passkey (run mc rd --help for full description)", true); } command_utils_1.homeDirLog(options.verbose, color); command_utils_1.proxyLog(options.verbose, color); const auth = utils_1.loadAuth(); const setup = new __1.MindConnectSetup(auth.gateway, utils_1.decrypt(auth, options.passkey), auth.tenant); const configFile = path.resolve(options.config); if (!fs.existsSync(configFile)) { throw new Error(`Can't find file ${configFile}`); } const configuration = require(configFile); command_utils_1.verboseLog(`registering for diagnostic with agent id ${color(configuration.content.clientId)}`, options.verbose); yield setup.RegisterForDiagnostic(configuration.content.clientId); command_utils_1.verboseLog(`successfully registered the agent with agent id ${color(configuration.content.clientId)} for diagnostic`, true); } catch (err) { command_utils_1.verboseLog(color("This operation requires additionaly the service credentials."), options.verbose); command_utils_1.errorLog(err, options.verbose); } }))(); }) .on("--help", () => { console_1.log(`\n Examples:\n`); console_1.log(` mc rd -k mypasskey`); console_1.log(` mc register-diagnostic --config someagent.json -passkey mypasskey`); command_utils_1.serviceCredentialLog(); }); }; //# sourceMappingURL=mc-register-diagnostic.js.map