forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport opensearch-project#6395] Do not support import data source …
…object to Local cluster when not enable data source Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
- Loading branch information
1 parent
d260f9e
commit b8da169
Showing
10 changed files
with
277 additions
and
6 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
Oops, something went wrong.