From 9835cef86460eedad63bb5084e2dcf652b26ff2d Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Thu, 17 Oct 2024 23:20:25 -0500 Subject: [PATCH 1/2] add suffix to database names --- .../routes/api/database/serialization.test.ts | 23 +++++++++++++++++++ .../routes/api/database/serialization.ts | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.test.ts diff --git a/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.test.ts b/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.test.ts new file mode 100644 index 0000000000000..80598a1401bb1 --- /dev/null +++ b/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.test.ts @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { serializeGeoipDatabase } from './serialization'; + +describe('serializeGeoipDatabase', () => { + it('serializes maxmind database', () => { + const licenseKey = '123'; + const createDbRequestBody = serializeGeoipDatabase({ + databaseType: 'maxmind', + databaseName: 'GeoIP2-Anonymous-IP', + maxmind: licenseKey, + }); + + expect(createDbRequestBody.name).toBe('GeoIP2-Anonymous-IP.mmdb'); + expect(createDbRequestBody.maxmind?.account_id).toBe(licenseKey); + expect(createDbRequestBody.ipinfo).toBeUndefined(); + }); +}); diff --git a/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.ts b/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.ts index 2f2c93ba5334d..d6546d3c85248 100644 --- a/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.ts +++ b/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.ts @@ -72,7 +72,7 @@ export const serializeGeoipDatabase = ({ databaseName: string; maxmind?: string; }): SerializedGeoipDatabase => { - const database = { name: databaseName } as SerializedGeoipDatabase; + const database = { name: `${databaseName}.mmdb` } as SerializedGeoipDatabase; if (databaseType === 'maxmind') { database.maxmind = { account_id: maxmind ?? '' }; From 16863b3e2ad74fe2b692d86e4ead8c5f31f9cda8 Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Fri, 18 Oct 2024 01:10:44 -0500 Subject: [PATCH 2/2] correct fix --- .../processor_form/processors/ip_location.tsx | 6 +++-- .../routes/api/database/serialization.test.ts | 23 ------------------- .../routes/api/database/serialization.ts | 2 +- 3 files changed, 5 insertions(+), 26 deletions(-) delete mode 100644 x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.test.ts diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/ip_location.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/ip_location.tsx index d1b8fbd7ea513..765c482f1c86b 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/ip_location.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/ip_location.tsx @@ -27,12 +27,14 @@ import { PropertiesField } from './common_fields/properties_field'; import type { GeoipDatabase } from '../../../../../../../common/types'; import { getTypeLabel } from '../../../../../sections/manage_processors/constants'; +const extension = '.mmdb'; + const fieldsConfig: FieldsConfig = { /* Optional field config */ database_file: { type: FIELD_TYPES.COMBO_BOX, - deserializer: to.arrayOfStrings, - serializer: (v: string[]) => (v.length ? v[0] : undefined), + deserializer: (v: unknown) => to.arrayOfStrings(v).map((str) => str?.split(extension)[0]), + serializer: (v: string[]) => (v.length ? `${v[0]}${extension}` : undefined), label: i18n.translate('xpack.ingestPipelines.pipelineEditor.ipLocationForm.databaseFileLabel', { defaultMessage: 'Database file (optional)', }), diff --git a/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.test.ts b/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.test.ts deleted file mode 100644 index 80598a1401bb1..0000000000000 --- a/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { serializeGeoipDatabase } from './serialization'; - -describe('serializeGeoipDatabase', () => { - it('serializes maxmind database', () => { - const licenseKey = '123'; - const createDbRequestBody = serializeGeoipDatabase({ - databaseType: 'maxmind', - databaseName: 'GeoIP2-Anonymous-IP', - maxmind: licenseKey, - }); - - expect(createDbRequestBody.name).toBe('GeoIP2-Anonymous-IP.mmdb'); - expect(createDbRequestBody.maxmind?.account_id).toBe(licenseKey); - expect(createDbRequestBody.ipinfo).toBeUndefined(); - }); -}); diff --git a/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.ts b/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.ts index d6546d3c85248..2f2c93ba5334d 100644 --- a/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.ts +++ b/x-pack/plugins/ingest_pipelines/server/routes/api/database/serialization.ts @@ -72,7 +72,7 @@ export const serializeGeoipDatabase = ({ databaseName: string; maxmind?: string; }): SerializedGeoipDatabase => { - const database = { name: `${databaseName}.mmdb` } as SerializedGeoipDatabase; + const database = { name: databaseName } as SerializedGeoipDatabase; if (databaseType === 'maxmind') { database.maxmind = { account_id: maxmind ?? '' };