Skip to content

Commit

Permalink
Merge main into 1.12 (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxitang-amzn authored Dec 29, 2020
1 parent d70c145 commit b0ac7c3
Show file tree
Hide file tree
Showing 23 changed files with 537 additions and 167 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ jobs:
name: Run integration tests
runs-on: ubuntu-latest
steps:

- name: Set up JDK 11
- name: Set up JDK 14
uses: actions/setup-java@v1
with:
java-version: 11.0.x
java-version: 14

- name: Checkout Kibana
uses: actions/checkout@v2
Expand Down Expand Up @@ -49,8 +48,8 @@ jobs:
- name: Run elasticsearch with plugin
run: |
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-${{ steps.kbn_version.outputs.kbn_version }}-darwin-x86_64.tar.gz
tar -xzf elasticsearch-oss-${{ steps.kbn_version.outputs.kbn_version }}-darwin-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-${{ steps.kbn_version.outputs.kbn_version }}-linux-x86_64.tar.gz
tar -xzf elasticsearch-oss-${{ steps.kbn_version.outputs.kbn_version }}-linux-x86_64.tar.gz
cd elasticsearch-${{ steps.kbn_version.outputs.kbn_version }}/
bin/elasticsearch-plugin install -b https://d3g5vo6xdbdb9a.cloudfront.net/downloads/elasticsearch-plugins/opendistro-security/opendistro_security-${{ steps.opendistro_version.outputs.opendistro_version }}.zip
bash plugins/opendistro_security/tools/install_demo_configuration.sh -y -i
Expand Down
2 changes: 0 additions & 2 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ export const PLUGIN_ID = 'opendistroSecurity';
export const PLUGIN_NAME = 'opendistro_security';

export const APP_ID_LOGIN = 'login';
export const APP_ID_MULTITENANCY = 'multitenancy';
export const APP_ID_CUSTOMERROR = 'customerror';

export const API_PREFIX = '/api/v1';
export const CONFIGURATION_API_PREFIX = 'configuration';
export const API_ENDPOINT_AUTHINFO = API_PREFIX + '/auth/authinfo';
export const LOGIN_PAGE_URI = '/app/' + APP_ID_LOGIN;
export const SELECT_TENANT_PAGE_URI = '/app/select_tenant';
export const CUSTOM_ERROR_PAGE_URI = '/app/' + APP_ID_CUSTOMERROR;
export const API_AUTH_LOGIN = '/auth/login';
export const API_AUTH_LOGOUT = '/auth/logout';
Expand Down
45 changes: 44 additions & 1 deletion public/apps/account/account-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ import { AccountNavButton } from './account-nav-button';
import { fetchAccountInfoSafe } from './utils';
import { ClientConfigType } from '../../types';
import { CUSTOM_ERROR_PAGE_URI, ERROR_MISSING_ROLE_PATH } from '../../../common';
import { selectTenant } from '../configuration/utils/tenant-utils';
import {
getSavedTenant,
getShouldShowTenantPopup,
setShouldShowTenantPopup,
} from '../../utils/storage-utils';
import { constructErrorMessageAndLog } from '../error-utils';

function tenantSpecifiedInUrl() {
return (
window.location.search.includes('security_tenant') ||
window.location.search.includes('securitytenant')
);
}

export async function setupTopNavButton(coreStart: CoreStart, config: ClientConfigType) {
const accountInfo = (await fetchAccountInfoSafe(coreStart.http))?.data;
Expand All @@ -30,6 +44,35 @@ export async function setupTopNavButton(coreStart: CoreStart, config: ClientConf
coreStart.http.basePath.serverBasePath + CUSTOM_ERROR_PAGE_URI + ERROR_MISSING_ROLE_PATH;
}

let tenant = accountInfo.user_requested_tenant;
let shouldShowTenantPopup = true;

if (tenantSpecifiedInUrl() || getShouldShowTenantPopup() === false) {
shouldShowTenantPopup = false;
} else {
// Switch to previous tenant based on localStorage, it may fail due to
// 1) Localstorage is disabled; 2) Request failed
try {
const savedTenant = getSavedTenant();
if (savedTenant !== null) {
if (savedTenant === tenant) {
shouldShowTenantPopup = false;
} else {
await selectTenant(coreStart.http, {
username: accountInfo.user_name,
tenant: savedTenant,
});
tenant = savedTenant;
shouldShowTenantPopup = false;
}
}
} catch (e) {
constructErrorMessageAndLog(e, `Failed to switch to ${tenant} tenant.`);
}
}

setShouldShowTenantPopup(shouldShowTenantPopup);

coreStart.chrome.navControls.registerRight({
// Pin to rightmost, since newsfeed plugin is using 1000, here needs a number > 1000
order: 2000,
Expand All @@ -39,7 +82,7 @@ export async function setupTopNavButton(coreStart: CoreStart, config: ClientConf
coreStart={coreStart}
isInternalUser={accountInfo.is_internal_user}
username={accountInfo.user_name}
tenant={accountInfo.user_requested_tenant}
tenant={tenant}
config={config}
/>,
element
Expand Down
45 changes: 27 additions & 18 deletions public/apps/account/account-nav-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import {
EuiText,
} from '@elastic/eui';
import { CoreStart } from 'kibana/public';
import React from 'react';
import React, { useCallback } from 'react';
import { RoleInfoPanel } from './role-info-panel';
import { PasswordResetPanel } from './password-reset-panel';
import { TenantSwitchPanel } from './tenant-switch-panel';
import { ClientConfigType } from '../../types';
import { LogoutButton } from './log-out-button';
import { resolveTenantName } from '../configuration/utils/tenant-utils';
import { getShouldShowTenantPopup, setShouldShowTenantPopup } from '../../utils/storage-utils';

export function AccountNavButton(props: {
coreStart: CoreStart;
Expand All @@ -46,6 +47,30 @@ export function AccountNavButton(props: {
const [modal, setModal] = React.useState<React.ReactNode>(null);
const horizontalRule = <EuiHorizontalRule margin="xs" />;
const username = props.username;

const showTenantSwitchPanel = useCallback(
() =>
setModal(
<TenantSwitchPanel
coreStart={props.coreStart}
config={props.config}
handleClose={() => {
setModal(null);
}}
handleSwitchAndClose={() => {
setModal(null);
window.location.reload();
}}
/>
),
[props.config, props.coreStart]
);

if (getShouldShowTenantPopup()) {
setShouldShowTenantPopup(false);
showTenantSwitchPanel();
}

const contextMenuPanel = (
<div style={{ maxWidth: '256px' }}>
<EuiFlexGroup gutterSize="s">
Expand Down Expand Up @@ -81,23 +106,7 @@ export function AccountNavButton(props: {
View roles and identities
</EuiButtonEmpty>
{horizontalRule}
<EuiButtonEmpty
data-test-subj="switch-tenants"
size="xs"
onClick={() =>
setModal(
<TenantSwitchPanel
coreStart={props.coreStart}
config={props.config}
handleClose={() => setModal(null)}
handleSwitchAndClose={() => {
setModal(null);
window.location.reload();
}}
/>
)
}
>
<EuiButtonEmpty data-test-subj="switch-tenants" size="xs" onClick={showTenantSwitchPanel}>
Switch tenants
</EuiButtonEmpty>
{props.isInternalUser && (
Expand Down
66 changes: 0 additions & 66 deletions public/apps/account/tenant-selection-page.tsx

This file was deleted.

22 changes: 22 additions & 0 deletions public/apps/account/tenant-switch-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EuiButton,
EuiButtonEmpty,
EuiCallOut,
EuiCheckbox,
EuiModal,
EuiModalBody,
EuiModalFooter,
Expand All @@ -39,6 +40,7 @@ import {
} from '../configuration/utils/tenant-utils';
import { fetchAccountInfo } from './utils';
import { constructErrorMessageAndLog } from '../error-utils';
import { getSavedTenant, setSavedTenant } from '../../utils/storage-utils';

interface TenantSwitchPanelProps {
coreStart: CoreStart;
Expand All @@ -59,6 +61,11 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) {
const [tenantSwitchRadioIdSelected, setTenantSwitchRadioIdSelected] = React.useState<string>();
const [selectedCustomTenantOption, setSelectedCustomTenantOption] = React.useState<string>('');

// If saved tenant is present, set remember option to true
const [rememberSelection, setRememberSelection] = React.useState<boolean>(
Boolean(getSavedTenant())
);

const setCurrentTenant = (currentRawTenantName: string, currentUserName: string) => {
const resolvedTenantName = resolveTenantName(currentRawTenantName, currentUserName);

Expand Down Expand Up @@ -210,6 +217,12 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) {
setErrorCallOut('No target tenant is specified!');
} else {
try {
if (rememberSelection) {
setSavedTenant(tenantName);
} else {
setSavedTenant(null);
}

await changeTenant(tenantName);
props.handleSwitchAndClose();
} catch (e) {
Expand Down Expand Up @@ -263,6 +276,15 @@ export function TenantSwitchPanel(props: TenantSwitchPanelProps) {
<EuiSpacer />

{content}

<EuiSpacer />

<EuiCheckbox
id="remember"
label="Remember my selection next time I log in from this device."
checked={rememberSelection}
onChange={(e) => setRememberSelection(e.target.checked)}
/>
</EuiModalBody>
<EuiModalFooter>
<EuiButtonEmpty onClick={props.handleClose}>Cancel</EuiButtonEmpty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ exports[`Account menu -tenant switch panel confirm button and renders renders wh
}
/>
<EuiSpacer />
<EuiSpacer />
<EuiCheckbox
checked={false}
compressed={false}
disabled={false}
id="remember"
indeterminate={false}
label="Remember my selection next time I log in from this device."
onChange={[Function]}
/>
</EuiModalBody>
<EuiModalFooter>
<EuiButtonEmpty
Expand Down Expand Up @@ -195,6 +205,16 @@ exports[`Account menu -tenant switch panel confirm button and renders renders wh
}
/>
<EuiSpacer />
<EuiSpacer />
<EuiCheckbox
checked={false}
compressed={false}
disabled={false}
id="remember"
indeterminate={false}
label="Remember my selection next time I log in from this device."
onChange={[Function]}
/>
</EuiModalBody>
<EuiModalFooter>
<EuiButtonEmpty
Expand Down Expand Up @@ -304,6 +324,16 @@ exports[`Account menu -tenant switch panel confirm button and renders renders wh
}
/>
<EuiSpacer />
<EuiSpacer />
<EuiCheckbox
checked={false}
compressed={false}
disabled={false}
id="remember"
indeterminate={false}
label="Remember my selection next time I log in from this device."
onChange={[Function]}
/>
</EuiModalBody>
<EuiModalFooter>
<EuiButtonEmpty
Expand Down
Loading

0 comments on commit b0ac7c3

Please sign in to comment.