Skip to content

Commit

Permalink
Lift state up one and generalize flow, render picker for auth tab (#1835
Browse files Browse the repository at this point in the history
)

Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho authored Mar 22, 2024
1 parent 4ba9fcf commit eae331a
Show file tree
Hide file tree
Showing 27 changed files with 1,093 additions and 249 deletions.
46 changes: 45 additions & 1 deletion .github/workflows/cypress-test-multidatasources-enabled-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,50 @@ jobs:
node.max_local_storage_nodes: 3
EOT
# Add Custom Configuration to differentiate between local and remote cluster
- name: Create Custom Configuration for Linux
if: ${{ runner.os == 'Linux'}}
run: |
echo "Creating new custom configuration"
cat << 'EOT' > config_custom.yml
---
_meta:
type: "config"
config_version: 2
config:
dynamic:
http:
anonymous_auth_enabled: false
authc:
basic_internal_auth_domain:
description: "Authenticate via HTTP Basic against internal users database"
http_enabled: true
transport_enabled: true
order: 0
http_authenticator:
type: basic
challenge: false
authentication_backend:
type: intern
saml_auth_domain:
http_enabled: true
transport_enabled: false
order: 1
http_authenticator:
type: saml
challenge: true
config:
idp:
entity_id: urn:example:idp
metadata_url: http://localhost:7000/metadata
sp:
entity_id: https://localhost:9200
kibana_url: http://localhost:5601
exchange_key: 6aff3042-1327-4f3d-82f0-40a157ac4464
authentication_backend:
type: noop
EOT
- name: Download security plugin and create setup scripts
uses: ./.github/actions/download-plugin
with:
Expand All @@ -84,7 +128,7 @@ jobs:
plugins: "file:$(pwd)/opensearch-security.zip"
security-enabled: true
admin-password: ${{ env.OPENSEARCH_INITIAL_ADMIN_PASSWORD }}
security_config_file: ${{ inputs.security_config_file }}
security_config_file: config_custom.yml
opensearch_yml_file: remote_opensearch.yml
opensearch_port: 9202

Expand Down
2 changes: 1 addition & 1 deletion public/apps/account/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { httpGet, httpGetWithIgnores, httpPost } from '../configuration/utils/re
import { setShouldShowTenantPopup } from '../../utils/storage-utils';

export function fetchAccountInfo(http: HttpStart): Promise<AccountInfo> {
return httpGet(http, API_ENDPOINT_ACCOUNT_INFO);
return httpGet({ http, url: API_ENDPOINT_ACCOUNT_INFO });
}

export async function fetchAccountInfoSafe(http: HttpStart): Promise<AccountInfo | undefined> {
Expand Down
279 changes: 147 additions & 132 deletions public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

import { EuiBreadcrumb, EuiPage, EuiPageBody, EuiPageSideBar } from '@elastic/eui';
import { flow, partial } from 'lodash';
import React from 'react';
import React, { createContext, useState } from 'react';
import { HashRouter as Router, Route, Switch, Redirect } from 'react-router-dom';
import { DataSourceOption } from '../../../../../src/plugins/data_source_management/public/components/data_source_selector/data_source_selector';
import { AppDependencies } from '../types';
import { AuditLogging } from './panels/audit-logging/audit-logging';
import { AuditLoggingEditSettings } from './panels/audit-logging/audit-logging-edit-settings';
Expand Down Expand Up @@ -143,140 +144,154 @@ function decodeParams(params: { [k: string]: string }): any {
}, {});
}

export interface DataSourceContextType {
dataSource: DataSourceOption;
setDataSource: React.Dispatch<React.SetStateAction<DataSourceOption>>;
}

export const DataSourceContext = createContext<DataSourceContextType | null>(null);

export function AppRouter(props: AppDependencies) {
const setGlobalBreadcrumbs = flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs);
const [dataSource, setDataSource] = useState<DataSourceOption>({
id: '',
label: 'Local cluster',
checked: 'on',
});

return (
<Router basename={props.params.appBasePath}>
<EuiPage>
{allNavPanelUrls.map((route) => (
// Create different routes to update the 'selected' nav item .
<Route key={route} path={route} exact>
<EuiPageSideBar>
<NavPanel items={ROUTE_LIST} />
</EuiPageSideBar>
</Route>
))}
<EuiPageBody>
<Switch>
<Route
path={buildUrl(ResourceType.roles, Action.edit) + '/:roleName/' + SubAction.mapuser}
render={(match) => (
<RoleEditMappedUser
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.roles)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
)}
/>
<Route
path={buildUrl(ResourceType.roles, Action.view) + '/:roleName/:prevAction?'}
render={(match) => (
<RoleView
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.roles)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
)}
/>
<Route
path={buildUrl(ResourceType.roles) + '/:action/:sourceRoleName?'}
render={(match) => (
<RoleEdit
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.roles)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
)}
/>
<Route
path={ROUTE_MAP.roles.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.roles);
return <RoleList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.auth.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.auth);
return <AuthView {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.users) + '/:action/:sourceUserName?'}
render={(match) => (
<InternalUserEdit
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.users)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
)}
/>
<Route
path={ROUTE_MAP.users.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.users);
return <UserList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.serviceAccounts.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.serviceAccounts);
return <ServiceAccountList {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_GENERAL_SETTINGS_EDIT}
render={() => {
setGlobalBreadcrumbs(ResourceType.auditLogging, 'General settings');
return <AuditLoggingEditSettings setting={'general'} {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT}
render={() => {
setGlobalBreadcrumbs(ResourceType.auditLogging, 'Compliance settings');
return <AuditLoggingEditSettings setting={'compliance'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.auditLogging.href + '/:fromType?'}
render={(match) => {
setGlobalBreadcrumbs(ResourceType.auditLogging);
return <AuditLogging {...{ ...props, ...match.match.params }} />;
}}
/>
<Route
path={ROUTE_MAP.permissions.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.permissions);
return <PermissionList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenants.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Manage'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenantsConfigureTab.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Configure'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.getStarted.href}
render={() => {
setGlobalBreadcrumbs();
return <GetStarted {...props} />;
}}
/>
<Redirect exact from="/" to={LANDING_PAGE_URL} />
</Switch>
</EuiPageBody>
<CrossPageToast />
</EuiPage>
</Router>
<DataSourceContext.Provider value={{ dataSource, setDataSource }}>
<Router basename={props.params.appBasePath}>
<EuiPage>
{allNavPanelUrls.map((route) => (
// Create different routes to update the 'selected' nav item .
<Route key={route} path={route} exact>
<EuiPageSideBar>
<NavPanel items={ROUTE_LIST} />
</EuiPageSideBar>
</Route>
))}
<EuiPageBody>
<Switch>
<Route
path={buildUrl(ResourceType.roles, Action.edit) + '/:roleName/' + SubAction.mapuser}
render={(match) => (
<RoleEditMappedUser
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.roles)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
)}
/>
<Route
path={buildUrl(ResourceType.roles, Action.view) + '/:roleName/:prevAction?'}
render={(match) => (
<RoleView
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.roles)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
)}
/>
<Route
path={buildUrl(ResourceType.roles) + '/:action/:sourceRoleName?'}
render={(match) => (
<RoleEdit
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.roles)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
)}
/>
<Route
path={ROUTE_MAP.roles.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.roles);
return <RoleList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.auth.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.auth);
return <AuthView {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.users) + '/:action/:sourceUserName?'}
render={(match) => (
<InternalUserEdit
buildBreadcrumbs={partial(setGlobalBreadcrumbs, ResourceType.users)}
{...{ ...props, ...decodeParams(match.match.params) }}
/>
)}
/>
<Route
path={ROUTE_MAP.users.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.users);
return <UserList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.serviceAccounts.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.serviceAccounts);
return <ServiceAccountList {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_GENERAL_SETTINGS_EDIT}
render={() => {
setGlobalBreadcrumbs(ResourceType.auditLogging, 'General settings');
return <AuditLoggingEditSettings setting={'general'} {...props} />;
}}
/>
<Route
path={buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT}
render={() => {
setGlobalBreadcrumbs(ResourceType.auditLogging, 'Compliance settings');
return <AuditLoggingEditSettings setting={'compliance'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.auditLogging.href + '/:fromType?'}
render={(match) => {
setGlobalBreadcrumbs(ResourceType.auditLogging);
return <AuditLogging {...{ ...props, ...match.match.params }} />;
}}
/>
<Route
path={ROUTE_MAP.permissions.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.permissions);
return <PermissionList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenants.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Manage'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenantsConfigureTab.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Configure'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.getStarted.href}
render={() => {
setGlobalBreadcrumbs();
return <GetStarted {...props} />;
}}
/>
<Redirect exact from="/" to={LANDING_PAGE_URL} />
</Switch>
</EuiPageBody>
<CrossPageToast />
</EuiPage>
</Router>
</DataSourceContext.Provider>
);
}
Loading

0 comments on commit eae331a

Please sign in to comment.