[8.8] [Cloud Security Posture] Revert custom integration name for policies (#156932) (#157196)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Cloud Security Posture] Revert custom integration name for policies
(#156932)](https://github.com/elastic/kibana/pull/156932)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Paulo
Henrique","email":"paulo.henrique@elastic.co"},"sourceCommit":{"committedDate":"2023-05-09T16:59:18Z","message":"[Cloud
Security Posture] Revert custom integration name for policies
(#156932)","sha":"581b69aa8463e1a38850565172b85e26d4b1c0b6","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Cloud
Security","backport:prev-minor","v8.8.0","v8.9.0"],"number":156932,"url":"https://github.com/elastic/kibana/pull/156932","mergeCommit":{"message":"[Cloud
Security Posture] Revert custom integration name for policies
(#156932)","sha":"581b69aa8463e1a38850565172b85e26d4b1c0b6"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156932","number":156932,"mergeCommit":{"message":"[Cloud
Security Posture] Revert custom integration name for policies
(#156932)","sha":"581b69aa8463e1a38850565172b85e26d4b1c0b6"}}]}]
BACKPORT-->

Co-authored-by: Paulo Henrique <paulo.henrique@elastic.co>
This commit is contained in:
Kibana Machine 2023-05-09 14:47:41 -04:00 committed by GitHub
parent bf92473415
commit 540275592c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 81 deletions

View file

@ -221,7 +221,6 @@ describe('<CspPolicyTemplateForm />', () => {
...input,
enabled: input.policy_template === 'kspm',
}));
policy.name = 'cloud_security_posture-1';
(useCspSetupStatusApi as jest.Mock).mockImplementation(() =>
createReactQueryResponse({
@ -242,16 +241,6 @@ describe('<CspPolicyTemplateForm />', () => {
isValid: true,
updatedPolicy: {
...getMockPolicyK8s(),
name: 'cloud_security_posture-1',
},
});
// 2nd call happens to set integration name
expect(onChange).toHaveBeenNthCalledWith(2, {
isValid: true,
updatedPolicy: {
...policy,
name: 'kspm-2',
},
});
});
@ -263,7 +252,6 @@ describe('<CspPolicyTemplateForm />', () => {
...input,
enabled: input.policy_template === 'cspm',
}));
policy.name = 'cloud_security_posture-1';
(useParams as jest.Mock).mockReturnValue({
integration: 'cspm',
@ -284,16 +272,6 @@ describe('<CspPolicyTemplateForm />', () => {
isValid: true,
updatedPolicy: {
...getMockPolicyAWS(),
name: 'cloud_security_posture-1',
},
});
// 2nd call happens to set integration name
expect(onChange).toHaveBeenNthCalledWith(2, {
isValid: true,
updatedPolicy: {
...policy,
name: 'cspm-2',
},
});
});
@ -305,7 +283,6 @@ describe('<CspPolicyTemplateForm />', () => {
...input,
enabled: input.policy_template === 'cspm',
}));
policy.name = 'cloud_security_posture-1';
(useParams as jest.Mock).mockReturnValue({
integration: 'vuln_mgmt',
@ -326,16 +303,6 @@ describe('<CspPolicyTemplateForm />', () => {
isValid: true,
updatedPolicy: {
...getMockPolicyAWS(),
name: 'cloud_security_posture-1',
},
});
// 2nd call happens to set integration name
expect(onChange).toHaveBeenNthCalledWith(2, {
isValid: true,
updatedPolicy: {
...policy,
name: 'vuln_mgmt-2',
},
});
});

View file

@ -45,7 +45,6 @@ import {
PolicyTemplateVarsForm,
} from './policy_template_selectors';
import { assert } from '../../../common/utils/helpers';
import { useCspSetupStatusApi } from '../../common/api/use_setup_status_api';
const DEFAULT_INPUT_TYPE = {
kspm: CLOUDBEAT_VANILLA,
@ -143,14 +142,6 @@ export const CspPolicyTemplateForm = memo<PackagePolicyReplaceDefineStepExtensio
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoading, input.policy_template, isEditPage]);
usePolicyTemplateInitialName({
isEditPage,
isLoading,
integration,
newPolicy,
updatePolicy,
});
useEnsureDefaultNamespace({ newPolicy, input, updatePolicy });
useCloudFormationTemplate({
@ -237,45 +228,6 @@ CspPolicyTemplateForm.displayName = 'CspPolicyTemplateForm';
// eslint-disable-next-line import/no-default-export
export { CspPolicyTemplateForm as default };
const usePolicyTemplateInitialName = ({
isEditPage,
isLoading,
integration,
newPolicy,
updatePolicy,
}: {
isEditPage: boolean;
isLoading: boolean;
integration: CloudSecurityPolicyTemplate | undefined;
newPolicy: NewPackagePolicy;
updatePolicy: (policy: NewPackagePolicy) => void;
}) => {
const getSetupStatus = useCspSetupStatusApi();
const installedPackagePolicyCount = Object.entries(getSetupStatus?.data ?? {})?.find(
([key, _value]) => key === integration
)?.[1]?.installedPackagePolicies;
const currentPackagePolicyCount =
typeof installedPackagePolicyCount === 'number' ? installedPackagePolicyCount + 1 : undefined;
useEffect(() => {
if (!integration) return;
if (isEditPage) return;
if (isLoading) return;
const sequenceSuffix = currentPackagePolicyCount ? `-${currentPackagePolicyCount}` : '';
const currentIntegrationName = `${integration}${sequenceSuffix}`;
if (newPolicy.name === currentIntegrationName) {
return;
}
updatePolicy({
...newPolicy,
name: currentIntegrationName,
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoading, integration, isEditPage]);
};
const useEnsureDefaultNamespace = ({
newPolicy,
input,