UNPKG

@papavault/cli

Version:

CLI tool for Papa Vault Secret Manager

66 lines (65 loc) 2.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.loginCommand = loginCommand; const inquirer_1 = __importDefault(require("inquirer")); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const config_1 = require("../utils/config"); const api_1 = require("../utils/api"); function loginCommand(program) { program .command('login') .description('Authenticate with Papa Vault using an API token') .option('-t, --token <token>', 'API token for authentication') .action(async (options) => { // Check if already logged in const existingToken = (0, config_1.getToken)(); if (existingToken) { const { confirm } = await inquirer_1.default.prompt([ { type: 'confirm', name: 'confirm', message: 'You are already logged in. Do you want to replace the existing token?', default: false } ]); if (!confirm) { console.log(chalk_1.default.green('Login cancelled. You are still logged in with your existing token.')); return; } } // Get token from options or prompt let token = options.token; if (!token) { const answers = await inquirer_1.default.prompt([ { type: 'password', name: 'token', message: 'Enter your Papa Vault API token:', validate: (input) => (input ? true : 'API token is required') } ]); token = answers.token; } // Validate the token const spinner = (0, ora_1.default)('Validating token...').start(); try { const isValid = await (0, api_1.validateToken)(token); if (isValid) { (0, config_1.setToken)(token); spinner.succeed('Successfully authenticated with Papa Vault!'); console.log(chalk_1.default.green('You can now use the CLI to manage your secrets.')); } else { spinner.fail('Invalid API token. Please check your token and try again.'); } } catch (error) { spinner.fail('Failed to validate token'); console.error(chalk_1.default.red('Error:'), error); } }); }