Skip to content

Commit

Permalink
[Automatic Import] Fix UI validation for Integration and Datastream n…
Browse files Browse the repository at this point in the history
…ame (#204943)

## Release Note

Fixes Integration and Datastream name validation

## Summary

#204409 implemented backend
validation for integration and datastream names and this PR fixes
allowing numbers on backend

<img width="858" alt="image"
src="https://github.com/user-attachments/assets/8d61305a-eeb8-41d7-8fa0-f0b466fa7528"
/>


Closes #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)
  • Loading branch information
bhapas authored Dec 19, 2024
1 parent 223781c commit b746c39
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b746c39

Please sign in to comment.