[8.x] [Automatic Import] Fix UI validation for Integration and Datastream name (#204943) (#205020)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Automatic Import] Fix UI validation for Integration and Datastream
name (#204943)](https://github.com/elastic/kibana/pull/204943)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Bharat
Pasupula","email":"123897612+bhapas@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-12-19T22:22:20Z","message":"[Automatic
Import] Fix UI validation for Integration and Datastream name
(#204943)\n\n## Release Note\r\n\r\nFixes Integration and Datastream
name validation\r\n\r\n##
Summary\r\n\r\nhttps://github.com/elastic/kibana/pull/204409 implemented
backend\r\nvalidation for integration and datastream names and this PR
fixes\r\nallowing numbers on backend\r\n\r\n<img width=\"858\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/8d61305a-eeb8-41d7-8fa0-f0b466fa7528\"\r\n/>\r\n\r\n\r\nCloses
https://github.com/elastic/kibana/issues/204935\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x] The PR description includes the appropriate Release Notes
section,\r\nand the correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"b746c39ca04446301747c17cd845b1582db05396","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","v9.0.0","backport:prev-major","Team:Security-Scalability","Feature:AutomaticImport"],"title":"[Automatic
Import] Fix UI validation for Integration and Datastream
name","number":204943,"url":"https://github.com/elastic/kibana/pull/204943","mergeCommit":{"message":"[Automatic
Import] Fix UI validation for Integration and Datastream name
(#204943)\n\n## Release Note\r\n\r\nFixes Integration and Datastream
name validation\r\n\r\n##
Summary\r\n\r\nhttps://github.com/elastic/kibana/pull/204409 implemented
backend\r\nvalidation for integration and datastream names and this PR
fixes\r\nallowing numbers on backend\r\n\r\n<img width=\"858\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/8d61305a-eeb8-41d7-8fa0-f0b466fa7528\"\r\n/>\r\n\r\n\r\nCloses
https://github.com/elastic/kibana/issues/204935\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x] The PR description includes the appropriate Release Notes
section,\r\nand the correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"b746c39ca04446301747c17cd845b1582db05396"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204943","number":204943,"mergeCommit":{"message":"[Automatic
Import] Fix UI validation for Integration and Datastream name
(#204943)\n\n## Release Note\r\n\r\nFixes Integration and Datastream
name validation\r\n\r\n##
Summary\r\n\r\nhttps://github.com/elastic/kibana/pull/204409 implemented
backend\r\nvalidation for integration and datastream names and this PR
fixes\r\nallowing numbers on backend\r\n\r\n<img width=\"858\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/8d61305a-eeb8-41d7-8fa0-f0b466fa7528\"\r\n/>\r\n\r\n\r\nCloses
https://github.com/elastic/kibana/issues/204935\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x] The PR description includes the appropriate Release Notes
section,\r\nand the correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"b746c39ca04446301747c17cd845b1582db05396"}}]}]
BACKPORT-->

Co-authored-by: Bharat Pasupula <123897612+bhapas@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2024-12-20 11:09:15 +11:00 committed by GitHub
parent 4f85910054
commit 6a0e65f7cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 9 deletions

View file

@ -292,12 +292,6 @@ describe('isValidName', () => {
expect(isValidName('anotherValidName')).toBe(true);
});
it('should return false for names with numbers', () => {
expect(isValidName('invalid123')).toBe(false);
expect(isValidName('123invalid')).toBe(false);
expect(isValidName('invalid_123')).toBe(false);
});
it('should return false for empty string', () => {
expect(isValidName('')).toBe(false);
});

View file

@ -36,7 +36,7 @@ export async function buildPackage(integration: Integration): Promise<Buffer> {
if (!isValidName(integration.name)) {
throw new Error(
`Invalid integration name: ${integration.name}, Should only contain letters and underscores`
`Invalid integration name: ${integration.name}, Should only contain letters, numbers and underscores`
);
}
@ -49,7 +49,7 @@ export async function buildPackage(integration: Integration): Promise<Buffer> {
const dataStreamName = dataStream.name;
if (!isValidName(dataStreamName)) {
throw new Error(
`Invalid datastream name: ${dataStreamName}, Should only contain letters and underscores`
`Invalid datastream name: ${dataStreamName}, Should only contain letters, numbers and underscores`
);
}
const specificDataStreamDir = joinPath(dataStreamsDir, dataStreamName);
@ -77,7 +77,7 @@ export async function buildPackage(integration: Integration): Promise<Buffer> {
return zipBuffer;
}
export function isValidName(input: string): boolean {
const regex = /^[a-zA-Z_]+$/;
const regex = /^[a-zA-Z0-9_]+$/;
return input.length > 0 && regex.test(input);
}
function createDirectories(