Wizard: support openscap compliance customisation in state
Merges all the compliance related state into a single compliance object.
This commit is contained in:
parent
c6a9d0a17a
commit
110e1d7d75
2 changed files with 87 additions and 22 deletions
|
|
@ -26,6 +26,8 @@ import {
|
|||
ImageRequest,
|
||||
ImageTypes,
|
||||
OpenScap,
|
||||
OpenScapCompliance,
|
||||
OpenScapProfile,
|
||||
Services,
|
||||
Subscription,
|
||||
UploadTypes,
|
||||
|
|
@ -44,6 +46,10 @@ import {
|
|||
selectBaseUrl,
|
||||
selectBlueprintDescription,
|
||||
selectBlueprintName,
|
||||
ComplianceType,
|
||||
selectCompliancePolicyID,
|
||||
selectComplianceProfileID,
|
||||
selectComplianceType,
|
||||
selectCustomRepositories,
|
||||
selectDistribution,
|
||||
selectGcpAccountType,
|
||||
|
|
@ -55,7 +61,6 @@ import {
|
|||
selectPackages,
|
||||
selectPayloadRepositories,
|
||||
selectRecommendedRepositories,
|
||||
selectProfile,
|
||||
selectRegistrationType,
|
||||
selectServerUrl,
|
||||
selectServices,
|
||||
|
|
@ -166,17 +171,42 @@ function commonRequestToState(
|
|||
if (arch !== 'x86_64' && arch !== 'aarch64') {
|
||||
throw new Error(`image type: ${arch} has no implementation yet`);
|
||||
}
|
||||
|
||||
let oscapProfile = undefined;
|
||||
let compliancePolicyID = undefined;
|
||||
if (request.customizations?.openscap) {
|
||||
const oscapAsProfile = request.customizations?.openscap as OpenScapProfile;
|
||||
if (oscapAsProfile.profile_id !== '') {
|
||||
oscapProfile = oscapAsProfile.profile_id as DistributionProfileItem;
|
||||
}
|
||||
const oscapAsCompliance = request.customizations
|
||||
?.openscap as OpenScapCompliance;
|
||||
if (oscapAsCompliance.policy_id !== '') {
|
||||
compliancePolicyID = oscapAsCompliance.policy_id;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
details: {
|
||||
blueprintName: request.name || '',
|
||||
blueprintDescription: request.description || '',
|
||||
},
|
||||
openScap: request.customizations
|
||||
? {
|
||||
profile: request.customizations.openscap
|
||||
?.profile_id as DistributionProfileItem,
|
||||
}
|
||||
: initialState.openScap,
|
||||
compliance:
|
||||
compliancePolicyID !== undefined
|
||||
? {
|
||||
complianceType: 'compliance' as ComplianceType,
|
||||
policyID: compliancePolicyID,
|
||||
profileID: undefined,
|
||||
policyTitle: undefined,
|
||||
}
|
||||
: oscapProfile !== undefined
|
||||
? {
|
||||
complianceType: 'openscap' as ComplianceType,
|
||||
profileID: oscapProfile,
|
||||
policyID: undefined,
|
||||
policyTitle: undefined,
|
||||
}
|
||||
: initialState.compliance,
|
||||
firstBoot: request.customizations
|
||||
? {
|
||||
script: getFirstBootScript(request.customizations.files),
|
||||
|
|
@ -442,7 +472,7 @@ const getCustomizations = (state: RootState, orgID: string): Customizations => {
|
|||
packages: getPackages(state),
|
||||
payload_repositories: getPayloadRepositories(state),
|
||||
custom_repositories: getCustomRepositories(state),
|
||||
openscap: getOpenscapProfile(state),
|
||||
openscap: getOpenscap(state),
|
||||
filesystem: getFileSystem(state),
|
||||
users: undefined,
|
||||
services: getServices(state),
|
||||
|
|
@ -487,11 +517,17 @@ const getServices = (state: RootState): Services | undefined => {
|
|||
};
|
||||
};
|
||||
|
||||
const getOpenscapProfile = (state: RootState): OpenScap | undefined => {
|
||||
const profile = selectProfile(state);
|
||||
if (profile) {
|
||||
const getOpenscap = (state: RootState): OpenScap | undefined => {
|
||||
const complianceType = selectComplianceType(state);
|
||||
const profile = selectComplianceProfileID(state);
|
||||
const policy = selectCompliancePolicyID(state);
|
||||
|
||||
if (complianceType === 'openscap' && profile) {
|
||||
return { profile_id: profile };
|
||||
}
|
||||
if (complianceType === 'compliance' && policy) {
|
||||
return { policy_id: policy };
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { v4 as uuidv4 } from 'uuid';
|
|||
import { ApiRepositoryResponseRead } from './contentSourcesApi';
|
||||
import {
|
||||
CustomRepository,
|
||||
DistributionProfileItem,
|
||||
Distributions,
|
||||
ImageRequest,
|
||||
ImageTypes,
|
||||
|
|
@ -40,6 +39,8 @@ export type RegistrationType =
|
|||
| 'register-now-insights'
|
||||
| 'register-now-rhc';
|
||||
|
||||
export type ComplianceType = 'openscap' | 'compliance';
|
||||
|
||||
export type wizardState = {
|
||||
env: {
|
||||
serverUrl: string;
|
||||
|
|
@ -72,8 +73,11 @@ export type wizardState = {
|
|||
registrationType: RegistrationType;
|
||||
activationKey: ActivationKeys['name'];
|
||||
};
|
||||
openScap: {
|
||||
profile: DistributionProfileItem | undefined;
|
||||
compliance: {
|
||||
complianceType: ComplianceType;
|
||||
policyID: string | undefined;
|
||||
profileID: string | undefined;
|
||||
policyTitle: string | undefined;
|
||||
};
|
||||
fileSystem: {
|
||||
mode: FileSystemConfigurationType;
|
||||
|
|
@ -141,8 +145,11 @@ export const initialState: wizardState = {
|
|||
registrationType: 'register-now-rhc',
|
||||
activationKey: undefined,
|
||||
},
|
||||
openScap: {
|
||||
profile: undefined,
|
||||
compliance: {
|
||||
complianceType: 'openscap',
|
||||
policyID: undefined,
|
||||
profileID: undefined,
|
||||
policyTitle: undefined,
|
||||
},
|
||||
fileSystem: {
|
||||
mode: 'automatic',
|
||||
|
|
@ -254,8 +261,20 @@ export const selectActivationKey = (state: RootState) => {
|
|||
return state.wizard.registration.activationKey;
|
||||
};
|
||||
|
||||
export const selectProfile = (state: RootState) => {
|
||||
return state.wizard.openScap.profile;
|
||||
export const selectComplianceProfileID = (state: RootState) => {
|
||||
return state.wizard.compliance.profileID;
|
||||
};
|
||||
|
||||
export const selectCompliancePolicyID = (state: RootState) => {
|
||||
return state.wizard.compliance.policyID;
|
||||
};
|
||||
|
||||
export const selectCompliancePolicyTitle = (state: RootState) => {
|
||||
return state.wizard.compliance.policyTitle;
|
||||
};
|
||||
|
||||
export const selectComplianceType = (state: RootState) => {
|
||||
return state.wizard.compliance.complianceType;
|
||||
};
|
||||
|
||||
export const selectFileSystemConfigurationType = (state: RootState) => {
|
||||
|
|
@ -427,11 +446,20 @@ export const wizardSlice = createSlice({
|
|||
) => {
|
||||
state.registration.activationKey = action.payload;
|
||||
},
|
||||
changeOscapProfile: (
|
||||
changeComplianceType: (state, action: PayloadAction<ComplianceType>) => {
|
||||
state.compliance.complianceType = action.payload;
|
||||
},
|
||||
changeCompliance: (
|
||||
state,
|
||||
action: PayloadAction<DistributionProfileItem | undefined>
|
||||
action: PayloadAction<{
|
||||
policyID: string | undefined;
|
||||
profileID: string | undefined;
|
||||
policyTitle: string | undefined;
|
||||
}>
|
||||
) => {
|
||||
state.openScap.profile = action.payload;
|
||||
state.compliance.policyID = action.payload.policyID;
|
||||
state.compliance.profileID = action.payload.profileID;
|
||||
state.compliance.policyTitle = action.payload.policyTitle;
|
||||
},
|
||||
|
||||
changeFileSystemConfiguration: (
|
||||
|
|
@ -668,7 +696,8 @@ export const {
|
|||
reinitializeGcp,
|
||||
changeRegistrationType,
|
||||
changeActivationKey,
|
||||
changeOscapProfile,
|
||||
changeCompliance,
|
||||
changeComplianceType,
|
||||
changeFileSystemConfiguration,
|
||||
changeFileSystemConfigurationType,
|
||||
clearPartitions,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue