Skip to content

Commit

Permalink
[MDS] Adds datasource filter for version decoupling (#2051)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura authored Jul 23, 2024
1 parent a44e265 commit e9609ac
Show file tree
Hide file tree
Showing 7 changed files with 784 additions and 523 deletions.
4 changes: 3 additions & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
"dataSourceManagement"
],
"server": true,
"ui": true
"ui": true,
"supportedOSDataSourceVersions": ">=1.0.0",
"requiredOSDataSourcePlugins": ["opensearch-security"]
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"@hapi/wreck": "^17.1.0",
"html-entities": "1.3.1",
"proxy-agent": "^6.4.0",
"zxcvbn": "^4.4.2"
"zxcvbn": "^4.4.2",
"semver": "^7.5.3"
},
"resolutions": {
"selenium-webdriver": "4.10.0",
Expand All @@ -55,4 +56,4 @@
"express": "^4.19.2",
"braces": "^3.0.3"
}
}
}
2 changes: 2 additions & 0 deletions public/apps/configuration/top-nav-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { AppDependencies } from '../types';
import {
setDataSourceInUrl,
setDataSource as setDataSourceInSubscription,
isDataSourceCompatible,
} from '../../utils/datasource-utils';

export interface TopNavMenuProps extends AppDependencies {
Expand Down Expand Up @@ -63,6 +64,7 @@ export const SecurityPluginTopNavMenu = React.memo(
: undefined,
onSelectedDataSources: wrapSetDataSourceWithUpdateUrl,
fullWidth: true,
dataSourceFilter: isDataSourceCompatible,
}}
/>
) : null;
Expand Down
28 changes: 27 additions & 1 deletion public/utils/datasource-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import semver from 'semver';
import { BehaviorSubject } from 'rxjs';
import { DataSourceOption } from 'src/plugins/data_source_management/public/components/data_source_menu/types';
import pluginManifest from '../../opensearch_dashboards.json';
import type { SavedObject } from '../../../../src/core/public';
import type { DataSourceAttributes } from '../../../../src/plugins/data_source/common/data_sources';

const DATASOURCEURLKEY = 'dataSource';

Expand Down Expand Up @@ -55,3 +58,26 @@ export const dataSource$ = new BehaviorSubject<DataSourceOption>(
export function setDataSource(dataSource: DataSourceOption) {
dataSource$.next(dataSource);
}

export const isDataSourceCompatible = (dataSource: SavedObject<DataSourceAttributes>) => {
if (
'requiredOSDataSourcePlugins' in pluginManifest &&
!pluginManifest.requiredOSDataSourcePlugins.every((plugin) =>
dataSource.attributes.installedPlugins?.includes(plugin)
)
) {
return false;
}

// filter out data sources which is NOT in the support range of plugin
if (
'supportedOSDataSourceVersions' in pluginManifest &&
!semver.satisfies(
dataSource.attributes.dataSourceVersion,
pluginManifest.supportedOSDataSourceVersions
)
) {
return false;
}
return true;
};
133 changes: 132 additions & 1 deletion public/utils/test/datasource-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
* permissions and limitations under the License.
*/

import { getClusterInfo, getDataSourceFromUrl, setDataSourceInUrl } from '../datasource-utils';
import {
getClusterInfo,
getDataSourceFromUrl,
setDataSourceInUrl,
isDataSourceCompatible,
} from '../datasource-utils';

describe('Tests datasource utils', () => {
it('Tests the GetClusterDescription helper function', () => {
Expand Down Expand Up @@ -78,4 +83,130 @@ describe('Tests datasource utils', () => {
});
expect(getDataSourceFromUrl()).toEqual({});
});

describe('isDataSourceCompatible', () => {
it('should return true for compatible data sources', () => {
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-security'],
dataSourceVersion: '2.9.0',
title: '',
endpoint: '',
auth: {
type: '',
credentials: undefined,
},
},
id: '',
type: '',
references: [],
})
).toBe(true);
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-security'],
dataSourceVersion: '2.11.0',
title: '',
endpoint: '',
auth: {
type: '',
credentials: undefined,
},
},
id: '',
type: '',
references: [],
})
).toBe(true);
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-security'],
dataSourceVersion: '2.13.0',
title: '',
endpoint: '',
auth: {
type: '',
credentials: undefined,
},
},
id: '',
type: '',
references: [],
})
).toBe(true);
});

it('should return false for un-compatible data sources', () => {
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: [],
dataSourceVersion: '2.13.0',
title: '',
endpoint: '',
auth: {
type: '',
credentials: undefined,
},
},
id: '',
type: '',
references: [],
})
).toBe(false);
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-ml'],
dataSourceVersion: '2.13.0',
title: '',
endpoint: '',
auth: {
type: '',
credentials: undefined,
},
},
id: '',
type: '',
references: [],
})
).toBe(false);
expect(
isDataSourceCompatible({
attributes: {
title: '',
endpoint: '',
dataSourceVersion: '',
auth: {
type: '',
credentials: undefined,
},
},
id: '',
type: '',
references: [],
})
).toBe(false);
expect(
isDataSourceCompatible({
attributes: {
installedPlugins: ['opensearch-security'],
dataSourceVersion: '1.0.0-beta1',
title: '',
endpoint: '',
auth: {
type: '',
credentials: undefined,
},
},
id: '',
type: '',
references: [],
})
).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const createDataSource = () => {
attributes: {
title: Cypress.env('externalDataSourceLabel'),
endpoint: Cypress.env('externalDataSourceEndpoint'),
installedPlugins: ['opensearch-security'],
dataSourceVersion: '2.15.0',
auth: {
type: 'username_password',
credentials: {
Expand Down
Loading

0 comments on commit e9609ac

Please sign in to comment.