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

[frontend] add output in payload form #2790

Open
wants to merge 12 commits into
base: release/current
Choose a base branch
from
Open

Conversation

MarineLeM
Copy link
Contributor

Proposed changes

  • Add output tab in payload form

Related issues

Further comments

image

@MarineLeM MarineLeM self-assigned this Mar 27, 2025
@MarineLeM MarineLeM linked an issue Mar 27, 2025 that may be closed by this pull request
Copy link

codecov bot commented Mar 27, 2025

Codecov Report

Attention: Patch coverage is 53.06122% with 69 lines in your changes missing coverage. Please review.

Project coverage is 40.62%. Comparing base (5915186) to head (80f8bbe).

Files with missing lines Patch % Lines
...enbas/rest/payload/ContractOutputElementUtils.java 56.52% 18 Missing and 2 partials ⚠️
.../java/io/openbas/rest/payload/RegexGroupUtils.java 48.38% 14 Missing and 2 partials ⚠️
...o/openbas/rest/payload/service/PayloadService.java 44.44% 14 Missing and 1 partial ⚠️
...bas/rest/payload/service/PayloadUpsertService.java 33.33% 8 Missing ⚠️
...ava/io/openbas/rest/payload/OutputParserUtils.java 75.00% 2 Missing and 2 partials ⚠️
...bas/rest/payload/service/PayloadUpdateService.java 50.00% 3 Missing ⚠️
...s/rest/payload/service/PayloadCreationService.java 60.00% 2 Missing ⚠️
.../src/main/java/io/openbas/utils/PayloadMapper.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##             release/current    #2790      +/-   ##
=====================================================
+ Coverage              40.59%   40.62%   +0.02%     
- Complexity              2081     2088       +7     
=====================================================
  Files                    638      640       +2     
  Lines                  19518    19559      +41     
  Branches                1324     1331       +7     
=====================================================
+ Hits                    7924     7945      +21     
- Misses                 11161    11178      +17     
- Partials                 433      436       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MarineLeM MarineLeM force-pushed the issue/2718 branch 2 times, most recently from ca4b268 to af2f7b2 Compare March 28, 2025 10:22
@savacano28
Copy link
Contributor

savacano28 commented Mar 28, 2025

Tested OK :):

  • Payloads: CRUD +/- Output parsers
  • Injects: CRUD + Execution (atomic + simulations) + Export/Import +/- Output Parsers

multiline?: boolean;
rows?: number;
required?: boolean;
style?: CSSProperties;
isCommand?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not super fan to have this specific property in a generic component

@@ -44,6 +46,10 @@ public Payload upsertPayload(PayloadUpsertInput input) {
input.getAttackPatternsExternalIds())));
existingPayload.setTags(iterableToSet(tagRepository.findAllById(input.getTagIds())));
existingPayload.setUpdatedAt(Instant.now());

outputParserUtils.removeOrphanOutputParsers(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure to understand why we need to have a specific request here since we have this constraint on the Payload bean

@onetomany(mappedBy = "payload", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JsonProperty("payload_output_parsers")
private Set outputParsers = new HashSet<>();

Copy link
Contributor

@savacano28 savacano28 Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case when we update the list of outputparsers (remove an output parser from a payload) we need to remove the reference parent (payload) from output parser and delete it from the database.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you need to add orphanRemoval = true I suppose.
This should be handled automatically, not manually.

Copy link
Contributor

@savacano28 savacano28 Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right, the issue was when I added it, I had a weird behavior in the updated and in the payloadService.generateDuplicatedPayload for the execution of the inject.

@@ -38,6 +38,26 @@ class CreatePayload extends Component {
}

onSubmit(data) {
function cleanupObjects(array, idKey, nestedKey, cleanupFn) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need to do that ?

const [activeTab, setActiveTab] = useState(tabs[0]);

const handleActiveTabChange = (_: SyntheticEvent, newValue: string) => {
setActiveTab(newValue);
};

const regexGroupObject = z.object({
regex_group_id: z.string().optional(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we have this ? The ID is generated by the back-end no ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we are updating un object, we pass the id.

});

const contractOutputElementObject = z.object({
contract_output_element_id: z.string().optional(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

contract_output_element_is_finding: z.boolean().optional(),
contract_output_element_name: z.string().min(1, { message: t('Should not be empty') }),
contract_output_element_key: z.string().min(1, { message: t('Should not be empty') }),
contract_output_element_type: z.string().min(1, { message: t('Should not be empty') }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be z.enum(['text', 'number', etc.]) no ?

});
const outputParserObject = z.object({
output_parser_id: z.string().optional(),
output_parser_mode: z.string().min(1, { message: t('Should not be empty') }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be an enum here

const outputParserObject = z.object({
output_parser_id: z.string().optional(),
output_parser_mode: z.string().min(1, { message: t('Should not be empty') }),
output_parser_type: z.string().min(1, { message: t('Should not be empty') }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

output_parser_id: z.string().optional(),
output_parser_mode: z.string().min(1, { message: t('Should not be empty') }),
output_parser_type: z.string().min(1, { message: t('Should not be empty') }),
output_parser_contract_output_elements: z.array(contractOutputElementObject).optional(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not aligned with the back-end
@NotNull
private Set contractOutputElements = new HashSet<>();

const selectedContractOutputElementType = watch(`${prefixName}.${index}.contract_output_element_type`) as keyof typeof defaultFields | undefined;
const regexGroups: RegexGroup[] = watch(`${prefixName}.${index}.contract_output_element_regex_groups`);

const outputParserTypeList = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should come from the contract_output_element_type type no ?

const { t } = useFormatter();
const theme = useTheme();
const { control, setValue } = useFormContext();
const outputParserName = 'payload_output_parsers.0.output_parser_contract_output_elements';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the index is 0 here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because for this first implementation we only have one outputParser on the payload with the type = REGEX and the mode = STDOUT

@@ -38,6 +38,26 @@ class CreatePayload extends Component {
}

onSubmit(data) {
function cleanupObjects(array, idKey, nestedKey, cleanupFn) {
Copy link
Member

@RomuDeuxfois RomuDeuxfois Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buttons at the bottom are reversed

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adapt frontend to support Output parsers in payloads
5 participants