UNPKG

trm-client

Version:

TRM (Transport Request Manager) Client

60 lines (59 loc) 2.53 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 }); exports.login = login; const registryAlias_1 = require("../registryAlias"); const whoami_1 = require("./whoami"); const commons_1 = require("./commons"); const trm_commons_1 = require("trm-commons"); function login(commandArgs) { return __awaiter(this, void 0, void 0, function* () { var continueLogin = false; if (!commandArgs.force) { try { const whoami = yield commons_1.CommandContext.getRegistry().whoAmI(); const inq1 = yield trm_commons_1.Inquirer.prompt({ type: "confirm", name: "continue", message: `Already logged in as "${whoami.username}". Do you want to logout and continue?`, default: false }); continueLogin = inq1.continue; } catch (e) { continueLogin = true; } } else { continueLogin = true; } if (continueLogin) { const auth = commandArgs.authentication; var oAuth; if (auth) { try { oAuth = JSON.parse(auth); } catch (e) { throw new Error(`Invalid authentication JSON object.`); } } else { oAuth = undefined; } yield commons_1.CommandContext.getRegistry().authenticate(oAuth); oAuth = commons_1.CommandContext.getRegistry().getAuthData(); trm_commons_1.Logger.success('Logged in.'); registryAlias_1.RegistryAlias.update(commons_1.CommandContext.getRegistry().name, oAuth); yield (0, whoami_1.whoami)({}); } }); }