-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Mock IDP login page and role switcher #172257
Merged
azasypkin
merged 51 commits into
elastic:main
from
thomheymann:serverless-role-selector-ui
Jan 12, 2024
Merged
Changes from 48 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
92686f3
Add Mock IDP login page and role switcher
thomheymann f1eb108
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine f0a38eb
Separate mock IDP package
thomheymann 58e2e2b
Merge branch 'serverless-role-selector-ui' of https://github.com/thom…
thomheymann eb34508
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine f1d598f
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine 2e47f43
Update limits
thomheymann a704a2d
Merge branch 'serverless-role-selector-ui' of https://github.com/thom…
thomheymann 75755eb
Remove translations
thomheymann a458759
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 0501827
Fix plugin path
thomheymann 84d52cd
Merge branch 'serverless-role-selector-ui' of https://github.com/thom…
thomheymann f2c74a1
Fix snapshot test
thomheymann 40259a9
Fix offset
thomheymann 848ec7c
Merge branch 'main' of https://github.com/elastic/kibana into serverl…
thomheymann d6a7623
Fix application usage test
thomheymann 0da9c1c
.
thomheymann 3e2ed38
Only show relevant roles
thomheymann 15ee54a
Merge branch 'main' of https://github.com/elastic/kibana into serverl…
thomheymann 86827f2
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine d341fb5
Fix functional test
thomheymann 0ea1ae3
Merge branch 'serverless-role-selector-ui' of https://github.com/thom…
thomheymann 1f26219
Merge branch 'main' of https://github.com/elastic/kibana into serverl…
thomheymann 933e225
Fix dynamic imports
thomheymann 374d518
Merge branch 'main' of https://github.com/elastic/kibana into serverl…
thomheymann 6805755
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine aaa7c72
Fix cyclic dependencies
thomheymann 10edd06
Merge branch 'serverless-role-selector-ui' of https://github.com/thom…
thomheymann e52244e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 7dd3e44
Fix types
thomheymann aaece90
Merge branch 'main' into serverless-role-selector-ui
thomheymann a5f30a9
Merge branch 'main' into pr-172257-mock-idp
azasypkin d9d2b34
Merge branch 'main' into pr-172257-mock-idp
azasypkin 404d4ab
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 3f6db79
[will be reverted] add debug info
pgayvallet b14d5ee
Revert "[will be reverted] add debug info"
pgayvallet a759611
Exclude dev-only packages from `package-map.json`.
azasypkin 65df3a3
Revert unnecessary test/telemetry changes.
azasypkin 5b788e0
Merge branch 'main' into pr-172257-mock-idp
azasypkin b1cd8ab
Add workaround for missing `mock_idp` plugin in serverless tests.
azasypkin 2aafc3b
Register fake root only in production mode to please Cypress tests th…
azasypkin b9ab6fa
Merge branch 'main' into serverless-role-selector-ui
kibanamachine 6f6b5af
Apply builkite patch from @delanni
azasypkin e4c508d
Merge branch 'main' into serverless-role-selector-ui
kibanamachine b9a3298
Merge branch 'main' into pr-172257-mock-idp
azasypkin 4239759
Merge branch 'main' into pr-172257-mock-idp
azasypkin ae6aabf
A few minor tweaks.
azasypkin eaba0ef
Few more tweaks.
azasypkin a5a08e2
Merge branch 'main' into pr-172257-mock-idp
azasypkin 8294235
Merge branch 'main' into pr-172257-mock-idp
azasypkin f979aa7
Review#1: move `isDevOnly` check to `getDistPackagesFromRepo`.
azasypkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { plugin } from './plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { | ||
EuiButton, | ||
EuiPageTemplate, | ||
EuiEmptyPrompt, | ||
EuiComboBox, | ||
EuiInlineEditTitle, | ||
EuiFormRow, | ||
EuiSpacer, | ||
EuiComboBoxOptionOption, | ||
EuiButtonEmpty, | ||
} from '@elastic/eui'; | ||
import React, { ChangeEvent, FunctionComponent } from 'react'; | ||
import { FormikProvider, useFormik, Field, Form } from 'formik'; | ||
|
||
import { | ||
MOCK_IDP_SECURITY_ROLE_NAMES, | ||
MOCK_IDP_OBSERVABILITY_ROLE_NAMES, | ||
MOCK_IDP_SEARCH_ROLE_NAMES, | ||
} from '@kbn/mock-idp-utils/src/constants'; | ||
import { useAuthenticator } from './role_switcher'; | ||
|
||
export interface LoginPageProps { | ||
projectType?: string; | ||
} | ||
|
||
export const LoginPage: FunctionComponent<LoginPageProps> = ({ projectType }) => { | ||
const roles = | ||
projectType === 'security' | ||
? MOCK_IDP_SECURITY_ROLE_NAMES | ||
: projectType === 'observability' | ||
? MOCK_IDP_OBSERVABILITY_ROLE_NAMES | ||
: MOCK_IDP_SEARCH_ROLE_NAMES; | ||
|
||
const [, switchCurrentUser] = useAuthenticator(true); | ||
const formik = useFormik({ | ||
initialValues: { | ||
full_name: 'Test User', | ||
role: roles[0], | ||
}, | ||
async onSubmit(values) { | ||
await switchCurrentUser({ | ||
username: sanitizeUsername(values.full_name), | ||
full_name: values.full_name, | ||
email: sanitizeEmail(values.full_name), | ||
roles: [values.role], | ||
}); | ||
}, | ||
}); | ||
|
||
return ( | ||
<FormikProvider value={formik}> | ||
<EuiPageTemplate panelled={false}> | ||
<EuiPageTemplate.Section alignment="center"> | ||
<Form> | ||
<EuiEmptyPrompt | ||
iconType="user" | ||
layout="vertical" | ||
color="plain" | ||
body={ | ||
<> | ||
<Field | ||
as={EuiInlineEditTitle} | ||
name="full_name" | ||
heading="h2" | ||
inputAriaLabel="Edit name inline" | ||
value={formik.values.full_name} | ||
onChange={(event: ChangeEvent<HTMLInputElement>) => { | ||
formik.setFieldValue('full_name', event.target.value); | ||
}} | ||
onCancel={(previousValue: string) => { | ||
formik.setFieldValue('full_name', previousValue); | ||
}} | ||
isReadOnly={formik.isSubmitting} | ||
editModeProps={{ | ||
formRowProps: { | ||
error: formik.errors.full_name, | ||
}, | ||
}} | ||
validate={(value: string) => { | ||
if (value.trim().length === 0) { | ||
return 'Name cannot be empty'; | ||
} | ||
}} | ||
isInvalid={!!formik.errors.full_name} | ||
placeholder="Enter your name" | ||
css={{ width: 350 }} | ||
/> | ||
<EuiSpacer size="m" /> | ||
|
||
<EuiFormRow error={formik.errors.role} isInvalid={!!formik.errors.role}> | ||
<Field | ||
as={EuiComboBox} | ||
name="role" | ||
placeholder="Select your role" | ||
singleSelection={{ asPlainText: true }} | ||
options={roles.map((role) => ({ label: role }))} | ||
selectedOptions={ | ||
formik.values.role ? [{ label: formik.values.role }] : undefined | ||
} | ||
onCreateOption={(value: string) => { | ||
formik.setFieldValue('role', value); | ||
}} | ||
onChange={(selectedOptions: EuiComboBoxOptionOption[]) => { | ||
formik.setFieldValue( | ||
'role', | ||
selectedOptions.length === 0 ? '' : selectedOptions[0].label | ||
); | ||
}} | ||
validate={(value: string) => { | ||
if (value.trim().length === 0) { | ||
return 'Role cannot be empty'; | ||
} | ||
}} | ||
isInvalid={!!formik.errors.role} | ||
isClearable={false} | ||
fullWidth | ||
/> | ||
</EuiFormRow> | ||
</> | ||
} | ||
actions={[ | ||
<EuiButton | ||
type="submit" | ||
disabled={!formik.isValid} | ||
isLoading={formik.isSubmitting} | ||
fill | ||
> | ||
Log in | ||
</EuiButton>, | ||
<EuiButtonEmpty size="xs" href="/"> | ||
More login options | ||
</EuiButtonEmpty>, | ||
]} | ||
/> | ||
</Form> | ||
</EuiPageTemplate.Section> | ||
</EuiPageTemplate> | ||
</FormikProvider> | ||
); | ||
}; | ||
|
||
const sanitizeUsername = (username: string) => | ||
username.replace(/[^a-zA-Z0-9_]/g, '_').toLowerCase(); | ||
const sanitizeEmail = (email: string) => `${sanitizeUsername(email)}@elastic.co`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { PluginInitializer } from '@kbn/core-plugins-browser'; | ||
import { AppNavLinkStatus } from '@kbn/core-application-browser'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { KibanaThemeProvider } from '@kbn/react-kibana-context-theme'; | ||
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public'; | ||
import { I18nProvider } from '@kbn/i18n-react'; | ||
import { MOCK_IDP_LOGIN_PATH } from '@kbn/mock-idp-utils/src/constants'; | ||
import type { CloudStart, CloudSetup } from '@kbn/cloud-plugin/public'; | ||
import { RoleSwitcher } from './role_switcher'; | ||
|
||
export interface PluginSetupDependencies { | ||
cloud?: CloudSetup; | ||
} | ||
|
||
export interface PluginStartDependencies { | ||
cloud?: CloudStart; | ||
} | ||
|
||
export const plugin: PluginInitializer< | ||
void, | ||
void, | ||
PluginSetupDependencies, | ||
PluginStartDependencies | ||
> = () => ({ | ||
setup(coreSetup, plugins) { | ||
// Register Mock IDP login page | ||
coreSetup.http.anonymousPaths.register(MOCK_IDP_LOGIN_PATH); | ||
coreSetup.application.register({ | ||
id: 'mock_idp', | ||
title: 'Mock IDP', | ||
chromeless: true, | ||
appRoute: MOCK_IDP_LOGIN_PATH, | ||
navLinkStatus: AppNavLinkStatus.hidden, | ||
mount: async (params) => { | ||
const [[coreStart], { LoginPage }] = await Promise.all([ | ||
coreSetup.getStartServices(), | ||
import('./login_page'), | ||
]); | ||
|
||
ReactDOM.render( | ||
<KibanaThemeProvider theme={coreStart.theme}> | ||
<KibanaContextProvider services={coreStart}> | ||
<I18nProvider> | ||
<LoginPage projectType={plugins.cloud?.serverless.projectType} /> | ||
</I18nProvider> | ||
</KibanaContextProvider> | ||
</KibanaThemeProvider>, | ||
params.element | ||
); | ||
|
||
return () => ReactDOM.unmountComponentAtNode(params.element); | ||
}, | ||
}); | ||
}, | ||
start(coreStart, plugins) { | ||
// Register role switcher dropdown menu in the top right navigation of the Kibana UI | ||
coreStart.chrome.navControls.registerRight({ | ||
order: 4000 + 1, // Make sure it comes after the user menu | ||
mount: (element: HTMLElement) => { | ||
ReactDOM.render( | ||
<KibanaThemeProvider theme={coreStart.theme}> | ||
<KibanaContextProvider services={coreStart}> | ||
<I18nProvider> | ||
<RoleSwitcher projectType={plugins.cloud?.serverless.projectType} /> | ||
</I18nProvider> | ||
</KibanaContextProvider> | ||
</KibanaThemeProvider>, | ||
element | ||
); | ||
return () => ReactDOM.unmountComponentAtNode(element); | ||
}, | ||
}); | ||
}, | ||
stop() {}, | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can feel the pain and suffering in this comment addition 😄