Skip to content

Commit

Permalink
- Server to NP
Browse files Browse the repository at this point in the history
- Slight update to filepicker style (center it)
  • Loading branch information
jloleysens committed Nov 28, 2019
1 parent cc3717d commit 5e0548a
Show file tree
Hide file tree
Showing 23 changed files with 345 additions and 204 deletions.
38 changes: 0 additions & 38 deletions x-pack/legacy/plugins/license_management/index.js

This file was deleted.

32 changes: 32 additions & 0 deletions x-pack/legacy/plugins/license_management/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { resolve } from 'path';
import { PLUGIN } from './common/constants';
import { Legacy } from '../../../../kibana';
import { plugin } from './server/np_ready';

export function licenseManagement(kibana: any) {
return new kibana.Plugin({
id: PLUGIN.ID,
configPrefix: 'xpack.license_management',
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch'],
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/np_ready/application/index.scss'),
managementSections: ['plugins/license_management/legacy'],
},
init: (server: Legacy.Server) => {
plugin({} as any).setup(server.newPlatform.setup.core, {
...server.newPlatform.setup.plugins,
__LEGACY: {
xpackMain: server.plugins.xpack_main,
elasticsearch: server.plugins.elasticsearch,
},
});
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { HttpSetup } from 'src/core/public';

export function putLicense(http: HttpSetup, license: any, acknowledge: any) {
export function putLicense(http: HttpSetup, license: any, acknowledge: boolean) {
return http.put('/api/license', {
query: {
acknowledge: acknowledge ? 'true' : '',
Expand All @@ -19,7 +19,7 @@ export function putLicense(http: HttpSetup, license: any, acknowledge: any) {
});
}

export function startBasic(http: HttpSetup, acknowledge: any) {
export function startBasic(http: HttpSetup, acknowledge: boolean) {
return http.post('/api/license/start_basic', {
query: {
acknowledge: acknowledge ? 'true' : '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,20 @@ export class UploadLicense extends React.PureComponent {
</EuiText>
<EuiSpacer />
<EuiForm isInvalid={!!this.errorMessage()} error={this.errorMessage()}>
<EuiText>
<EuiFilePicker
id="licenseFile"
initialPromptText={<FormattedMessage
id="xpack.licenseMgmt.uploadLicense.selectLicenseFileDescription"
defaultMessage="Select or drag your license file"
/>}
onChange={this.handleFile}
/>
</EuiText>
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<EuiText>
<EuiFilePicker
id="licenseFile"
initialPromptText={<FormattedMessage
id="xpack.licenseMgmt.uploadLicense.selectLicenseFileDescription"
defaultMessage="Select or drag your license file"
/>}
onChange={this.handleFile}
/>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
<TelemetryOptIn
ref={ref => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const uploadLicense = (licenseString, currentLicenseType, acknowledge) =>
));
}
try {
const response = await putLicense(licenseString, acknowledge);
const response = await putLicense(services.http, licenseString, acknowledge);
await dispatchFromResponse(response, dispatch, currentLicenseType, newLicenseType, services);
} catch (err) {
const message = (err.responseJSON && err.responseJSON.error.reason) ? err.responseJSON.error.reason : i18n.translate(
Expand Down
27 changes: 0 additions & 27 deletions x-pack/legacy/plugins/license_management/server/lib/license.js

This file was deleted.

28 changes: 0 additions & 28 deletions x-pack/legacy/plugins/license_management/server/lib/start_basic.js

This file was deleted.

38 changes: 0 additions & 38 deletions x-pack/legacy/plugins/license_management/server/lib/start_trial.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { putLicense } from '../../../lib/license';
import { PluginInitializerContext } from 'src/core/server';
import { LicenseManagementServerPlugin } from './plugin';

export function registerLicenseRoute(router, xpackInfo) {
router.put('', (request) => {
return putLicense(request, xpackInfo);
});
}
export const plugin = (ctx: PluginInitializerContext) => new LicenseManagementServerPlugin();
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { KibanaRequest } from 'src/core/server';
import { ElasticsearchPlugin } from '../../../../../../../src/legacy/core_plugins/elasticsearch';
const getLicensePath = (acknowledge: boolean) =>
`/_license${acknowledge ? '?acknowledge=true' : ''}`;

export async function putLicense(
req: KibanaRequest<any, { acknowledge: string }, any>,
elasticsearch: ElasticsearchPlugin,
xpackInfo: any
) {
const { acknowledge } = req.query;
const { callWithRequest } = elasticsearch.getCluster('admin');
const options = {
method: 'POST',
path: getLicensePath(Boolean(acknowledge)),
body: req.body,
};
try {
const response = await callWithRequest(req as any, 'transport.request', options);
const { acknowledged, license_status: licenseStatus } = response;
if (acknowledged && licenseStatus === 'valid') {
await xpackInfo.refreshNow();
}
return response;
} catch (error) {
return error.body;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { wrapCustomError } from '../../../../server/lib/create_router/error_wrappers';

export async function getPermissions(req, xpackInfo) {
if (!xpackInfo) {
// xpackInfo is updated via poll, so it may not be available until polling has begun.
// In this rare situation, tell the client the service is temporarily unavailable.
throw wrapCustomError(new Error('Security info unavailable'), 503);
}
import { KibanaRequest } from 'src/core/server';
import { ElasticsearchPlugin } from '../../../../../../../src/legacy/core_plugins/elasticsearch';

export async function getPermissions(
req: KibanaRequest,
elasticsearch: ElasticsearchPlugin,
xpackInfo: any
) {
const securityInfo = xpackInfo && xpackInfo.isAvailable() && xpackInfo.feature('security');
if (!securityInfo || !securityInfo.isAvailable() || !securityInfo.isEnabled()) {
// If security isn't enabled, let the user use license management
Expand All @@ -21,22 +20,21 @@ export async function getPermissions(req, xpackInfo) {
};
}

const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('admin');
const { callWithRequest } = elasticsearch.getCluster('admin');
const options = {
method: 'POST',
path: '/_security/user/_has_privileges',
body: {
cluster: ['manage'], // License management requires "manage" cluster privileges
}
},
};

try {
const response = await callWithRequest(req, 'transport.request', options);
const response = await callWithRequest(req as any, 'transport.request', options);
return {
hasPermission: response.cluster.manage,
};
} catch (error) {
return error.body;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { KibanaRequest } from 'kibana/server';
import { ElasticsearchPlugin } from '../../../../../../../src/legacy/core_plugins/elasticsearch';

const getStartBasicPath = (acknowledge: boolean) =>
`/_license/start_basic${acknowledge ? '?acknowledge=true' : ''}`;

export async function startBasic(
req: KibanaRequest<any, { acknowledge: string }, any>,
elasticsearch: ElasticsearchPlugin,
xpackInfo: any
) {
const { acknowledge } = req.query;
const { callWithRequest } = elasticsearch.getCluster('admin');
const options = {
method: 'POST',
path: getStartBasicPath(Boolean(acknowledge)),
};
try {
const response = await callWithRequest(req as any, 'transport.request', options);
const { basic_was_started: basicWasStarted } = response;
if (basicWasStarted) {
await xpackInfo.refreshNow();
}
return response;
} catch (error) {
return error.body;
}
}
Loading

0 comments on commit 5e0548a

Please sign in to comment.