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

[Cloud Security] Investigate Agentless credential validation #205125

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ export function useOnSubmit({
]
);

console.log({
formState,
disableSaveAndContinue: formState !== 'VALID' || hasAgentPolicyError || !validationResults,
});

return {
agentPolicies,
updateAgentPolicies,
Expand All @@ -498,6 +503,7 @@ export function useOnSubmit({
setValidationResults,
hasAgentPolicyError,
setHasAgentPolicyError,
disableSaveAndContinue: formState !== 'VALID' || hasAgentPolicyError || !validationResults,
isInitialized,
// TODO check
navigateAddAgent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const CreatePackagePolicySinglePage: CreatePackagePolicyParams = ({
setHasAgentPolicyError,
validationResults,
hasAgentPolicyError,
disableSaveAndContinue,
isInitialized,
} = useOnSubmit({
agentCount,
Expand Down Expand Up @@ -261,7 +262,7 @@ export const CreatePackagePolicySinglePage: CreatePackagePolicyParams = ({
({ isValid, updatedPolicy }) => {
updatePackagePolicy(updatedPolicy);
setFormState((prevState) => {
if (prevState === 'VALID' && !isValid) {
if (!isValid) {
return 'INVALID';
}
return prevState;
Expand Down Expand Up @@ -425,14 +426,14 @@ export const CreatePackagePolicySinglePage: CreatePackagePolicyParams = ({
)}

{/* If a package has been loaded, then show UI extension (if any) */}
{extensionView && packagePolicy.package?.name && (
{/* {extensionView && packagePolicy.package?.name && (
<ExtensionWrapper>
<extensionView.Component
newPolicy={packagePolicy}
onChange={handleExtensionViewOnChange}
/>
</ExtensionWrapper>
)}
)} */}
</>
) : (
<div />
Expand All @@ -448,7 +449,7 @@ export const CreatePackagePolicySinglePage: CreatePackagePolicyParams = ({
formState,
integrationInfo?.name,
extensionView,
handleExtensionViewOnChange,
// handleExtensionViewOnChange,
spaceSettings?.allowedNamespacePrefixes,
handleSetupTechnologyChange,
isAgentlessIntegration,
Expand Down Expand Up @@ -644,9 +645,7 @@ export const CreatePackagePolicySinglePage: CreatePackagePolicyParams = ({
<EuiButton
onClick={() => onSubmit()}
isLoading={formState === 'LOADING'}
disabled={
formState !== 'VALID' || hasAgentPolicyError || !validationResults
}
disabled={disableSaveAndContinue}
iconType="save"
color="primary"
fill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React from 'react';
import React, { useEffect } from 'react';
import { EuiAccordion, EuiButton, EuiCallOut, EuiLink, EuiSpacer, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import semverCompare from 'semver/functions/compare';
Expand Down Expand Up @@ -179,6 +179,8 @@ export const AwsCredentialsFormAgentless = ({
newPolicy,
packageInfo,
updatePolicy,
onChange,
setIsValid,
}: AwsFormProps) => {
const awsCredentialsType = getAwsCredentialsType(input) || DEFAULT_AGENTLESS_AWS_CREDENTIALS_TYPE;
const options = getAwsCredentialsFormOptions();
Expand All @@ -200,6 +202,16 @@ export const AwsCredentialsFormAgentless = ({

const isOrganization = accountType === ORGANIZATION_ACCOUNT;

useEffect(() => {
setIsValid(false);

onChange({
isValid: false,
updatedPolicy: newPolicy,
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [input.type]);

return (
<>
<AWSSetupInfoContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,9 @@ export const CspPolicyTemplateForm = memo<PackagePolicyReplaceDefineStepExtensio

const updatePolicy = useCallback(
(updatedPolicy: NewPackagePolicy) => {
onChange({ isValid, updatedPolicy });
onChange({ isValid: setupTechnology === SetupTechnology.AGENT_BASED, updatedPolicy });
},
[onChange, isValid]
[onChange, setupTechnology]
);

/**
Expand Down Expand Up @@ -785,11 +785,11 @@ export const CspPolicyTemplateForm = memo<PackagePolicyReplaceDefineStepExtensio
enabled: canFetchIntegration,
});

useEffect(() => {
if (!isServerless) {
setIsValid(isSubscriptionValid);
}
}, [isServerless, isSubscriptionValid]);
// useEffect(() => {
// if (!isServerless) {
// setIsValid(isSubscriptionValid);
// }
// }, [isServerless, isSubscriptionValid]);

useEffect(() => {
if (isEditPage) return;
Expand Down