-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Manual Backport 2.x] [Multiple DataSource] Do not support import dat…
…a source object to Local cluster when not enable data source (#6913) * [Backport #6395] Do not support import data source object to Local cluster when not enable data source Signed-off-by: yujin-emma <[email protected]> * Update CHANGELOG.md Signed-off-by: yujin-emma <[email protected]> * fix: integration test failure Signed-off-by: SuZhou-Joe <[email protected]> Signed-off-by: yujin-emma <[email protected]> --------- Signed-off-by: yujin-emma <[email protected]> Signed-off-by: SuZhou-Joe <[email protected]> Co-authored-by: SuZhou-Joe <[email protected]>
- Loading branch information
1 parent
7ee7a75
commit ad47909
Showing
11 changed files
with
248 additions
and
7 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
59 changes: 59 additions & 0 deletions
59
src/core/server/saved_objects/import/validate_object_id.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,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { isSavedObjectWithDataSource } from './validate_object_id'; | ||
|
||
describe('isObjectWithDataSource', () => { | ||
test('should return false for valid object with data source ID but in wrong format', () => { | ||
// Valid ID with two parts separated by underscore, and both parts being UUIDs | ||
const inValidId = 'invalid_uuid_1234-invalid_uuid_5678'; | ||
expect(isSavedObjectWithDataSource(inValidId)).toBe(false); | ||
}); | ||
|
||
test('should return false for invalid IDs', () => { | ||
// Missing underscore | ||
const invalidId1 = 'missingunderscore'; | ||
expect(isSavedObjectWithDataSource(invalidId1)).toBe(false); | ||
|
||
// Invalid UUID in the second part | ||
const invalidId2 = 'valid_uuid_1234-invalid_uuid'; | ||
expect(isSavedObjectWithDataSource(invalidId2)).toBe(false); | ||
|
||
// Missing second part | ||
const invalidId3 = 'valid_uuid_1234'; | ||
expect(isSavedObjectWithDataSource(invalidId3)).toBe(false); | ||
|
||
// More than two parts | ||
const invalidId4 = 'valid_uuid_1234-valid_uuid_5678-extra_part'; | ||
expect(isSavedObjectWithDataSource(invalidId4)).toBe(false); | ||
}); | ||
|
||
test('should return false for non-UUID parts', () => { | ||
// First part is not a UUID | ||
const invalidId1 = 'not_a_uuid_valid_uuid_1234'; | ||
expect(isSavedObjectWithDataSource(invalidId1)).toBe(false); | ||
|
||
// Second part is not a UUID | ||
const invalidId2 = 'valid_uuid_1234_not_a_uuid'; | ||
expect(isSavedObjectWithDataSource(invalidId2)).toBe(false); | ||
|
||
// Both parts are not UUIDs | ||
const invalidId3 = 'not_a_uuid_not_a_uuid'; | ||
expect(isSavedObjectWithDataSource(invalidId3)).toBe(false); | ||
}); | ||
|
||
test('should return false for string with underscore but not with UUID', () => { | ||
// First part is not a UUID | ||
const invalidId = 'saved_object_with_index_pattern_conflict'; | ||
expect(isSavedObjectWithDataSource(invalidId)).toBe(false); | ||
}); | ||
|
||
test('should return false for string with underscore but with three UUIDs', () => { | ||
// First part is not a UUID | ||
const invalidId = | ||
'7cbd2350-2223-11e8-b802-5bcf64c2cfb4_7cbd2350-2223-11e8-b802-5bcf64c2cfb4_7cbd2350-2223-11e8-b802-5bcf64c2cfb4'; | ||
expect(isSavedObjectWithDataSource(invalidId)).toBe(false); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/core/server/saved_objects/import/validate_object_id.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,40 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* When enable multiple data source, exported objects from a data source will maintain object id like | ||
* "69a34b00-9ee8-11e7-8711-e7a007dcef99_7cbd2350-2223-11e8-b802-5bcf64c2cfb4" | ||
* two UUIDs are connected with a underscore, | ||
* before the underscore, the UUID represents the data source | ||
* after the underscore, the UUID is the original object id | ||
* when disable multiple data source, the exported object from local cluster will look like 7cbd2350-2223-11e8-b802-5bcf64c2cfb4 | ||
* we can use this format to tell out whether a single object is exported from MDS enabled/disabled cluster | ||
* | ||
* This file to going to group some validate function to tell source of object based on the object id | ||
*/ | ||
|
||
/** | ||
* | ||
* @param candidate: string without underscore | ||
* @returns | ||
*/ | ||
const isUUID = (candidate: string): boolean => { | ||
// Regular expression pattern for UUID | ||
const uuidPattern: RegExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; | ||
return uuidPattern.test(candidate); | ||
}; | ||
|
||
/** | ||
* | ||
* @param id single object id | ||
* @returns | ||
*/ | ||
export const isSavedObjectWithDataSource = (id: string): boolean => { | ||
const idParts = id.split('_'); | ||
/** | ||
* check with the | ||
*/ | ||
return idParts && idParts.length === 2 && idParts.every(isUUID); | ||
}; |
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
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