Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pack installer] implemented changes from PR review
Browse files Browse the repository at this point in the history
BigFunger committed Mar 11, 2016

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 842af6c commit ded166e
Showing 19 changed files with 265 additions and 243 deletions.
9 changes: 4 additions & 5 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import _ from 'lodash';

import pkg from '../utils/packageJson';
import Command from './Command';
import serveCommand from './serve/serve';

let argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) : process.argv.slice();
let program = new Command('bin/kibana');
const argv = process.env.kbnWorkerArgv ? JSON.parse(process.env.kbnWorkerArgv) : process.argv.slice();
const program = new Command('bin/kibana');

program
.version(pkg.version)
@@ -21,7 +20,7 @@ program
.command('help <command>')
.description('Get the help for a specific command')
.action(function (cmdName) {
var cmd = _.find(program.commands, { _name: cmdName });
const cmd = _.find(program.commands, { _name: cmdName });
if (!cmd) return program.error(`unknown command ${cmdName}`);
cmd.help();
});
@@ -33,7 +32,7 @@ program
});

// check for no command name
var subCommand = argv[2] && !String(argv[2][0]).match(/^-|^\.|\//);
const subCommand = argv[2] && !String(argv[2][0]).match(/^-|^\.|\//);

if (!subCommand) {
if (_.intersection(argv.slice(2), ['-h', '--help']).length) {
4 changes: 2 additions & 2 deletions src/cli_plugin/cli.js
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ let program = new Command('bin/kibana-plugin');
program
.version(pkg.version)
.description(
'Kibana is an open source (Apache Licensed), browser ' +
'based analytics and search dashboard for Elasticsearch.'
'The Kibana plugin manager enables you to install and remove plugins that ' +
'provide additional functionality to Kibana'
);

listCommand(program);
8 changes: 4 additions & 4 deletions src/cli_plugin/install/__tests__/cleanup.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import sinon from 'sinon';
import fs from 'fs';
import rimraf from 'rimraf';

import { cleanPrevious, cleanError } from '../cleanup';
import { cleanPrevious, cleanArtifacts } from '../cleanup';
import Logger from '../../lib/logger';

describe('kibana cli', function () {
@@ -108,7 +108,7 @@ describe('kibana cli', function () {

});

describe('cleanError', function () {
describe('cleanArtifacts', function () {
let logger;

beforeEach(function () {
@@ -122,7 +122,7 @@ describe('kibana cli', function () {
it('should attempt to delete the working directory', function () {
sinon.stub(rimraf, 'sync');

cleanError(settings);
cleanArtifacts(settings);
expect(rimraf.sync.calledWith(settings.workingPath)).to.be(true);
});

@@ -131,7 +131,7 @@ describe('kibana cli', function () {
throw new Error('Something bad happened.');
});

expect(cleanError).withArgs(settings).to.not.throwError();
expect(cleanArtifacts).withArgs(settings).to.not.throwError();
});

});
34 changes: 17 additions & 17 deletions src/cli_plugin/install/__tests__/download.js
Original file line number Diff line number Diff line change
@@ -61,11 +61,11 @@ describe('kibana cli', function () {
describe('http downloader', function () {

it('should throw an ENOTFOUND error for a http ulr that returns 404', function () {
const couchdb = nock('http://www.files.com')
const couchdb = nock('http://example.com')
.get('/plugin.tar.gz')
.reply(404);

const sourceUrl = 'http://www.files.com/plugin.tar.gz';
const sourceUrl = 'http://example.com/plugin.tar.gz';

return _downloadSingle(settings, logger, sourceUrl)
.then(shouldReject, function (err) {
@@ -87,15 +87,15 @@ describe('kibana cli', function () {
it('should download a file from a valid http url', function () {
const filePath = join(__dirname, 'replies/banana.jpg');

const couchdb = nock('http://www.files.com')
const couchdb = nock('http://example.com')
.defaultReplyHeaders({
'content-length': '341965',
'content-type': 'application/zip'
})
.get('/plugin.zip')
.replyWithFile(200, filePath);

const sourceUrl = 'http://www.files.com/plugin.zip';
const sourceUrl = 'http://example.com/plugin.zip';

return _downloadSingle(settings, logger, sourceUrl)
.then(function () {
@@ -136,13 +136,13 @@ describe('kibana cli', function () {
it('should loop through bad urls until it finds a good one.', function () {
const filePath = join(__dirname, 'replies/test_plugin.zip');
settings.urls = [
'http://www.files.com/badfile1.tar.gz',
'http://www.files.com/badfile2.tar.gz',
'http://example.com/badfile1.tar.gz',
'http://example.com/badfile2.tar.gz',
'I am a bad uri',
'http://www.files.com/goodfile.tar.gz'
'http://example.com/goodfile.tar.gz'
];

const couchdb = nock('http://www.files.com')
const couchdb = nock('http://example.com')
.defaultReplyHeaders({
'content-length': '10'
})
@@ -166,13 +166,13 @@ describe('kibana cli', function () {
it('should stop looping through urls when it finds a good one.', function () {
const filePath = join(__dirname, 'replies/test_plugin.zip');
settings.urls = [
'http://www.files.com/badfile1.tar.gz',
'http://www.files.com/badfile2.tar.gz',
'http://www.files.com/goodfile.tar.gz',
'http://www.files.com/badfile3.tar.gz'
'http://example.com/badfile1.tar.gz',
'http://example.com/badfile2.tar.gz',
'http://example.com/goodfile.tar.gz',
'http://example.com/badfile3.tar.gz'
];

const couchdb = nock('http://www.files.com')
const couchdb = nock('http://example.com')
.defaultReplyHeaders({
'content-length': '10'
})
@@ -196,12 +196,12 @@ describe('kibana cli', function () {

it('should throw an error when it doesn\'t find a good url.', function () {
settings.urls = [
'http://www.files.com/badfile1.tar.gz',
'http://www.files.com/badfile2.tar.gz',
'http://www.files.com/badfile3.tar.gz'
'http://example.com/badfile1.tar.gz',
'http://example.com/badfile2.tar.gz',
'http://example.com/badfile3.tar.gz'
];

const couchdb = nock('http://www.files.com')
const couchdb = nock('http://example.com')
.defaultReplyHeaders({
'content-length': '10'
})
2 changes: 1 addition & 1 deletion src/cli_plugin/install/cleanup.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ export function cleanPrevious(settings, logger) {
});
};

export function cleanError(settings) {
export function cleanArtifacts(settings) {
// delete the working directory.
// At this point we're bailing, so swallow any errors on delete.
try {
1 change: 0 additions & 1 deletion src/cli_plugin/install/download.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import downloadHttpFile from './downloaders/http';
import downloadLocalFile from './downloaders/file';
import { parse } from 'url';
26 changes: 13 additions & 13 deletions src/cli_plugin/install/index.js
Original file line number Diff line number Diff line change
@@ -4,21 +4,21 @@ import Logger from '../lib/logger';
import pkg from '../../utils/packageJson';
import { parse, parseMilliseconds } from './settings';

export default function pluginInstall(program) {
function processCommand(command, options) {
let settings;
try {
settings = parse(command, options, pkg);
} catch (ex) {
//The logger has not yet been initialized.
console.error(ex.message);
process.exit(64); // eslint-disable-line no-process-exit
}

const logger = new Logger(settings);
install(settings, logger);
function processCommand(command, options) {
let settings;
try {
settings = parse(command, options, pkg);
} catch (ex) {
//The logger has not yet been initialized.
console.error(ex.message);
process.exit(64); // eslint-disable-line no-process-exit
}

const logger = new Logger(settings);
install(settings, logger);
}

export default function pluginInstall(program) {
program
.command('install <plugin/url>')
.option('-q, --quiet', 'Disable all process messaging except errors')
14 changes: 7 additions & 7 deletions src/cli_plugin/install/install.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import _ from 'lodash';
import { download } from './download';
import Promise from 'bluebird';
import { cleanPrevious, cleanError } from './cleanup';
import { cleanPrevious, cleanArtifacts } from './cleanup';
import { extract, getPackData } from './pack';
import { sync as rimrafSync } from 'rimraf';
import { statSync, renameSync } from 'fs';
import { renameSync } from 'fs';
import { existingInstall, rebuildCache, checkVersion } from './kibana';
import mkdirp from 'mkdirp';

const mkdirp = Promise.promisify(require('mkdirp'));
const mkdir = Promise.promisify(mkdirp);

export default async function install(settings, logger) {
try {
await cleanPrevious(settings, logger);

await mkdirp(settings.workingPath);
await mkdir(settings.workingPath);

await download(settings, logger);

await getPackData(settings, logger);

await extract (settings, logger);
await extract(settings, logger);

rimrafSync(settings.tempArchiveFile);

@@ -34,7 +34,7 @@ export default async function install(settings, logger) {
logger.log('Plugin installation complete');
} catch (err) {
logger.error(`Plugin installation was unsuccessful due to error "${err.message}"`);
cleanError(settings);
cleanArtifacts(settings);
process.exit(70); // eslint-disable-line no-process-exit
}
}
Loading

0 comments on commit ded166e

Please sign in to comment.