-
Notifications
You must be signed in to change notification settings - Fork 63
feat(Permissions > Identities): add OIDC configuration from Settings #1974
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
Open
kimanhou
wants to merge
1
commit into
canonical:main
Choose a base branch
from
kimanhou:WD-34784-oidc-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
This file contains hidden or 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 hidden or 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,48 @@ | ||
| import type { FC } from "react"; | ||
| import OidcConfigurationModal from "./OidcConfigurationModal"; | ||
| import { Button, usePortal } from "@canonical/react-components"; | ||
| import { useServerEntitlements } from "util/entitlements/server"; | ||
|
|
||
| interface Props { | ||
| isDisabled?: boolean; | ||
| className?: string; | ||
| onClose?: () => void; | ||
| } | ||
|
|
||
| const OidcConfigurationBtn: FC<Props> = ({ | ||
| isDisabled, | ||
| className, | ||
| onClose, | ||
| }) => { | ||
| const { openPortal, closePortal, isOpen, Portal } = usePortal(); | ||
| const { canEditServerConfiguration } = useServerEntitlements(); | ||
|
|
||
| const handleClose = () => { | ||
| closePortal(); | ||
| onClose?.(); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| {isOpen && ( | ||
| <Portal> | ||
| <OidcConfigurationModal close={handleClose} /> | ||
| </Portal> | ||
| )} | ||
| <Button | ||
| onClick={openPortal} | ||
| className={className} | ||
| disabled={isDisabled || !canEditServerConfiguration()} | ||
| title={ | ||
| canEditServerConfiguration() | ||
| ? "" | ||
| : "You do not have permission to edit server configuration" | ||
| } | ||
| > | ||
| Configure single sign-on | ||
| </Button> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default OidcConfigurationBtn; |
This file contains hidden or 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,109 @@ | ||
| import type { FC } from "react"; | ||
| import type { MainTableRow } from "@canonical/react-components/dist/components/MainTable/MainTable"; | ||
| import { | ||
| MainTable, | ||
| Notification, | ||
| Spinner, | ||
| useNotify, | ||
| } from "@canonical/react-components"; | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import { fetchConfigOptions } from "api/server"; | ||
| import NotificationRow from "components/NotificationRow"; | ||
| import { useSupportedFeatures } from "context/useSupportedFeatures"; | ||
| import { useClusteredSettings } from "context/useClusteredSettings"; | ||
| import SsoNotification from "pages/permissions/SsoNotification"; | ||
| import { getSettingRow } from "pages/settings/SettingsRow"; | ||
| import { toConfigFields } from "util/config"; | ||
| import { queryKeys } from "util/queryKeys"; | ||
| import { getConfigFieldClusteredValue } from "util/settings"; | ||
|
|
||
| interface Props { | ||
| closeModal: () => void; | ||
| } | ||
|
|
||
| const OidcConfigurationForm: FC<Props> = ({ closeModal }: Props) => { | ||
| const notify = useNotify(); | ||
| const { | ||
| hasMetadataConfiguration, | ||
| settings, | ||
| isSettingsLoading, | ||
| settingsError, | ||
| } = useSupportedFeatures(); | ||
| const { data: configOptions, isLoading: isConfigOptionsLoading } = useQuery({ | ||
| queryKey: [queryKeys.configOptions], | ||
| queryFn: async () => fetchConfigOptions(hasMetadataConfiguration), | ||
| }); | ||
| const { | ||
| data: clusteredSettings = [], | ||
| isLoading: isClusteredSettingsLoading, | ||
| error: clusterError, | ||
| } = useClusteredSettings(); | ||
|
|
||
| if (clusterError) { | ||
| notify.failure("Loading clustered settings failed", clusterError); | ||
| closeModal(); | ||
| return null; | ||
| } | ||
|
|
||
| if (settingsError) { | ||
| notify.failure("Loading settings failed", settingsError); | ||
| closeModal(); | ||
| return null; | ||
| } | ||
|
|
||
| if ( | ||
| isConfigOptionsLoading || | ||
| isSettingsLoading || | ||
| isClusteredSettingsLoading | ||
| ) { | ||
| return <Spinner className="u-loader" text="Loading..." isMainComponent />; | ||
| } | ||
|
|
||
| const headers = [ | ||
| { content: "Group", className: "u-hide" }, | ||
| { content: "Key", className: "key" }, | ||
| { content: "Value" }, | ||
| ]; | ||
| const configFields = toConfigFields(configOptions?.configs?.server ?? {}); | ||
| const rows: MainTableRow[] = configFields | ||
| .filter((t) => t.key.startsWith("oidc")) | ||
| .map((configField) => { | ||
| const clusteredValue = getConfigFieldClusteredValue( | ||
| clusteredSettings, | ||
| configField, | ||
| ); | ||
|
|
||
| return getSettingRow( | ||
| configField, | ||
| false, | ||
| clusteredValue, | ||
| () => {}, | ||
| settings, | ||
| (message) => notify.success(message), | ||
| ); | ||
| }); | ||
|
|
||
| return ( | ||
| <> | ||
| {!hasMetadataConfiguration && ( | ||
| <Notification | ||
| severity="caution" | ||
| title="Get access to SSO configuration settings" | ||
| titleElement="h2" | ||
| > | ||
| Update to LXD v5.19.0 or later to access these settings | ||
| </Notification> | ||
| )} | ||
| <SsoNotification /> | ||
| <NotificationRow className="u-no-padding" /> | ||
| <MainTable | ||
| id="settings-table" | ||
| headers={headers} | ||
| rows={rows} | ||
| emptyStateMsg="No data to display" | ||
| /> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default OidcConfigurationForm; | ||
This file contains hidden or 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,28 @@ | ||
| import type { FC, KeyboardEvent } from "react"; | ||
| import { Modal } from "@canonical/react-components"; | ||
| import OidcConfigurationForm from "pages/permissions/OidcConfigurationForm"; | ||
|
|
||
| interface Props { | ||
| close: () => void; | ||
| } | ||
|
|
||
| const OidcConfigurationModal: FC<Props> = ({ close }) => { | ||
|
edlerd marked this conversation as resolved.
|
||
| const handleEscKey = (e: KeyboardEvent<HTMLElement>) => { | ||
| if (e.key === "Escape") { | ||
| close(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal | ||
| close={close} | ||
| className="edit-oidc-config settings" | ||
|
edlerd marked this conversation as resolved.
|
||
| title="Single sign-on configuration" | ||
| onKeyDown={handleEscKey} | ||
| > | ||
| <OidcConfigurationForm closeModal={close} /> | ||
| </Modal> | ||
| ); | ||
| }; | ||
|
|
||
| export default OidcConfigurationModal; | ||
This file contains hidden or 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 hidden or 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,58 @@ | ||
| import type { FC } from "react"; | ||
| import { cloneElement } from "react"; | ||
| import { ContextualMenu } from "@canonical/react-components"; | ||
| import { | ||
| largeScreenBreakpoint, | ||
| useIsScreenBelow, | ||
| } from "context/useIsScreenBelow"; | ||
| import OidcConfigurationBtn from "pages/permissions/OidcConfigurationBtn"; | ||
| import CreateTlsIdentityBtn from "pages/permissions/CreateTlsIdentityBtn"; | ||
|
|
||
| interface Props { | ||
| openPanel: () => void; | ||
| } | ||
|
|
||
| const PermissionIdentitiesActions: FC<Props> = ({ openPanel }) => { | ||
| const isSmallScreen = useIsScreenBelow(largeScreenBreakpoint); | ||
|
|
||
| const classname = isSmallScreen | ||
| ? "p-contextual-menu__link" | ||
| : "p-segmented-control__button"; | ||
|
|
||
| const menuElements = [ | ||
| <OidcConfigurationBtn key="oidc" className={classname} />, | ||
| <CreateTlsIdentityBtn | ||
| key="create" | ||
| openPanel={openPanel} | ||
| className={classname} | ||
| />, | ||
| ]; | ||
|
|
||
| return ( | ||
| <> | ||
| {isSmallScreen ? ( | ||
| <ContextualMenu | ||
| closeOnOutsideClick={false} | ||
| toggleLabel="Actions" | ||
| position="left" | ||
| hasToggleIcon | ||
| title="actions" | ||
| > | ||
| {(close: () => void) => ( | ||
| <span> | ||
| {[...menuElements].map((item) => | ||
| cloneElement(item, { onClose: close }), | ||
| )} | ||
| </span> | ||
| )} | ||
| </ContextualMenu> | ||
| ) : ( | ||
| <div className="p-segmented-control"> | ||
| <div className="p-segmented-control__list">{menuElements}</div> | ||
| </div> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default PermissionIdentitiesActions; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.