From d60c6cb74b506a658cfeb3baec36f1f5ed480107 Mon Sep 17 00:00:00 2001 From: Thomas Lavocat Date: Tue, 17 Oct 2023 17:18:08 +0200 Subject: [PATCH] oscap: lock the wizard step behind a feature flag The oscap feature have been quite eagerly pushed forward and it seems we went a bit fast with it. To take more time and make sure all the stakeholders agree on the way forward the decision was taken to put this functionality behind a feature flag. The two feature flags for both stage and prod are there: * https://insights-stage.unleash.devshift.net/projects/default/features/image-builder.wizard.oscap.enabled (enabled on stage so we can test the feature) * https://insights.unleash.devshift.net/projects/default/features/image-builder.wizard.oscap.enabled (disabled on prod) --- .../CreateImageWizard/CreateImageWizard.js | 24 +++++++++++++------ .../steps/imageOutputStepMapper.js | 4 ++-- .../CreateImageWizard/steps/registration.js | 2 +- .../CreateImageWizard.compliance.test.js | 7 ++++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Components/CreateImageWizard/CreateImageWizard.js b/src/Components/CreateImageWizard/CreateImageWizard.js index 348f8125..d503a555 100644 --- a/src/Components/CreateImageWizard/CreateImageWizard.js +++ b/src/Components/CreateImageWizard/CreateImageWizard.js @@ -320,7 +320,7 @@ const parseSizeUnit = (bytesize) => { }; // map the compose request object to the expected form state -const requestToState = (composeRequest, distroInfo, isBeta, isProd) => { +const requestToState = (composeRequest, distroInfo, isProd, enableOscap) => { if (composeRequest) { const imageRequest = composeRequest.image_requests[0]; const uploadRequest = imageRequest.upload_request; @@ -476,7 +476,7 @@ const requestToState = (composeRequest, distroInfo, isBeta, isProd) => { } // oscap policy - if (isBeta) { + if (enableOscap) { formState['oscap-policy'] = composeRequest?.customizations?.openscap?.profile_id; } @@ -487,7 +487,11 @@ const requestToState = (composeRequest, distroInfo, isBeta, isProd) => { } }; -const formStepHistory = (composeRequest, contentSourcesEnabled, isBeta) => { +const formStepHistory = ( + composeRequest, + contentSourcesEnabled, + enableOscap +) => { if (composeRequest) { const imageRequest = composeRequest.image_requests[0]; const uploadRequest = imageRequest.upload_request; @@ -506,7 +510,7 @@ const formStepHistory = (composeRequest, contentSourcesEnabled, isBeta) => { steps.push('registration'); } - if (isBeta) { + if (enableOscap) { steps.push('Compliance'); } @@ -559,24 +563,30 @@ const CreateImageWizard = () => { const { isBeta, isProd } = useGetEnvironment(); + // Only allow oscap to be used in Beta even if the flag says the feature is + // activated. + const oscapFeatureFlag = + useFlag('image-builder.wizard.oscap.enabled') && isBeta(); let initialState = requestToState( composeRequest, distroInfo, - isBeta(), - isProd() + isProd(), + oscapFeatureFlag ); const stepHistory = formStepHistory( composeRequest, contentSourcesEnabled, - isBeta() + oscapFeatureFlag ); if (initialState) { initialState.isBeta = isBeta(); initialState.contentSourcesEnabled = contentSourcesEnabled; + initialState.enableOscap = oscapFeatureFlag; } else { initialState = { isBeta: isBeta(), + enableOscap: oscapFeatureFlag, contentSourcesEnabled, }; } diff --git a/src/Components/CreateImageWizard/steps/imageOutputStepMapper.js b/src/Components/CreateImageWizard/steps/imageOutputStepMapper.js index b6e75c30..b80fc8f3 100644 --- a/src/Components/CreateImageWizard/steps/imageOutputStepMapper.js +++ b/src/Components/CreateImageWizard/steps/imageOutputStepMapper.js @@ -1,7 +1,7 @@ import isRhel from '../../../Utilities/isRhel.js'; const imageOutputStepMapper = ( - { 'target-environment': targetEnv, release, isBeta } = {}, + { 'target-environment': targetEnv, release, enableOscap } = {}, { skipAws, skipGoogle, skipAzure } = {} ) => { if (!skipAws && targetEnv?.aws) { @@ -19,7 +19,7 @@ const imageOutputStepMapper = ( if (isRhel(release)) { return 'registration'; } - if (isBeta) { + if (enableOscap) { return 'Compliance'; } return 'File system configuration'; diff --git a/src/Components/CreateImageWizard/steps/registration.js b/src/Components/CreateImageWizard/steps/registration.js index f69bc15e..b56699e2 100644 --- a/src/Components/CreateImageWizard/steps/registration.js +++ b/src/Components/CreateImageWizard/steps/registration.js @@ -70,7 +70,7 @@ const registrationStep = { ), name: 'registration', nextStep: ({ values }) => { - if (values.isBeta) { + if (values.enableOscap) { return 'Compliance'; } else { return 'File system configuration'; diff --git a/src/test/Components/CreateImageWizard/CreateImageWizard.compliance.test.js b/src/test/Components/CreateImageWizard/CreateImageWizard.compliance.test.js index 29080e48..25c019fc 100644 --- a/src/test/Components/CreateImageWizard/CreateImageWizard.compliance.test.js +++ b/src/test/Components/CreateImageWizard/CreateImageWizard.compliance.test.js @@ -49,6 +49,13 @@ jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({ }), })); +jest.mock('@unleash/proxy-client-react', () => ({ + useUnleashContext: () => jest.fn(), + useFlag: jest.fn((flag) => + flag === 'image-builder.wizard.oscap.enabled' ? true : false + ), +})); + beforeAll(() => { // scrollTo is not defined in jsdom window.HTMLElement.prototype.scrollTo = function () {};