Skip to content

Commit 2cd6a34

Browse files
committed
prevent logged out datasources call (#1653)
* prevent logged out datasources call Signed-off-by: Paul Sebastian <[email protected]> * check if security plugin is installed Signed-off-by: Paul Sebastian <[email protected]> * clean up logic Signed-off-by: Paul Sebastian <[email protected]> * include a catch clause to register datasources when account api has non 401 error Signed-off-by: Paul Sebastian <[email protected]> * included comment Signed-off-by: Paul Sebastian <[email protected]> --------- Signed-off-by: Paul Sebastian <[email protected]> (cherry picked from commit c14c3f8)
1 parent 3a69e36 commit 2cd6a34

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

opensearch_dashboards.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
],
2121
"optionalPlugins": [
2222
"managementOverview",
23-
"assistantDashboards"
23+
"assistantDashboards",
24+
"securityDashboards"
2425
],
2526
"configPath": [
2627
"observability"
2728
]
28-
}
29+
}

public/plugin.tsx

+31-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { createGetterSetter } from '../../../src/plugins/opensearch_dashboards_u
2020
import { CREATE_TAB_PARAM, CREATE_TAB_PARAM_KEY, TAB_CHART_ID } from '../common/constants/explorer';
2121
import {
2222
DATACONNECTIONS_BASE,
23+
SECURITY_PLUGIN_ACCOUNT_API,
2324
observabilityApplicationsID,
2425
observabilityApplicationsPluginOrder,
2526
observabilityApplicationsTitle,
@@ -388,18 +389,37 @@ export class ObservabilityPlugin
388389
const { dataSourceService, dataSourceFactory } = startDeps.data.dataSources;
389390

390391
// register all s3 datasources
391-
dataSourceFactory.registerDataSourceType(S3_DATASOURCE_TYPE, S3DataSource);
392-
core.http.get(`${DATACONNECTIONS_BASE}`).then((s3DataSources) => {
393-
s3DataSources.map((s3ds) => {
394-
dataSourceService.registerDataSource(
395-
dataSourceFactory.getDataSourceInstance(S3_DATASOURCE_TYPE, {
396-
name: s3ds.name,
397-
type: s3ds.connector.toLowerCase(),
398-
metadata: s3ds,
399-
})
400-
);
392+
const registerS3Datasource = () => {
393+
dataSourceFactory.registerDataSourceType(S3_DATASOURCE_TYPE, S3DataSource);
394+
core.http.get(`${DATACONNECTIONS_BASE}`).then((s3DataSources) => {
395+
s3DataSources.map((s3ds) => {
396+
dataSourceService.registerDataSource(
397+
dataSourceFactory.getDataSourceInstance(S3_DATASOURCE_TYPE, {
398+
name: s3ds.name,
399+
type: s3ds.connector.toLowerCase(),
400+
metadata: s3ds,
401+
})
402+
);
403+
});
401404
});
402-
});
405+
};
406+
407+
if (startDeps.securityDashboards) {
408+
core.http
409+
.get(SECURITY_PLUGIN_ACCOUNT_API)
410+
.then(() => {
411+
registerS3Datasource();
412+
})
413+
.catch((e) => {
414+
if (e?.response?.status !== 401) {
415+
// accounts api should not return any error status other than 401 if security installed,
416+
// this datasource register is included just in case
417+
registerS3Datasource();
418+
}
419+
});
420+
} else {
421+
registerS3Datasource();
422+
}
403423

404424
core.http.intercept({
405425
request: catalogRequestIntercept(),

public/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface AppPluginStartDependencies {
2525
dashboard: DashboardStart;
2626
savedObjectsClient: SavedObjectsClient;
2727
data: DataPublicPluginStart;
28+
securityDashboards?: {};
2829
}
2930

3031
export interface SetupDependencies {

0 commit comments

Comments
 (0)