UNPKG

@mindconnect/mindconnect-nodejs

Version:

MindConnect Library for NodeJS (community based)

54 lines 3.15 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 utils_1 = require("../../api/utils"); const command_utils_1 = require("./command-utils"); const color = command_utils_1.getColor("magenta"); exports.default = (program) => { program .command("service-credentials") .alias("sc") .option("-u, --user <username>", "service credentials: username") .option("-p, --password <password>", "service credendials: password") .option("-g, --gateway <gateway>", "region string or full gateway url (e.g. eu1, eu2 or https://gateway.eu1.mindsphere.io)") .option("-t, --tenant <tenant>", "your tenant name") .option("-k, --passkey <passkey>", "passkey (you will use this in the commands which require service credentials)") .option("-v, --verbose", "verbose output") .description(color("provide login for commands which require technical user credentials *")) .action(options => { (() => __awaiter(void 0, void 0, void 0, function* () { try { if (!options.gateway || !options.user || !options.tenant || !options.passkey) { command_utils_1.errorLog("Invalid/missing parameters for service-credentials command. Run mc sc --help for full syntax and examples.", true); process.exit(1); } const gateway = utils_1.isUrl(options.gateway) ? options.gateway : `https://gateway.${options.gateway}.mindsphere.io`; console_1.log(utils_1.getPiamUrl(gateway, options.tenant)); const encrypted = utils_1.encrypt(options.user, options.password, options.passkey, gateway, options.tenant); utils_1.storeAuth(encrypted); const decrypted = utils_1.decrypt(encrypted, options.passkey); console.log(decrypted); } catch (err) { command_utils_1.errorLog(err, options.verbose); } }))(); }) .on("--help", () => { console_1.log(`\n Example:\n`); console_1.log(` mc service-credentials --user tenantx001 --password xxxx-xxx-x-x --gateway eu1 --tenant tenantx --passkey mypasskey`); command_utils_1.serviceCredentialLog(); }); }; //# sourceMappingURL=mc-service-credentials.js.map