UNPKG

auditjs

Version:

Audit dependencies to identify known vulnerabilities and maintenance problems

83 lines 4.24 kB
"use strict"; /* * Copyright 2019-Present Sonatype Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AppConfig = void 0; const readline_1 = __importDefault(require("readline")); const OssIndexServerConfig_1 = require("./OssIndexServerConfig"); const IqServerConfig_1 = require("./IqServerConfig"); const ConfigPersist_1 = require("./ConfigPersist"); const path_1 = require("path"); const os_1 = require("os"); class AppConfig { constructor() { this.rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout, }); } getConfigFromCommandLine() { return __awaiter(this, void 0, void 0, function* () { let username = ''; let token = ''; let type = ''; type = yield this.setVariable('Do you want to set config for Nexus IQ Server or OSS Index? Hit enter for OSS Index, iq for Nexus IQ Server? '); if (type == 'iq') { username = 'admin'; token = 'admin123'; let host = 'http://localhost:8070'; username = yield this.setVariable(`What is your username (default: ${username})? `, username); token = yield this.setVariable(`What is your password/token (pretty please do not save your password to the filesystem, USE A TOKEN) (default: ${token})? `, token); host = yield this.setVariable(`What is your IQ Server address (default: ${host})? `, host); this.rl.close(); const iqConfig = new ConfigPersist_1.ConfigPersist(username, token, host.endsWith('/') ? host.slice(0, host.length - 1) : host); const config = new IqServerConfig_1.IqServerConfig(); return config.saveFile(iqConfig); } else { let cacheLocation = (0, path_1.join)((0, os_1.homedir)(), '.ossindex', 'auditjs'); username = yield this.setVariable('What is your username? '); token = yield this.setVariable('What is your token? '); cacheLocation = yield this.setVariable(`Where would you like your OSS Index cache saved to (default: ${cacheLocation})? `, cacheLocation); this.rl.close(); const ossIndexConfig = new ConfigPersist_1.ConfigPersist(username, token, undefined, cacheLocation); const config = new OssIndexServerConfig_1.OssIndexServerConfig(); return config.saveFile(ossIndexConfig); } }); } setVariable(message, defaultValue = '') { return new Promise((resolve) => { this.rl.question(message, (answer) => { resolve(answer || defaultValue); }); }); } } exports.AppConfig = AppConfig; //# sourceMappingURL=AppConfig.js.map