Skip to content

Commit

Permalink
prevent logged out datasources call (#1653)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
paulstn authored Apr 4, 2024
1 parent 952b4bc commit c14c3f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"urlForwarding",
"visualizations"
],
"optionalPlugins": ["managementOverview", "assistantDashboards"],
"optionalPlugins": ["managementOverview", "assistantDashboards", "securityDashboards"],
"configPath": ["observability"]
}
42 changes: 31 additions & 11 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { createGetterSetter } from '../../../src/plugins/opensearch_dashboards_u
import { CREATE_TAB_PARAM, CREATE_TAB_PARAM_KEY, TAB_CHART_ID } from '../common/constants/explorer';
import {
DATACONNECTIONS_BASE,
SECURITY_PLUGIN_ACCOUNT_API,
observabilityApplicationsID,
observabilityApplicationsPluginOrder,
observabilityApplicationsTitle,
Expand Down Expand Up @@ -388,18 +389,37 @@ export class ObservabilityPlugin
const { dataSourceService, dataSourceFactory } = startDeps.data.dataSources;

// register all s3 datasources
dataSourceFactory.registerDataSourceType(S3_DATASOURCE_TYPE, S3DataSource);
core.http.get(`${DATACONNECTIONS_BASE}`).then((s3DataSources) => {
s3DataSources.map((s3ds) => {
dataSourceService.registerDataSource(
dataSourceFactory.getDataSourceInstance(S3_DATASOURCE_TYPE, {
name: s3ds.name,
type: s3ds.connector.toLowerCase(),
metadata: s3ds,
})
);
const registerS3Datasource = () => {
dataSourceFactory.registerDataSourceType(S3_DATASOURCE_TYPE, S3DataSource);
core.http.get(`${DATACONNECTIONS_BASE}`).then((s3DataSources) => {
s3DataSources.map((s3ds) => {
dataSourceService.registerDataSource(
dataSourceFactory.getDataSourceInstance(S3_DATASOURCE_TYPE, {
name: s3ds.name,
type: s3ds.connector.toLowerCase(),
metadata: s3ds,
})
);
});
});
});
};

if (startDeps.securityDashboards) {
core.http
.get(SECURITY_PLUGIN_ACCOUNT_API)
.then(() => {
registerS3Datasource();
})
.catch((e) => {
if (e?.response?.status !== 401) {
// accounts api should not return any error status other than 401 if security installed,
// this datasource register is included just in case
registerS3Datasource();
}
});
} else {
registerS3Datasource();
}

core.http.intercept({
request: catalogRequestIntercept(),
Expand Down
1 change: 1 addition & 0 deletions public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface AppPluginStartDependencies {
dashboard: DashboardStart;
savedObjectsClient: SavedObjectsClient;
data: DataPublicPluginStart;
securityDashboards?: {};
}

export interface SetupDependencies {
Expand Down

0 comments on commit c14c3f8

Please sign in to comment.