Skip to content

Commit

Permalink
Added feature flag to be enabled in the position off along with warni…
Browse files Browse the repository at this point in the history
…ng message and a few import fix ups
  • Loading branch information
FrankHassanabad committed Apr 28, 2020
1 parent 06c9d9a commit 3cb4c27
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import * as t from 'io-ts';

export const listItemIndexExistSchema = t.type({
lists_index: t.boolean,
lists_items_index: t.boolean,
list_index: t.boolean,
list_item_index: t.boolean,
});

export type ListItemIndexExistSchema = t.TypeOf<typeof listItemIndexExistSchema>;
2 changes: 1 addition & 1 deletion x-pack/plugins/lists/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { TypeOf, schema } from '@kbn/config-schema';

export const ConfigSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
enabled: schema.boolean({ defaultValue: false }),
listIndex: schema.string({ defaultValue: '.lists' }),
listItemIndex: schema.string({ defaultValue: '.items' }),
});
Expand Down
19 changes: 10 additions & 9 deletions x-pack/plugins/lists/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ export class ListPlugin {
.pipe(first())
.toPromise();

if (config.enabled) {
this.spaces = plugins.spaces?.spacesService;
this.config = config;
this.elasticsearch = core.elasticsearch;
this.security = plugins.security;
this.logger.error(
'You have activated the lists values feature flag which is NOT currently supported for Elastic Security! You should turn this feature flag off immediately by un-setting "xpack.lists.enabled: true" in kibana.yml and restarting Kibana'
);
this.spaces = plugins.spaces?.spacesService;
this.config = config;
this.elasticsearch = core.elasticsearch;
this.security = plugins.security;

core.http.registerRouteHandlerContext('lists', this.createRouteHandlerContext());
const router = core.http.createRouter();
initRoutes(router);
}
core.http.registerRouteHandlerContext('lists', this.createRouteHandlerContext());
const router = core.http.createRouter();
initRoutes(router);
}

public start(): void {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/lists/server/routes/create_list_index_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export const createListIndexRoute = (router: IRouter): void => {

try {
const lists = getListClient(context);
const listsIndexExists = await lists.getListIndexExists();
const listIndexExists = await lists.getListIndexExists();
const listItemIndexExists = await lists.getListItemIndexExists();

if (listsIndexExists && listItemIndexExists) {
if (listIndexExists && listItemIndexExists) {
return siemResponse.error({
body: `index: "${lists.getListIndex()}" and "${lists.getListItemIndex()}" already exists`,
statusCode: 409,
Expand All @@ -56,7 +56,7 @@ export const createListIndexRoute = (router: IRouter): void => {
await lists.setListItemTemplate();
}

if (!listsIndexExists) {
if (!listIndexExists) {
await lists.createListBootStrapIndex();
}
if (!listItemIndexExists) {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/lists/server/routes/delete_list_index_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ export const deleteListIndexRoute = (router: IRouter): void => {

try {
const lists = getListClient(context);
const listsIndexExists = await lists.getListIndexExists();
const listIndexExists = await lists.getListIndexExists();
const listItemIndexExists = await lists.getListItemIndexExists();

if (!listsIndexExists && !listItemIndexExists) {
if (!listIndexExists && !listItemIndexExists) {
return siemResponse.error({
body: `index: "${lists.getListIndex()}" and "${lists.getListItemIndex()}" does not exist`,
statusCode: 404,
});
} else {
if (listsIndexExists) {
if (listIndexExists) {
await lists.deleteListIndex();
}
if (listItemIndexExists) {
Expand Down
15 changes: 8 additions & 7 deletions x-pack/plugins/lists/server/routes/import_list_item_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
} from '../siem_server_deps';
import {
ImportListItemSchema,
acknowledgeSchema,
importListItemQuerySchema,
importListItemSchema,
listSchema,
} from '../../common/schemas';

import { getListClient } from '.';
Expand Down Expand Up @@ -59,11 +59,12 @@ export const importListItemRoute = (router: IRouter): void => {
type: list.type,
});

return response.accepted({
body: {
acknowledged: true,
},
});
const [validated, errors] = validate(list, listSchema);
if (errors != null) {
return siemResponse.error({ body: errors, statusCode: 500 });
} else {
return response.ok({ body: validated ?? {} });
}
} else if (type != null) {
const { filename } = request.body.file.hapi;
// TODO: Should we prevent the same file from being uploaded multiple times?
Expand All @@ -80,7 +81,7 @@ export const importListItemRoute = (router: IRouter): void => {
stream: request.body.file,
type: list.type,
});
const [validated, errors] = validate({ acknowledged: true }, acknowledgeSchema);
const [validated, errors] = validate(list, listSchema);
if (errors != null) {
return siemResponse.error({ body: errors, statusCode: 500 });
} else {
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/lists/server/routes/read_list_index_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ export const readListIndexRoute = (router: IRouter): void => {

try {
const lists = getListClient(context);
const listsIndexExists = await lists.getListIndexExists();
const listIndexExists = await lists.getListIndexExists();
const listItemIndexExists = await lists.getListItemIndexExists();

if (listsIndexExists || listItemIndexExists) {
if (listIndexExists || listItemIndexExists) {
const [validated, errors] = validate(
{ lists_index: listsIndexExists, lists_items_index: listItemIndexExists },
{ list_index: listIndexExists, lists_item_index: listItemIndexExists },
listItemIndexExistSchema
);
if (errors != null) {
return siemResponse.error({ body: errors, statusCode: 500 });
} else {
return response.ok({ body: validated ?? {} });
}
} else if (!listsIndexExists && listItemIndexExists) {
} else if (!listIndexExists && listItemIndexExists) {
return siemResponse.error({
body: `index ${lists.getListIndex()} does not exist`,
statusCode: 404,
});
} else if (!listItemIndexExists && listsIndexExists) {
} else if (!listItemIndexExists && listIndexExists) {
return siemResponse.error({
body: `index ${lists.getListItemIndex()} does not exist`,
statusCode: 404,
Expand Down

0 comments on commit 3cb4c27

Please sign in to comment.