Skip to content

Commit

Permalink
[plugin installer] Allow x-pack removal if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jbudz committed Jun 7, 2018
1 parent 5ccaca4 commit 47555d9
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 85 deletions.
72 changes: 0 additions & 72 deletions src/cli_plugin/lib/__tests__/error_if_x_pack.js

This file was deleted.

11 changes: 5 additions & 6 deletions src/cli_plugin/lib/error_if_x_pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@ function isXPack(plugin) {
return /x-pack/.test(plugin);
}

export function errorIfXPackInstall(settings, logger) {
export function errorIfXPackInstall(settings) {
if (isXPack(settings.plugin)) {
if (isOSS()) {
logger.error(
throw new Error(
'You are using the OSS-only distribution of Kibana. ' +
'As of version 6.3+ X-Pack is bundled in the standard distribution of this software by default; ' +
'consequently it is no longer available as a plugin. Please use the standard distribution of Kibana to use X-Pack features.'
);
} else {
logger.error(
throw new Error(
'Kibana now contains X-Pack by default, there is no longer any need to install it as it is already present.'
);
}
process.exit(1);
}
}

export function errorIfXPackRemove(settings, logger) {
export function errorIfXPackRemove(settings) {
if (isXPack(settings.plugin) && !isOSS()) {
logger.error(
throw new Error(
'You are using the standard distrbution of Kibana. Please install the OSS-only distribution to remove X-Pack features.'
);
process.exit(1);
Expand Down
51 changes: 51 additions & 0 deletions src/cli_plugin/lib/error_if_x_pack.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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.
*/


import { errorIfXPackInstall, errorIfXPackRemove } from './error_if_x_pack';

describe('error_if_xpack', () => {
it('should error on install if x-pack by name', () => {
expect(() => errorIfXPackInstall({ plugin: 'x-pack' })).toThrow();
});

it('should error on install if x-pack by url', () => {
expect(() => (
errorIfXPackInstall({
plugin: 'http://localhost/x-pack/x-pack-7.0.0-alpha1-SNAPSHOT.zip'
}))
).toThrow();
});

it('should not error on install if not x-pack', () => {
expect(() => (
errorIfXPackInstall({
plugin: 'foo'
}))
).not.toThrow();
});

it('should error on remove if x-pack', () => {
expect(() => errorIfXPackRemove({ plugin: 'x-pack' })).toThrow();
});

it('should not error on remove if not x-pack', () => {
expect(() => errorIfXPackRemove({ plugin: 'bar' })).not.toThrow();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
* under the License.
*/

import expect from 'expect.js';

import { isOSS } from '../is_oss';
import { isOSS } from './is_oss';

describe('is_oss', () => {
describe('x-pack installed', () => {
it('should return false', () => {
expect(isOSS()).to.be(false);
expect(isOSS()).toEqual(false);
});
});
});
4 changes: 2 additions & 2 deletions src/cli_plugin/remove/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import rimraf from 'rimraf';

export default function remove(settings, logger) {
try {
errorIfXPackRemove(settings, logger);

let stat;
try {
stat = statSync(settings.pluginPath);
} catch (e) {
errorIfXPackRemove(settings, logger);
throw new Error(`Plugin [${settings.plugin}] is not installed`);
}

Expand All @@ -39,6 +38,7 @@ export default function remove(settings, logger) {

logger.log(`Removing ${settings.plugin}...`);
rimraf.sync(settings.pluginPath);
logger.log('Plugin removal complete');
} catch (err) {
logger.error(`Unable to remove plugin because of error: "${err.message}"`);
process.exit(74); // eslint-disable-line no-process-exit
Expand Down
19 changes: 18 additions & 1 deletion src/cli_plugin/remove/remove.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import mkdirp from 'mkdirp';
import Logger from '../lib/logger';
import remove from './remove';
import { join } from 'path';
import { writeFileSync } from 'fs';
import { writeFileSync, existsSync } from 'fs';

describe('kibana cli', function () {

Expand Down Expand Up @@ -69,6 +69,23 @@ describe('kibana cli', function () {
expect(process.exit.called).toBe(true);
});

it('remove x-pack if it exists', () => {
settings.pluginPath = join(pluginDir, 'x-pack');
settings.plugin = 'x-pack';
mkdirp.sync(join(pluginDir, 'x-pack'));
expect(existsSync(settings.pluginPath)).toEqual(true);
remove(settings, logger);
expect(existsSync(settings.pluginPath)).toEqual(false);
});

it('distribution error if x-pack does not exist', () => {
settings.pluginPath = join(pluginDir, 'x-pack');
settings.plugin = 'x-pack';
expect(existsSync(settings.pluginPath)).toEqual(false);
remove(settings, logger);
expect(logger.error.getCall(0).args[0]).toMatch(/Please install the OSS-only distribution to remove X-Pack features/);
});

it('delete the specified folder.', function () {
settings.pluginPath = join(pluginDir, 'foo');
mkdirp.sync(join(pluginDir, 'foo'));
Expand Down

0 comments on commit 47555d9

Please sign in to comment.