UNPKG

@mindconnect/mindconnect-nodejs

Version:

NodeJS Library for MindSphere Connectivity - TypeScript SDK for MindSphere - MindSphere Command Line Interface - MindSphere Development Proxy

79 lines 4.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"); let color = (0, command_utils_1.getColor)("magenta"); let green = (0, command_utils_1.getColor)("green"); let red = (0, command_utils_1.getColor)("red"); exports.default = (program) => { program .command("asset-lock") .alias("lck") .option("-m, --mode [info|lock|unlock]", "mode [info | lock | unlock]", "info") .option("-k, --passkey <passkey>", "passkey") .option("-y, --retry <number>", "retry attempts before giving up", "3") .option("-v, --verbose", "verbose output") .description(color(`lock/unlock asset model modifications *`)) .action((options) => { (() => __awaiter(void 0, void 0, void 0, function* () { try { checkRequiredParameters(options); const sdk = (0, command_utils_1.getSdk)(options); color = (0, command_utils_1.adjustColor)(color, options); (0, command_utils_1.homeDirLog)(options.verbose, color); (0, command_utils_1.proxyLog)(options.verbose, color); const assetManagement = sdk.GetAssetManagementClient(); switch (options.mode) { case "info": { const info = (yield (0, utils_1.retry)(options.retry, () => assetManagement.GetModelLock())); printStatus(sdk, info, options); } break; case "lock": { const info = (yield (0, utils_1.retry)(options.retry, () => assetManagement.PutModelLock({ enabled: true }))); printStatus(sdk, info, options); } break; case "unlock": { const info = (yield (0, utils_1.retry)(options.retry, () => assetManagement.PutModelLock({ enabled: false }))); printStatus(sdk, info, options); } break; default: throw Error(`no such option: ${options.mode}`); } } catch (err) { (0, command_utils_1.errorLog)(err, options.verbose); } }))(); }) .on("--help", () => { (0, console_1.log)("\n Examples:\n"); (0, console_1.log)(` mc asset-lock --mode info \t\t\t\t print out the asset model lock state`); (0, console_1.log)(` mc asset-lock --mode lock \t\t\t\t lock the asset model and disable modifications`); (0, console_1.log)(` mc asset-lock --mode unlock \t\t\t unlock the asset model and enable modifications`); (0, command_utils_1.serviceCredentialLog)(); }); }; function printStatus(sdk, info, options) { (0, command_utils_1.verboseLog)(JSON.stringify(info, null, 2), options.verbose); console.log(`The asset model for ${color(sdk.GetTenant())} is ${info.enabled ? red("locked") + ". Modifications are blocked." : green("unlocked") + ". Modifications are allowed."}`); } function checkRequiredParameters(options) { } //# sourceMappingURL=asset-model-lock.js.map