mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[plugin installer] Allow x-pack removal if it exists (#19327)
* [plugin installer] Allow x-pack removal if it exists * remove lingering exit
This commit is contained in:
parent
5148dbf6f5
commit
c8216de9d5
6 changed files with 78 additions and 86 deletions
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* 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 expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import { errorIfXPackInstall, errorIfXPackRemove } from '../error_if_x_pack';
|
||||
|
||||
describe('error_if_xpack', () => {
|
||||
const logger = {
|
||||
error: sinon.stub()
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
sinon.stub(process, 'exit');
|
||||
});
|
||||
|
||||
it('should exit on install if x-pack by name', () => {
|
||||
errorIfXPackInstall({
|
||||
plugin: 'x-pack'
|
||||
}, logger);
|
||||
expect(process.exit.called).to.be(true);
|
||||
});
|
||||
|
||||
it('should exit on install if x-pack by url', () => {
|
||||
errorIfXPackInstall({
|
||||
plugin: ' http://localhost/x-pack/x-pack-7.0.0-alpha1-SNAPSHOT.zip'
|
||||
}, logger);
|
||||
expect(process.exit.called).to.be(true);
|
||||
});
|
||||
|
||||
it('should not exit on install if not x-pack', () => {
|
||||
errorIfXPackInstall({
|
||||
plugin: 'foo'
|
||||
}, logger);
|
||||
expect(process.exit.called).to.be(false);
|
||||
});
|
||||
|
||||
it('should exit on remove if x-pack', () => {
|
||||
errorIfXPackRemove({
|
||||
plugin: 'x-pack'
|
||||
}, logger);
|
||||
expect(process.exit.called).to.be(true);
|
||||
});
|
||||
|
||||
it('should not exit on remove if not x-pack', () => {
|
||||
errorIfXPackRemove({
|
||||
plugin: 'bar'
|
||||
}, logger);
|
||||
expect(process.exit.called).to.be(false);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.exit.restore();
|
||||
});
|
||||
});
|
|
@ -23,28 +23,26 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
51
src/cli_plugin/lib/error_if_x_pack.test.js
Normal file
51
src/cli_plugin/lib/error_if_x_pack.test.js
Normal file
|
@ -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();
|
||||
});
|
||||
});
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -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`);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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 () {
|
||||
|
||||
|
@ -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'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue