Skip to content
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

fix: cluster-wizard UI & oidc-scopes #3209

Merged
merged 13 commits into from
Aug 27, 2024
Prev Previous commit
Next Next commit
fix: list input instead of formfield for scopes
  • Loading branch information
chriskari committed Aug 25, 2024
commit b16ccde54fd443732a6ed514af1e8436f572c4d9
13 changes: 5 additions & 8 deletions src/components/Clusters/components/AuthForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import * as Inputs from 'shared/ResourceForm/inputs';
import { getUser, getUserIndex } from '../shared';

import { spacing } from '@ui5/webcomponents-react-base';

export const AUTH_FORM_TOKEN = 'Token';
export const AUTH_FORM_OIDC = 'OIDC';
export const DEFAULT_SCOPE_VALUE = 'openid';
import { TextArrayInput } from 'shared/ResourceForm/fields';

const OIDCform = ({ resource, setResource, ...props }) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -57,11 +54,11 @@ const OIDCform = ({ resource, setResource, ...props }) => {
input={Inputs.Text}
aria-label="client-secret"
/>
<ResourceForm.FormField
<TextArrayInput
required
propertyPath="$.scope"
label={t('clusters.wizard.auth.scopes')}
input={Inputs.Text}
defaultOpen
propertyPath="$.scopes"
title={t('clusters.wizard.auth.scopes')}
aria-label="scopes"
/>
</ResourceForm.Wrapper>
Expand Down
25 changes: 18 additions & 7 deletions src/components/Clusters/components/oidc-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const OIDC_PARAM_NAMES = new Map([
['--oidc-issuer-url', 'issuerUrl'],
['--oidc-client-id', 'clientId'],
['--oidc-client-secret', 'clientSecret'],
['--oidc-extra-scope', 'scope'],
['--oidc-extra-scope', 'scopes'],
]);

export function parseOIDCparams({ exec: commandData }: KubeconfigOIDCAuth) {
Expand Down Expand Up @@ -40,8 +40,19 @@ export function parseOIDCparams({ exec: commandData }: KubeconfigOIDCAuth) {
if (!OIDC_PARAM_NAMES.has(argKey)) return;

const outputKey = OIDC_PARAM_NAMES.get(argKey)!;
if (output[outputKey]) output[outputKey] += ' ' + argValue;
else output[outputKey] = argValue;
if (output[outputKey]) {
if (outputKey === 'scopes') {
output[outputKey].push(argValue);
} else {
output[outputKey] += ' ' + argValue;
}
} else {
if (outputKey === 'scopes') {
output[outputKey] = [argValue];
} else {
output[outputKey] = argValue;
}
}
});

return output;
Expand All @@ -60,7 +71,7 @@ export function createLoginCommand(
issuerUrl: string;
clientId: string;
clientSecret?: string;
scope: string;
scopes: string[];
},
execRest: object,
): LoginCommand {
Expand All @@ -74,9 +85,9 @@ export function createLoginCommand(
`--oidc-issuer-url=${oidcConfig.issuerUrl || ''}`,
`--oidc-client-id=${oidcConfig.clientId || ''}`,
`--oidc-client-secret=${oidcConfig.clientSecret || ''}`,
oidcConfig.scope
? `--oidc-extra-scope=${oidcConfig.scope || ''}`
: `--oidc-extra-scope=openid ${oidcConfig.scope || ''}`,
...(oidcConfig.scopes?.length
? oidcConfig.scopes.map(scope => `--oidc-extra-scope=${scope || ''}`)
: [`--oidc-extra-scope=openid`]),
'--grant-type=auto',
],
};
Expand Down
18 changes: 9 additions & 9 deletions src/components/Clusters/views/EditCluster/EditCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
import { useSetRecoilState } from 'recoil';

import { ResourceForm } from 'shared/ResourceForm';
import { K8sNameField } from 'shared/ResourceForm/fields';
import { K8sNameField, TextArrayInput } from 'shared/ResourceForm/fields';
import { ChooseStorage } from 'components/Clusters/components/ChooseStorage';
import { ErrorBoundary } from 'shared/components/ErrorBoundary/ErrorBoundary';
import { useNotification } from 'shared/contexts/NotificationContext';
Expand All @@ -22,7 +22,7 @@ import { getUserIndex } from '../../shared';
export const findInitialValues = (kubeconfig, id, userIndex = 0) => {
const elementsWithId =
kubeconfig?.users?.[userIndex]?.user?.exec?.args.filter(el =>
el.includes(id),
el?.includes(id),
) || [];
const regex = new RegExp(`${id}=(?<value>.*)`);
const values = [];
Expand All @@ -41,7 +41,7 @@ export const findInitialValue = (kubeconfig, id, userIndex = 0) => {
if (kubeconfig?.users?.[userIndex]?.user?.exec?.args) {
const elementWithId = kubeconfig?.users?.[
userIndex
]?.user?.exec?.args.find(el => el.includes(id));
]?.user?.exec?.args.find(el => el?.includes(id));
const regex = new RegExp(`${id}=(?<value>.*)`);
return regex.exec(elementWithId)?.groups?.value || '';
}
Expand Down Expand Up @@ -107,9 +107,9 @@ export const ClusterDataForm = ({
`--oidc-issuer-url=${config.issuerUrl}`,
`--oidc-client-id=${config.clientId}`,
`--oidc-client-secret=${config.clientSecret}`,
findInitialValues(kubeconfig, 'oidc-extra-scope', userIndex)
? `--oidc-extra-scope=${config.scopes}`
: `--oidc-extra-scope=openid ${config.scopes}`,
...(config.scopes?.length
? config.scopes.map(scope => `--oidc-extra-scope=${scope || ''}`)
: [`--oidc-extra-scope=openid`]),
'--grant-type=auto',
],
};
Expand Down Expand Up @@ -145,10 +145,10 @@ export const ClusterDataForm = ({
createOIDC('clientSecret', val);
}}
/>
<ResourceForm.FormField
label={t('clusters.labels.scopes')}
input={Inputs.Text}
<TextArrayInput
required
defaultOpen
title={t('clusters.labels.scopes')}
value={scopes}
setValue={val => {
createOIDC('scopes', val);
Expand Down
Loading