Skip to content

Commit

Permalink
fix bad rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mattapperson authored and justinkambic committed Jul 23, 2018
1 parent 4e96aea commit 0f30124
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 240 deletions.
23 changes: 12 additions & 11 deletions x-pack/plugins/beats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import Joi from 'joi';
import { PLUGIN } from './common/constants';
import { initServerWithKibana } from './server/kibana.index';

const DEFAULT_ENROLLMENT_TOKENS_TTL_S = 10 * 60; // 10 minutes

export const config = Joi.object({
enabled: Joi.boolean().default(true),
encryptionKey: Joi.string(),
enrollmentTokensTtlInSeconds: Joi.number()
.integer()
.min(1)
.default(DEFAULT_ENROLLMENT_TOKENS_TTL_S),
}).default();
export const configPrefix = 'xpack.beats';

export function beats(kibana: any) {
return new kibana.Plugin({
config: () =>
Joi.object({
enabled: Joi.boolean().default(true),
encryptionKey: Joi.string(),
enrollmentTokensTtlInSeconds: Joi.number()
.integer()
.min(1)
.default(DEFAULT_ENROLLMENT_TOKENS_TTL_S),
}).default(),
configPrefix: 'xpack.beats',
config: () => config,
configPrefix,
id: PLUGIN.ID,
require: ['kibana', 'elasticsearch', 'xpack_main'],
init(server: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface CMBeatsAdapter {
get(id: string): any;
getAll(user: FrameworkUser): any;
getWithIds(user: FrameworkUser, beatIds: string[]): any;
verifyBeats(user: FrameworkUser, beatIds: string[]): any;
removeTagsFromBeats(
user: FrameworkUser,
removals: BeatsTagAssignment[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { flatten, get as _get, omit } from 'lodash';
import moment from 'moment';
import { INDEX_NAMES } from '../../../../common/constants';
import { CMBeat } from '../../../../common/domain_types';
import { DatabaseAdapter } from '../database/adapter_types';
Expand Down Expand Up @@ -87,33 +86,6 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
.map((b: any) => b._source.beat);
}

public async verifyBeats(user: FrameworkUser, beatIds: string[]) {
if (!Array.isArray(beatIds) || beatIds.length === 0) {
return [];
}

const verifiedOn = moment().toJSON();
const body = flatten(
beatIds.map(beatId => [
{ update: { _id: `beat:${beatId}` } },
{ doc: { beat: { verified_on: verifiedOn } } },
])
);

const response = await this.database.bulk(user, {
_sourceInclude: ['beat.id', 'beat.verified_on'],
body,
index: INDEX_NAMES.BEATS,
refresh: 'wait_for',
type: '_doc',
});

return _get(response, 'items', []).map(b => ({
..._get(b, 'update.get._source.beat', {}),
updateStatus: _get(b, 'update.result', 'unknown error'),
}));
}

public async getAll(user: FrameworkUser) {
const params = {
index: INDEX_NAMES.BEATS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { omit } from 'lodash';
import moment from 'moment';

import { CMBeat } from '../../../../common/domain_types';
import { FrameworkUser } from '../framework/adapter_types';
Expand Down Expand Up @@ -39,22 +38,6 @@ export class MemoryBeatsAdapter implements CMBeatsAdapter {
return this.beatsDB.filter(beat => beatIds.includes(beat.id));
}

public async verifyBeats(user: FrameworkUser, beatIds: string[]) {
if (!Array.isArray(beatIds) || beatIds.length === 0) {
return [];
}

const verifiedOn = moment().toJSON();

this.beatsDB.forEach((beat, i) => {
if (beatIds.includes(beat.id)) {
this.beatsDB[i].verified_on = verifiedOn;
}
});

return this.beatsDB.filter(beat => beatIds.includes(beat.id));
}

public async getAll(user: FrameworkUser) {
return this.beatsDB.map((beat: any) => omit(beat, ['access_token']));
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

// @ts-ignore
import { createEsTestCluster } from '@kbn/test';
import { config as beatsPluginConfig, configPrefix } from '../../../../..';
// @ts-ignore
import * as kbnTestServer from '../../../../../../../../src/test_utils/kbn_server';
import { config as beatsPluginConfig, configPrefix } from '../../../../../index';
import { KibanaBackendFrameworkAdapter } from '../kibana_framework_adapter';
import { contractTests } from './test_contract';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe('Beats Domain Lib', () => {

expect(beatsDB.length).toEqual(1);
expect(beatsDB[0]).toHaveProperty('host_ip');
expect(beatsDB[0]).toHaveProperty('verified_on');

expect(accessToken).toEqual(beatsDB[0].access_token);

Expand Down
4 changes: 0 additions & 4 deletions x-pack/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@
version "1.2.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-1.2.0.tgz#81a6731ce4df43619e5c8c945383b3e62a89ea86"

"@types/expect.js@^0.3.29":
version "0.3.29"
resolved "https://registry.yarnpkg.com/@types/expect.js/-/expect.js-0.3.29.tgz#28dd359155b84b8ecb094afc3f4b74c3222dca3b"

"@types/form-data@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@types/form-data/-/form-data-2.2.1.tgz#ee2b3b8eaa11c0938289953606b745b738c54b1e"
Expand Down

0 comments on commit 0f30124

Please sign in to comment.