UNPKG

cli-stash

Version:

CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.

78 lines (77 loc) 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const baseCommand_1 = require("../../libs/core/baseCommand"); const stashResponse_1 = require("../../libs/core/stashResponse"); const tables_1 = require("../../libs/core/tables"); const ux_1 = require("../../libs/core/ux"); class Login extends baseCommand_1.BaseCommand { async run() { const { host, alias, username, password } = this.flags; const response = new stashResponse_1.StashCLIResponse(); if (this.localConfig.instances && this.localConfig.instances[alias]) { if (this.flags.override) { this.localConfig.instances[alias] = { host: host.href, alias: alias, token: Buffer.from(username + ':' + password).toString('base64'), }; } else { throw new Error('An existing instance exists with the same alias. Use override flag if you want to override it'); } } else { this.localConfig.instances[alias] = { host: host.href, alias: alias, token: Buffer.from(username + ':' + password).toString('base64'), }; } this.localConfig.save(); const message = 'Instace with alias ' + alias + ' logged successfully'; response.status = 0; response.message = message; response.result = this.localConfig.instances[alias]; this.ux.table([response.result], tables_1.InstanceColumns, { csv: this.flags.csv, }); return response; } } exports.default = Login; Login.loginRequired = false; Login.description = 'Login againts Stash instance. Return the Stash Instance data. ' + ux_1.UX.processDocumentation('<doc:Instance>'); Login.examples = [ `$ stash auth:login -a "Alias" -u "username" -p "password" -h "http.//stash.example.com" --csv`, `$ stash auth:login -a "Alias" -u "username" -p "password" -h "http.//stash.example.com" -o --json`, ]; Login.flags = { ...baseCommand_1.BaseCommand.flags, alias: baseCommand_1.BuildFlags.alias, csv: baseCommand_1.BuildFlags.csv, username: core_1.Flags.string({ description: 'The Stash username to login', required: true, char: 'u', name: 'Username' }), password: core_1.Flags.string({ description: 'The Stash password', required: true, char: 'p', name: 'Password', }), host: core_1.Flags.url({ description: 'The Stash host URL to login and work with it', required: true, char: 'h', name: 'Host' }), override: core_1.Flags.boolean({ description: 'Override the existing Stash instance configuration', required: false, char: 'o', name: 'Override' }) };