Skip to content

Commit

Permalink
prevent logged out datasources call (opensearch-project#1653) (opense…
Browse files Browse the repository at this point in the history
…arch-project#1672)

* prevent logged out datasources call

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

* check if security plugin is installed

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

* clean up logic

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

* include a catch clause to register datasources when account api has non 401 error

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

* included comment

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

---------

Signed-off-by: Paul Sebastian <paulstn@amazon.com>
(cherry picked from commit c14c3f8)
  • Loading branch information
paulstn authored Apr 5, 2024
1 parent 3a69e36 commit cdfeefd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
5 changes: 3 additions & 2 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
],
"optionalPlugins": [
"managementOverview",
"assistantDashboards"
"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 cdfeefd

Please sign in to comment.