-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest pipelines] Use human-readable database names in IP location p…
…rocessor form (#197413) Fixes #196768 ## Summary This PR adds human-readable labels in the Database field in the IP location processor form. https://github.com/user-attachments/assets/94fb5e22-ccae-4bff-b6fb-92ae0cf9449c
- Loading branch information
1 parent
66b2447
commit 9c92b52
Showing
6 changed files
with
132 additions
and
10 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
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
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/ingest_pipelines/public/application/sections/manage_processors/utils.test.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,60 @@ | ||
/* | ||
* 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 { getDatabaseValue, getDatabaseText } from './utils'; | ||
|
||
describe('getDatabaseValue', () => { | ||
it('should return the value for a given database text for maxmind', () => { | ||
const databaseText = 'GeoIP2 City'; | ||
const result = getDatabaseValue(databaseText, 'maxmind'); | ||
expect(result).toBe('GeoIP2-City'); | ||
}); | ||
|
||
it('should return the value for a given database text for ipinfo', () => { | ||
const databaseText = 'Free IP to ASN'; | ||
const result = getDatabaseValue(databaseText, 'ipinfo'); | ||
expect(result).toBe('asn'); | ||
}); | ||
|
||
it('should return undefined if the database text is not found', () => { | ||
const databaseText = 'Unknown Database'; | ||
const result = getDatabaseValue(databaseText); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should return the value when no type is provided and the database text is found in any option', () => { | ||
const databaseText = 'ASN'; | ||
const result = getDatabaseValue(databaseText); | ||
expect(result).toBe('standard_asn'); | ||
}); | ||
}); | ||
|
||
describe('getDatabaseText', () => { | ||
it('should return the human-readable name for a given database value for maxmind', () => { | ||
const databaseValue = 'GeoIP2-City'; | ||
const result = getDatabaseText(databaseValue, 'maxmind'); | ||
expect(result).toBe('GeoIP2 City'); | ||
}); | ||
|
||
it('should return the human-readable name for a given database value for ipinfo', () => { | ||
const databaseValue = 'asn'; | ||
const result = getDatabaseText(databaseValue, 'ipinfo'); | ||
expect(result).toBe('Free IP to ASN'); | ||
}); | ||
|
||
it('should return undefined if the database value is not found', () => { | ||
const databaseValue = 'unknown-value'; | ||
const result = getDatabaseText(databaseValue); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should return the human-readable name when no type is provided and the value is found in any option', () => { | ||
const databaseValue = 'standard_location'; | ||
const result = getDatabaseText(databaseValue); | ||
expect(result).toBe('IP Geolocation'); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/ingest_pipelines/public/application/sections/manage_processors/utils.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,44 @@ | ||
/* | ||
* 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 { DatabaseType, DatabaseNameOption } from '../../../../common/types'; | ||
import { GEOIP_NAME_OPTIONS, IPINFO_NAME_OPTIONS } from './constants'; | ||
|
||
const getDatabaseNameOptions = (type?: DatabaseType): DatabaseNameOption[] => { | ||
switch (type) { | ||
case 'maxmind': | ||
return GEOIP_NAME_OPTIONS; | ||
case 'ipinfo': | ||
return IPINFO_NAME_OPTIONS; | ||
case undefined: | ||
return [...GEOIP_NAME_OPTIONS, ...IPINFO_NAME_OPTIONS]; | ||
default: | ||
return []; | ||
} | ||
}; | ||
|
||
/** | ||
* Returns the value/id of the database, if it exists. | ||
* | ||
* @param databaseText The human-readable name of the database | ||
* @param type If specified, searches only in the database name options for this type | ||
*/ | ||
export const getDatabaseValue = (databaseText: string, type?: DatabaseType): string | undefined => { | ||
const options = getDatabaseNameOptions(type); | ||
return options.find((opt) => opt.text === databaseText)?.value; | ||
}; | ||
|
||
/** | ||
* Returns the human-readable name of the database, if it exists. | ||
* | ||
* @param databaseText The id/value of the database | ||
* @param type If specified, searches only in the database name options for this type | ||
*/ | ||
export const getDatabaseText = (databaseValue: string, type?: DatabaseType): string | undefined => { | ||
const options = getDatabaseNameOptions(type); | ||
return options.find((opt) => opt.value === databaseValue)?.text; | ||
}; |