Skip to content

Commit

Permalink
Dynamic tenancy configurations (opensearch-project#1394)
Browse files Browse the repository at this point in the history
* Dynamic multitenancy feature.

Signed-off-by: Abhi Kalra <abhivka@amazon.com>

* Dynamic multitenancy feature -PR feedback

Signed-off-by: Abhi Kalra <abhivka@amazon.com>

---------

Signed-off-by: Abhi Kalra <abhivka@amazon.com>
Co-authored-by: Abhi Kalra <abhivka@amazon.com>
Signed-off-by: leanneeliatra <leanne.laceybyrne@eliatra.com>
  • Loading branch information
2 people authored and leanneeliatra committed Jun 12, 2023
1 parent ee7ab0a commit d8f8daa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
19 changes: 4 additions & 15 deletions public/apps/account/account-nav-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,7 @@ export function AccountNavButton(props: {
}}
handleSwitchAndClose={() => {
setModal(null);
const lastUrls = [];
for (let i = 0; i < sessionStorage.length; i++) {
const key = sessionStorage.key(i);
if (key?.startsWith('lastUrl')) {
lastUrls.push(key);
}
}
for (let i = 0; i < lastUrls.length; i++) {
sessionStorage.removeItem(lastUrls[i]);
}

window.location.href = window.location.pathname;
reloadAfterTenantSwitch();
}}
tenant={props.tenant!}
/>
Expand All @@ -83,9 +72,9 @@ export function AccountNavButton(props: {
React.useEffect(() => {
const fetchData = async () => {
try {
// setIsMultiTenancyEnabled(
// (await getDashboardsInfo(props.coreStart.http)).multitenancy_enabled
// );
setIsMultiTenancyEnabled(
(await getDashboardsInfo(props.coreStart.http)).multitenancy_enabled
);
} catch (e) {
// TODO: switch to better error display.
console.error(e);
Expand Down
2 changes: 1 addition & 1 deletion public/apps/account/test/account-nav-button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('Account navigation button, multitenancy disabled', () => {
currAuthType={'dummy'}
/>
);
expect(setState).toBeCalledTimes(0);
expect(setState).toBeCalledTimes(1);
});
});

Expand Down
25 changes: 15 additions & 10 deletions public/apps/configuration/panels/tenant-list/manage_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { showTableStatusMessage } from '../../utils/loading-spinner-utils';
import { useContextMenuState } from '../../utils/context-menu';
import { generateResourceName } from '../../utils/resource-utils';
import { DocLinks } from '../../constants';
import { TenantInstructionView } from './tenant-instruction-view';
import { TenantList } from './tenant-list';
import { getBreadcrumbs, Route_MAP } from '../../app-router';
import { buildUrl } from '../../utils/url-builder';
Expand All @@ -91,29 +92,30 @@ export function ManageTab(props: AppDependencies) {
const [isPrivateTenantEnabled, setIsPrivateTenantEnabled] = useState(false);
const [dashboardsDefaultTenant, setDashboardsDefaultTenant] = useState('');

const { http } = props.coreStart;

const fetchData = useCallback(async () => {
try {
setLoading(true);
const rawTenantData = await fetchTenants(http);
const rawTenantData = await fetchTenants(props.coreStart.http);
const processedTenantData = transformTenantData(rawTenantData);
const activeTenant = await fetchCurrentTenant(http);
const currentUser = await getCurrentUser(http);
const activeTenant = await fetchCurrentTenant(props.coreStart.http);
const currentUser = await getCurrentUser(props.coreStart.http);
setCurrentUsername(currentUser);
setCurrentTenant(resolveTenantName(activeTenant, currentUser));
setTenantData(processedTenantData);
const tenancyConfig = await getDashboardsInfo(http);
setIsMultiTenancyEnabled(tenancyConfig.multitenancy_enabled);
setIsPrivateTenantEnabled(tenancyConfig.private_tenant_enabled);
setDashboardsDefaultTenant(tenancyConfig.default_tenant);
setIsMultiTenancyEnabled(
(await getDashboardsInfo(props.coreStart.http)).multitenancy_enabled
);
setIsPrivateTenantEnabled(
(await getDashboardsInfo(props.coreStart.http)).private_tenant_enabled
);
setDashboardsDefaultTenant((await getDashboardsInfo(props.coreStart.http)).default_tenant);
} catch (e) {
console.log(e);
setErrorFlag(true);
} finally {
setLoading(false);
}
}, [http]);
}, [props.coreStart.http]);

React.useEffect(() => {
fetchData();
Expand Down Expand Up @@ -477,6 +479,9 @@ export function ManageTab(props: AppDependencies) {
);
};

if (!props.config.multitenancy.enabled) {
return <TenantInstructionView />;
}
/* eslint-disable */
return (
<>
Expand Down
6 changes: 1 addition & 5 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ export class SecurityPlugin
})
);

if (
multitenancyEnabled &&
config.multitenancy.enabled &&
config.multitenancy.enable_aggregation_view
) {
if (multitenancyEnabled && config.multitenancy.enable_aggregation_view) {
deps.savedObjectsManagement.columns.register(
(tenantColumn as unknown) as SavedObjectsManagementColumn<string>
);
Expand Down

0 comments on commit d8f8daa

Please sign in to comment.