forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Beats Management] add get beat endpoint (elastic#20603)
* [Beats Management] Move tokens to use JWT, add more complete test suite (elastic#20317) * inital effort to move to JWT and added jest based tests on libs * assign beats tests all passing * token tests now pass * add more tests * all tests now green * fix broken test, this is beats CM not logstash 😊 * added readme * move enrollment token back to a hash * remove un-needed comment * alias lodash get to avoid confusion * isolated hash creation * inital effort to move to JWT and added jest based tests on libs * assign beats tests all passing * token tests now pass * add more tests * all tests now green * move enrollment token back to a hash * remove un-needed comment * alias lodash get to avoid confusion * isolated hash creation * Add initial efforts for backend framework adapter testing * move ES code to a DatabaseAdapter from BackendAdapter and add a TON of types for ES * re-typed * renamed types to match pattern * aditional renames * adapter tests should always just use adapterSetup(); * database now uses InternalRequest * corrected spelling of framework * fix typings * remove CRUFT * RequestOrInternal * Dont pass around request objects everywhere, just pass the user. Also, removed hapi types as they were not compatible * fix tests, add test, removed extra comment * Moved critical path code from route, to more easeley tested domain * fix auth * remove beat verification, added get beat endpoint to return configs * fix type * update createGetBeatConfigurationRoute URL * rename method * update to match PR elastic#20566 * updated lock file * fix bad merge * update TSLinting
- Loading branch information
1 parent
f0d8c97
commit d2aa659
Showing
49 changed files
with
600 additions
and
746 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
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 |
---|---|---|
@@ -1,15 +1,7 @@ | ||
# Documentation for Beats CM in x-pack kibana | ||
|
||
### Run tests (from x-pack dir) | ||
|
||
Functional tests | ||
### Run tests | ||
|
||
``` | ||
node scripts/jest.js plugins/beats --watch | ||
``` | ||
|
||
Functional API tests | ||
|
||
``` | ||
node scripts/functional_tests --config test/api_integration/config | ||
``` |
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
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
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
99 changes: 99 additions & 0 deletions
99
x-pack/plugins/beats/server/lib/adapters/famework/kibana/kibana_framework_adapter.ts
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,99 @@ | ||
/* | ||
* 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 { | ||
BackendFrameworkAdapter, | ||
FrameworkRequest, | ||
FrameworkRouteOptions, | ||
WrappableRequest, | ||
} from '../../../lib'; | ||
|
||
import { IStrictReply, Request, Server } from 'hapi'; | ||
import { internalFrameworkRequest, wrapRequest } from '../../../../utils/wrap_request'; | ||
|
||
export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter { | ||
public version: string; | ||
private server: Server; | ||
private cryptoHash: string | null; | ||
|
||
constructor(hapiServer: Server) { | ||
this.server = hapiServer; | ||
this.version = hapiServer.plugins.kibana.status.plugin.version; | ||
this.cryptoHash = null; | ||
|
||
this.validateConfig(); | ||
} | ||
|
||
public getSetting(settingPath: string) { | ||
// TODO type check server properly | ||
if (settingPath === 'xpack.beats.encryptionKey') { | ||
// @ts-ignore | ||
return this.server.config().get(settingPath) || this.cryptoHash; | ||
} | ||
// @ts-ignore | ||
return this.server.config().get(settingPath) || this.cryptoHash; | ||
} | ||
|
||
public exposeStaticDir(urlPath: string, dir: string): void { | ||
this.server.route({ | ||
handler: { | ||
directory: { | ||
path: dir, | ||
}, | ||
}, | ||
method: 'GET', | ||
path: urlPath, | ||
}); | ||
} | ||
|
||
public registerRoute<RouteRequest extends WrappableRequest, RouteResponse>( | ||
route: FrameworkRouteOptions<RouteRequest, RouteResponse> | ||
) { | ||
const wrappedHandler = (request: any, reply: IStrictReply<RouteResponse>) => | ||
route.handler(wrapRequest(request), reply); | ||
|
||
this.server.route({ | ||
config: route.config, | ||
handler: wrappedHandler, | ||
method: route.method, | ||
path: route.path, | ||
}); | ||
} | ||
|
||
public installIndexTemplate(name: string, template: {}) { | ||
return this.callWithInternalUser('indices.putTemplate', { | ||
body: template, | ||
name, | ||
}); | ||
} | ||
|
||
public async callWithInternalUser(esMethod: string, options: {}) { | ||
const { elasticsearch } = this.server.plugins; | ||
const { callWithInternalUser } = elasticsearch.getCluster('admin'); | ||
return await callWithInternalUser(esMethod, options); | ||
} | ||
|
||
public async callWithRequest(req: FrameworkRequest<Request>, ...rest: any[]) { | ||
const internalRequest = req[internalFrameworkRequest]; | ||
const { elasticsearch } = internalRequest.server.plugins; | ||
const { callWithRequest } = elasticsearch.getCluster('data'); | ||
const fields = await callWithRequest(internalRequest, ...rest); | ||
return fields; | ||
} | ||
|
||
private validateConfig() { | ||
// @ts-ignore | ||
const config = this.server.config(); | ||
const encryptionKey = config.get('xpack.beats.encryptionKey'); | ||
|
||
if (!encryptionKey) { | ||
this.server.log( | ||
'Using a default encryption key for xpack.beats.encryptionKey. It is recommended that you set xpack.beats.encryptionKey in kibana.yml with a unique token' | ||
); | ||
this.cryptoHash = 'xpack_beats_default_encryptionKey'; | ||
} | ||
} | ||
} |
Oops, something went wrong.