Skip to content

Commit

Permalink
Adds datasource filter for version decoupling in MDS
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
  • Loading branch information
DarshitChanpura committed Jul 23, 2024
1 parent a44e265 commit 22734f9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 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"]
}
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;
};

0 comments on commit 22734f9

Please sign in to comment.