oscap: a policy isn't a profile

There was a mixup on our side between what is a profile and what is a
policy. Long story short, a policy a super set of rules including a
profile. For now the wizard is only able to apply profiles and no
policies on images. So let's fix the terminology there.
This commit is contained in:
Thomas Lavocat 2023-10-17 17:28:41 +02:00 committed by Klara Simickova
parent d60c6cb74b
commit 1c1290f7ed
9 changed files with 67 additions and 66 deletions

View file

@ -94,9 +94,9 @@ const onSave = (values) => {
}
}
if (values['oscap-policy']) {
if (values['oscap-profile']) {
customizations.openscap = {
profile_id: values['oscap-policy'],
profile_id: values['oscap-profile'],
};
}
@ -475,9 +475,8 @@ const requestToState = (composeRequest, distroInfo, isProd, enableOscap) => {
formState['register-system'] = 'register-later';
}
// oscap policy
if (enableOscap) {
formState['oscap-policy'] =
formState['oscap-profile'] =
composeRequest?.customizations?.openscap?.profile_id;
}

View file

@ -54,8 +54,8 @@ const FileSystemConfiguration = ({ ...props }) => {
const bodyref = useRef();
const [rows, setRows] = useState([initialRow]);
const oscapPolicy = getState()?.values?.['oscap-policy'];
const hasNoOscapPolicy = !oscapPolicy;
const oscapProfile = getState()?.values?.['oscap-profile'];
const hasNoOscapProfile = !oscapProfile;
const hasCustomizations = !(
getState()?.values?.['file-system-configuration'] === undefined ||
getState().values['file-system-configuration'].length === 1
@ -68,11 +68,11 @@ const FileSystemConfiguration = ({ ...props }) => {
} = useGetOscapCustomizationsQuery(
{
distribution: getState()?.values?.['release'],
profile: oscapPolicy,
profile: oscapProfile,
},
{
// Don't override the user's data if they made customizations
skip: hasNoOscapPolicy || hasCustomizations,
skip: hasNoOscapProfile || hasCustomizations,
}
);

View file

@ -29,13 +29,15 @@ const reinitDependingSteps = (change) => {
};
/**
* Component for the user to select the policy to apply to their image.
* The selected policy will be stored in the `oscap-policy` form state variable.
* Component for the user to select the profile to apply to their image.
* The selected profile will be stored in the `oscap-profile` form state variable.
* The Component is shown or not depending on the ShowSelector variable.
*/
const PolicySelector = ({ input, showSelector }) => {
const ProfileSelector = ({ input, showSelector }) => {
const { change, getState } = useFormApi();
const [policy, selectPolicy] = useState(getState()?.values?.['oscap-policy']);
const [profile, selectProfile] = useState(
getState()?.values?.['oscap-profile']
);
const [isOpen, setIsOpen] = useState(false);
const { data, isFetching, isSuccess, isError, refetch } =
@ -60,13 +62,13 @@ const PolicySelector = ({ input, showSelector }) => {
};
const handleClear = () => {
selectPolicy(undefined);
selectProfile(undefined);
change(input.name, undefined);
reinitDependingSteps(change);
};
const setPolicy = (_, selection) => {
selectPolicy(selection);
const setProfile = (_, selection) => {
selectProfile(selection);
setIsOpen(false);
change(input.name, selection);
reinitDependingSteps(change);
@ -76,98 +78,98 @@ const PolicySelector = ({ input, showSelector }) => {
return (
<FormGroup
isRequired={true}
label={'Policy to use for this image'}
data-testid="policies-form-group"
label={'Profile to use for this image'}
data-testid="profiles-form-group"
>
<Select
ouiaId="policySelect"
ouiaId="profileSelect"
variant={SelectVariant.typeahead}
onToggle={handleToggle}
onSelect={setPolicy}
onSelect={setProfile}
onClear={handleClear}
selections={policy}
selections={profile}
isOpen={isOpen}
placeholderText="Select a policy"
typeAheadAriaLabel="Select a policy"
placeholderText="Select a profile"
typeAheadAriaLabel="Select a profile"
isDisabled={!isSuccess}
>
{isSuccess &&
data.map((key, index) => <SelectOption key={index} value={key} />)}
{isFetching && (
<SelectOption isNoResultsOption={true} data-testid="policies-loading">
<SelectOption isNoResultsOption={true} data-testid="profiles-loading">
<Spinner isSVG size="md" />
</SelectOption>
)}
</Select>
{isError && (
<Alert
title="Error fetching the policies"
title="Error fetching the profiles"
variant="danger"
isPlain
isInline
>
Cannot get the list of policies
Cannot get the list of profiles
</Alert>
)}
</FormGroup>
);
};
PolicySelector.propTypes = {
ProfileSelector.propTypes = {
input: PropTypes.any,
showSelector: PropTypes.bool,
};
/**
* Component to prompt the use with two choices:
* - to add a policy, in which case the PolicySelector will allow the user to
* pick a policy to be stored in the `oscap-policy` variable.
* - to not add a policy, in which case the `oscap-policy` form state goes
* - to add a profile, in which case the ProfileSelector will allow the user to
* pick a profile to be stored in the `oscap-profile` variable.
* - to not add a profile, in which case the `oscap-profile` form state goes
* undefined.
*/
const AddPolicy = ({ input }) => {
const AddProfile = ({ input }) => {
const { change, getState } = useFormApi();
const oscapPolicy = getState()?.values?.['oscap-policy'];
const [wantsPolicy, setWantsPolicy] = useState(oscapPolicy !== undefined);
const oscapProfile = getState()?.values?.['oscap-profile'];
const [wantsProfile, setWantsProfile] = useState(oscapProfile !== undefined);
return (
<>
<FormGroup label="Compliance policy">
<FormGroup label="Compliance profile">
<Radio
name="add-a-policy"
name="add-a-profile"
className="pf-u-mt-md"
data-testid="add-a-policy-radio"
id="add-a-policy"
label="Add a policy"
isChecked={wantsPolicy}
data-testid="add-a-profile-radio"
id="add-a-profile"
label="Add a profile"
isChecked={wantsProfile}
onChange={() => {
setWantsPolicy(true);
setWantsProfile(true);
reinitDependingSteps(change);
}}
/>
<Radio
name="dont-add-a-policy"
name="dont-add-a-profile"
className="pf-u-mt-md"
data-testid="dont-add-a-policy-radio"
id="dont-add-a-policy"
label="Do not add a policy"
isChecked={!wantsPolicy}
data-testid="dont-add-a-profile-radio"
id="dont-add-a-profile"
label="Do not add a profile"
isChecked={!wantsProfile}
onChange={() => {
setWantsPolicy(false);
setWantsProfile(false);
change(input.name, undefined);
reinitDependingSteps(change);
}}
/>
</FormGroup>
<PolicySelector input={input} showSelector={wantsPolicy} />
<ProfileSelector input={input} showSelector={wantsProfile} />
</>
);
};
AddPolicy.propTypes = {
AddProfile.propTypes = {
input: PropTypes.object,
};
export const Oscap = ({ ...props }) => {
const { input } = useFieldApi(props);
return <AddPolicy input={input} />;
return <AddProfile input={input} />;
};

View file

@ -129,16 +129,16 @@ const Packages = ({ getAllPackages, isSuccess }) => {
);
const firstInputElement = useRef(null);
const oscapPolicy = getState()?.values?.['oscap-policy'];
const oscapProfile = getState()?.values?.['oscap-profile'];
const { data: customizations, isSuccess: isSuccessCustomizations } =
useGetOscapCustomizationsQuery(
{
distribution: getState()?.values?.['release'],
profile: oscapPolicy,
profile: oscapProfile,
},
{
skip: !oscapPolicy,
skip: !oscapProfile,
}
);
useEffect(() => {

View file

@ -173,7 +173,7 @@ const ReviewStep = () => {
<ImageDetailsList />
</ExpandableSection>
)}
{getState()?.values?.['oscap-policy'] && (
{getState()?.values?.['oscap-profile'] && (
<ExpandableSection
toggleContent={'OpenSCAP Compliance'}
onToggle={onToggleOscapDetails}

View file

@ -592,7 +592,7 @@ export const ImageDetailsList = () => {
export const OscapList = () => {
const { getState } = useFormApi();
const oscapPolicy = getState()?.values?.['oscap-policy'];
const oscapProfile = getState()?.values?.['oscap-profile'];
return (
<TextContent>
<TextList component={TextListVariants.dl}>
@ -600,10 +600,10 @@ export const OscapList = () => {
component={TextListItemVariants.dt}
className="pf-u-min-width"
>
Policy
Profile
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{oscapPolicy}
{oscapProfile}
</TextListItem>
</TextList>
<br />

View file

@ -69,7 +69,7 @@ const fileSystemConfigurationStep = {
},
],
condition: {
when: 'oscap-policy',
when: 'oscap-profile',
is: undefined,
},
},
@ -87,7 +87,7 @@ const fileSystemConfigurationStep = {
when: 'file-system-config-radio',
is: 'manual',
},
{ not: [{ when: 'oscap-policy', is: undefined }] },
{ not: [{ when: 'oscap-profile', is: undefined }] },
],
},
},
@ -127,7 +127,7 @@ const fileSystemConfigurationStep = {
condition: {
or: [
{ when: 'file-system-config-radio', is: 'automatic' },
{ when: 'oscap-policy', is: undefined },
{ when: 'oscap-profile', is: undefined },
],
},
},

View file

@ -20,14 +20,14 @@ const oscapStep = {
name: 'oscap-text-component',
label: (
<Text>
Monitor regulatory compliance policies of registered RHEL systems you
Monitor regulatory compliance profiles of registered RHEL systems you
must adhere to via OpenSCAP.
</Text>
),
},
{
component: 'oscap-profile-selector',
name: 'oscap-policy',
name: 'oscap-profile',
label: 'Available profiles for the distribution',
},
],