From ac1cf60b9db190ae07a4acb25106886d12e6f35c Mon Sep 17 00:00:00 2001
From: Bharat Pasupula <123897612+bhapas@users.noreply.github.com>
Date: Thu, 19 Dec 2024 23:22:20 +0100
Subject: [PATCH] [Automatic Import] Fix UI validation for Integration and
Datastream name (#204943)
## Release Note
Fixes Integration and Datastream name validation
## Summary
https://github.com/elastic/kibana/pull/204409 implemented backend
validation for integration and datastream names and this PR fixes
allowing numbers on backend
Closes https://github.com/elastic/kibana/issues/204935
### Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
(cherry picked from commit b746c39ca04446301747c17cd845b1582db05396)
---
.../server/integration_builder/build_integration.test.ts | 6 ------
.../server/integration_builder/build_integration.ts | 6 +++---
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.test.ts b/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.test.ts
index 16ce7e8be8c9f..a99eaba6446cc 100644
--- a/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.test.ts
+++ b/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.test.ts
@@ -287,12 +287,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);
});
diff --git a/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.ts b/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.ts
index b466f059d7df9..22ef37b8f90b1 100644
--- a/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.ts
+++ b/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.ts
@@ -36,7 +36,7 @@ export async function buildPackage(integration: Integration): Promise {
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 {
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);
@@ -76,7 +76,7 @@ export async function buildPackage(integration: Integration): Promise {
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(