-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6689519
commit b681a18
Showing
17 changed files
with
284 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
x-pack/legacy/plugins/painless_lab/server/lib/check_license.ts
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
x-pack/legacy/plugins/painless_lab/server/lib/license_pre_routing_factory.ts
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
x-pack/legacy/plugins/painless_lab/server/register_execute_route.ts
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
x-pack/legacy/plugins/painless_lab/server/register_license_checker.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* 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 { LicenseType } from '../../licensing/common/types'; | ||
|
||
const basicLicense: LicenseType = 'basic'; | ||
|
||
export const PLUGIN = { | ||
id: 'painlessLab', | ||
minimumLicenseType: basicLicense, | ||
getI18nName: (i18n: any): string => | ||
i18n.translate('xpack.painlessLab.appTitle', { | ||
defaultMessage: 'Painless Lab', | ||
}), | ||
}; | ||
|
||
export const API_BASE_PATH = '/api/painless_lab'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"id": "painlessLab", | ||
"version": "8.0.0", | ||
"kibanaVersion": "kibana", | ||
"requiredPlugins": [ | ||
"devTools", | ||
"licensing" | ||
], | ||
"configPath": [ | ||
"xpack", | ||
"painless_lab" | ||
], | ||
"server": true, | ||
"ui": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* 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 { PluginInitializerContext } from 'kibana/server'; | ||
import { PainlessLabServerPlugin } from './plugin'; | ||
|
||
export const plugin = (ctx: PluginInitializerContext) => { | ||
return new PainlessLabServerPlugin(ctx); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { isEsError } from './is_es_error'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 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 * as legacyElasticsearch from 'elasticsearch'; | ||
|
||
const esErrorsParent = legacyElasticsearch.errors._Abstract; | ||
|
||
export function isEsError(err: Error) { | ||
return err instanceof esErrorsParent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import { CoreSetup, Logger, Plugin, PluginInitializerContext } from 'kibana/server'; | ||
|
||
import { PLUGIN } from '../common/constants'; | ||
import { License } from './services'; | ||
import { Dependencies } from './types'; | ||
import { registerExecuteRoute } from './routes/api'; | ||
|
||
export class PainlessLabServerPlugin implements Plugin { | ||
private readonly license: License; | ||
private readonly logger: Logger; | ||
|
||
constructor({ logger }: PluginInitializerContext) { | ||
this.logger = logger.get(); | ||
this.license = new License(); | ||
} | ||
|
||
async setup({ http }: CoreSetup, { licensing }: Dependencies) { | ||
const router = http.createRouter(); | ||
|
||
this.license.setup( | ||
{ | ||
pluginId: PLUGIN.id, | ||
minimumLicenseType: PLUGIN.minimumLicenseType, | ||
defaultErrorMessage: i18n.translate('xpack.painlessLab.licenseCheckErrorMessage', { | ||
defaultMessage: 'License check failed', | ||
}), | ||
}, | ||
{ | ||
licensing, | ||
logger: this.logger, | ||
} | ||
); | ||
|
||
registerExecuteRoute({ router, license: this.license }); | ||
} | ||
|
||
start() {} | ||
|
||
stop() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
|
||
import { RouteDependencies } from '../../types'; | ||
import { API_BASE_PATH } from '../../../common/constants'; | ||
import { isEsError } from '../../lib'; | ||
|
||
const bodySchema = schema.object({ | ||
script: schema.object({ | ||
source: schema.string(), | ||
}), | ||
}); | ||
|
||
export function registerExecuteRoute({ router, license }: RouteDependencies) { | ||
router.post( | ||
{ | ||
path: `${API_BASE_PATH}/execute`, | ||
validate: { | ||
body: bodySchema, | ||
}, | ||
}, | ||
license.guardApiRoute(async (ctx, req, res) => { | ||
const body = req.body as typeof bodySchema.type; | ||
|
||
try { | ||
const callAsCurrentUser = ctx.core.elasticsearch.dataClient.callAsCurrentUser; | ||
|
||
const response = await callAsCurrentUser('scriptsPainlessExecute', { | ||
body, | ||
}); | ||
|
||
return res.ok({ | ||
body: response, | ||
}); | ||
} catch (e) { | ||
if (isEsError(e)) { | ||
return res.customError({ statusCode: e.statusCode, body: e }); | ||
} | ||
return res.internalError({ body: e }); | ||
} | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { registerExecuteRoute } from './execute'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { License } from './license'; |
Oops, something went wrong.