Skip to content

Commit

Permalink
update TSLinting
Browse files Browse the repository at this point in the history
  • Loading branch information
mattapperson committed Jul 13, 2018
1 parent 28d486d commit 14534c6
Show file tree
Hide file tree
Showing 29 changed files with 110 additions and 290 deletions.
5 changes: 1 addition & 4 deletions x-pack/plugins/beats/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@

export { PLUGIN } from './plugin';
export { INDEX_NAMES } from './index_names';
export {
UNIQUENESS_ENFORCING_TYPES,
ConfigurationBlockTypes,
} from './configuration_blocks';
export { UNIQUENESS_ENFORCING_TYPES, ConfigurationBlockTypes } from './configuration_blocks';
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
type: '_doc',
};

const response = await this.database.get(
this.framework.internalUser,
params
);
const response = await this.database.get(this.framework.internalUser, params);
if (!response.found) {
return null;
}
Expand Down Expand Up @@ -155,13 +152,11 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
refresh: 'wait_for',
type: '_doc',
});
return _get<any>(response, 'items', []).map(
(item: any, resultIdx: number) => ({
idxInRequest: removals[resultIdx].idxInRequest,
result: item.update.result,
status: item.update.status,
})
);
return _get<any>(response, 'items', []).map((item: any, resultIdx: number) => ({
idxInRequest: removals[resultIdx].idxInRequest,
result: item.update.result,
status: item.update.status,
}));
}

public async assignTagsToBeats(
Expand Down Expand Up @@ -193,12 +188,10 @@ export class ElasticsearchBeatsAdapter implements CMBeatsAdapter {
refresh: 'wait_for',
type: '_doc',
});
return _get<any>(response, 'items', []).map(
(item: any, resultIdx: any) => ({
idxInRequest: assignments[resultIdx].idxInRequest,
result: item.update.result,
status: item.update.status,
})
);
return _get<any>(response, 'items', []).map((item: any, resultIdx: any) => ({
idxInRequest: assignments[resultIdx].idxInRequest,
result: item.update.result,
status: item.update.status,
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,15 @@ export class MemoryBeatsAdapter implements CMBeatsAdapter {
): Promise<BeatsTagAssignment[]> {
const beatIds = removals.map(r => r.beatId);

const response = this.beatsDB
.filter(beat => beatIds.includes(beat.id))
.map(beat => {
const tagData = removals.find(r => r.beatId === beat.id);
if (tagData) {
if (beat.tags) {
beat.tags = beat.tags.filter(tag => tag !== tagData.tag);
}
const response = this.beatsDB.filter(beat => beatIds.includes(beat.id)).map(beat => {
const tagData = removals.find(r => r.beatId === beat.id);
if (tagData) {
if (beat.tags) {
beat.tags = beat.tags.filter(tag => tag !== tagData.tag);
}
return beat;
});
}
return beat;
});

return response.map<any>((item: CMBeat, resultIdx: number) => ({
idxInRequest: removals[resultIdx].idxInRequest,
Expand All @@ -100,9 +98,7 @@ export class MemoryBeatsAdapter implements CMBeatsAdapter {
if (!beat.tags) {
beat.tags = [];
}
const nonExistingTags = tags.filter(
(t: string) => beat.tags && !beat.tags.includes(t)
);
const nonExistingTags = tags.filter((t: string) => beat.tags && !beat.tags.includes(t));

if (nonExistingTags.length > 0) {
beat.tags = beat.tags.concat(nonExistingTags);
Expand All @@ -111,12 +107,10 @@ export class MemoryBeatsAdapter implements CMBeatsAdapter {
return beat;
});

return assignments.map<any>(
(item: BeatsTagAssignment, resultIdx: number) => ({
idxInRequest: assignments[resultIdx].idxInRequest,
result: 'updated',
status: 200,
})
);
return assignments.map<any>((item: BeatsTagAssignment, resultIdx: number) => ({
idxInRequest: assignments[resultIdx].idxInRequest,
result: 'updated',
status: 200,
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ contractTests('Kibana Database Adapter', {
return await es.cleanup();
},
adapterSetup: () => {
return new KibanaDatabaseAdapter(kbnServer.server.plugins
.elasticsearch as DatabaseKbnESPlugin);
return new KibanaDatabaseAdapter(kbnServer.server.plugins.elasticsearch as DatabaseKbnESPlugin);
},
});
34 changes: 7 additions & 27 deletions x-pack/plugins/beats/server/lib/adapters/database/adapter_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
*/
import { FrameworkRequest, FrameworkUser } from '../framework/adapter_types';
export interface DatabaseAdapter {
putTemplate(
user: FrameworkUser,
params: DatabasePutTemplateParams
): Promise<any>;
putTemplate(user: FrameworkUser, params: DatabasePutTemplateParams): Promise<any>;
get<Source>(
user: FrameworkUser,
params: DatabaseGetParams
Expand All @@ -25,27 +22,17 @@ export interface DatabaseAdapter {
user: FrameworkUser,
params: DatabaseDeleteDocumentParams
): Promise<DatabaseDeleteDocumentResponse>;
mget<T>(
user: FrameworkUser,
params: DatabaseMGetParams
): Promise<DatabaseMGetResponse<T>>;
mget<T>(user: FrameworkUser, params: DatabaseMGetParams): Promise<DatabaseMGetResponse<T>>;
bulk(
user: FrameworkUser,
params: DatabaseBulkIndexDocumentsParams
): Promise<DatabaseBulkResponse>;
search<T>(
user: FrameworkUser,
params: DatabaseSearchParams
): Promise<DatabaseSearchResponse<T>>;
search<T>(user: FrameworkUser, params: DatabaseSearchParams): Promise<DatabaseSearchResponse<T>>;
}

export interface DatabaseKbnESCluster {
callWithInternalUser(esMethod: string, options: {}): Promise<any>;
callWithRequest(
req: FrameworkRequest,
esMethod: string,
options: {}
): Promise<any>;
callWithRequest(req: FrameworkRequest, esMethod: string, options: {}): Promise<any>;
}

export interface DatabaseKbnESPlugin {
Expand Down Expand Up @@ -142,14 +129,11 @@ export interface DatabaseBulkResponse {
took: number;
errors: boolean;
items: Array<
| DatabaseDeleteDocumentResponse
| DatabaseIndexDocumentResponse
| DatabaseUpdateDocumentResponse
DatabaseDeleteDocumentResponse | DatabaseIndexDocumentResponse | DatabaseUpdateDocumentResponse
>;
}

export interface DatabaseBulkIndexDocumentsParams
extends DatabaseGenericParams {
export interface DatabaseBulkIndexDocumentsParams extends DatabaseGenericParams {
waitForActiveShards?: string;
refresh?: DatabaseRefresh;
routing?: string;
Expand Down Expand Up @@ -299,11 +283,7 @@ export interface DatabaseGetParams extends DatabaseGenericParams {

export type DatabaseNameList = string | string[] | boolean;
export type DatabaseRefresh = boolean | 'true' | 'false' | 'wait_for' | '';
export type DatabaseVersionType =
| 'internal'
| 'external'
| 'external_gte'
| 'force';
export type DatabaseVersionType = 'internal' | 'external' | 'external_gte' | 'force';
export type ExpandWildcards = 'open' | 'closed' | 'none' | 'all';
export type DefaultOperator = 'AND' | 'OR';
export type DatabaseConflicts = 'abort' | 'proceed';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export class KibanaDatabaseAdapter implements DatabaseAdapter {
constructor(kbnElasticSearch: DatabaseKbnESPlugin) {
this.es = kbnElasticSearch.getCluster('admin');
}
public async putTemplate(
user: FrameworkUser,
params: DatabasePutTemplateParams
): Promise<any> {
public async putTemplate(user: FrameworkUser, params: DatabasePutTemplateParams): Promise<any> {
const callES = this.getCallType(user);
const result = await callES('indices.putTemplate', params);
return result;
Expand All @@ -59,10 +56,7 @@ export class KibanaDatabaseAdapter implements DatabaseAdapter {
// todo
}

public async bulk(
user: FrameworkUser,
params: DatabaseBulkIndexDocumentsParams
): Promise<any> {
public async bulk(user: FrameworkUser, params: DatabaseBulkIndexDocumentsParams): Promise<any> {
const callES = this.getCallType(user);
const result = await callES('bulk', params);
return result;
Expand All @@ -76,10 +70,7 @@ export class KibanaDatabaseAdapter implements DatabaseAdapter {
const result = await callES('create', params);
return result;
}
public async index<T>(
user: FrameworkUser,
params: DatabaseIndexDocumentParams<T>
): Promise<any> {
public async index<T>(user: FrameworkUser, params: DatabaseIndexDocumentParams<T>): Promise<any> {
const callES = this.getCallType(user);
const result = await callES('index', params);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
} from '../../../lib';

import { IStrictReply, Request, Server } from 'hapi';
import {
internalFrameworkRequest,
wrapRequest,
} from '../../../../utils/wrap_request';
import { internalFrameworkRequest, wrapRequest } from '../../../../utils/wrap_request';

export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter {
public version: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ export class TestingBackendFrameworkAdapter implements BackendFrameworkAdapter {
return await api(options);
}

public async callWithRequest(
req: FrameworkRequest<Request>,
esMethod: string,
options: {}
) {
public async callWithRequest(req: FrameworkRequest<Request>, esMethod: string, options: {}) {
const api = get<any>(this.client, esMethod);

api(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export interface FrameworkRouteOptions<
config?: {};
}

export type FrameworkRouteHandler<
RouteRequest extends FrameworkWrappableRequest,
RouteResponse
> = (request: FrameworkRequest<RouteRequest>, reply: any) => void;
export type FrameworkRouteHandler<RouteRequest extends FrameworkWrappableRequest, RouteResponse> = (
request: FrameworkRequest<RouteRequest>,
reply: any
) => void;

export interface FrameworkWrappableRequest<
Payload = any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ export class KibanaBackendFrameworkAdapter implements BackendFrameworkAdapter {
});
}

public registerRoute<
RouteRequest extends FrameworkWrappableRequest,
RouteResponse
>(route: FrameworkRouteOptions<RouteRequest, RouteResponse>) {
const wrappedHandler = (request: any, reply: any) =>
route.handler(wrapRequest(request), reply);
public registerRoute<RouteRequest extends FrameworkWrappableRequest, RouteResponse>(
route: FrameworkRouteOptions<RouteRequest, RouteResponse>
) {
const wrappedHandler = (request: any, reply: any) => route.handler(wrapRequest(request), reply);

this.server.route({
handler: wrappedHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ export class TestingBackendFrameworkAdapter implements BackendFrameworkAdapter {
// not yet testable
}

public registerRoute<
RouteRequest extends FrameworkWrappableRequest,
RouteResponse
>(route: FrameworkRouteOptions<RouteRequest, RouteResponse>) {
public registerRoute<RouteRequest extends FrameworkWrappableRequest, RouteResponse>(
route: FrameworkRouteOptions<RouteRequest, RouteResponse>
) {
// not yet testable
}

Expand All @@ -68,11 +67,7 @@ export class TestingBackendFrameworkAdapter implements BackendFrameworkAdapter {
return await api(options);
}

public async callWithRequest(
req: FrameworkRequest,
esMethod: string,
options: {}
) {
public async callWithRequest(req: FrameworkRequest, esMethod: string, options: {}) {
const api = get<any>(this.client, esMethod);

api(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ export interface TokenEnrollmentData {
export interface CMTokensAdapter {
deleteEnrollmentToken(enrollmentToken: string): Promise<void>;
getEnrollmentToken(enrollmentToken: string): Promise<TokenEnrollmentData>;
upsertTokens(
user: FrameworkUser,
tokens: TokenEnrollmentData[]
): Promise<TokenEnrollmentData[]>;
upsertTokens(user: FrameworkUser, tokens: TokenEnrollmentData[]): Promise<TokenEnrollmentData[]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import { flatten, get } from 'lodash';
import { INDEX_NAMES } from '../../../../common/constants';
import { DatabaseAdapter } from '../database/adapter_types';
import {
BackendFrameworkAdapter,
FrameworkUser,
} from '../framework/adapter_types';
import { BackendFrameworkAdapter, FrameworkUser } from '../framework/adapter_types';
import { CMTokensAdapter, TokenEnrollmentData } from './adapter_types';

export class ElasticsearchTokensAdapter implements CMTokensAdapter {
Expand All @@ -32,28 +29,19 @@ export class ElasticsearchTokensAdapter implements CMTokensAdapter {
await this.database.delete(this.framework.internalUser, params);
}

public async getEnrollmentToken(
tokenString: string
): Promise<TokenEnrollmentData> {
public async getEnrollmentToken(tokenString: string): Promise<TokenEnrollmentData> {
const params = {
id: `enrollment_token:${tokenString}`,
ignore: [404],
index: INDEX_NAMES.BEATS,
type: '_doc',
};

const response = await this.database.get(
this.framework.internalUser,
params
);
const tokenDetails = get<TokenEnrollmentData>(
response,
'_source.enrollment_token',
{
expires_on: '0',
token: null,
}
);
const response = await this.database.get(this.framework.internalUser, params);
const tokenDetails = get<TokenEnrollmentData>(response, '_source.enrollment_token', {
expires_on: '0',
token: null,
});

// Elasticsearch might return fast if the token is not found. OR it might return fast
// if the token *is* found. Either way, an attacker could using a timing attack to figure
Expand All @@ -65,10 +53,7 @@ export class ElasticsearchTokensAdapter implements CMTokensAdapter {
);
}

public async upsertTokens(
user: FrameworkUser,
tokens: TokenEnrollmentData[]
) {
public async upsertTokens(user: FrameworkUser, tokens: TokenEnrollmentData[]) {
const body = flatten(
tokens.map(token => [
{ index: { _id: `enrollment_token:${token.token}` } },
Expand Down
Loading

0 comments on commit 14534c6

Please sign in to comment.