Skip to content

Clean up Generate function in report.go#992

Merged
egibs merged 9 commits into
chainguard-dev:mainfrom
Ritish134:main
Jul 2, 2025
Merged

Clean up Generate function in report.go#992
egibs merged 9 commits into
chainguard-dev:mainfrom
Ritish134:main

Conversation

@Ritish134
Copy link
Copy Markdown
Contributor

Broken down the functionality of the generate function into modular functions:
buildIgnoreMap() — creates the ignore tag map

trimDisplayPath() — handles trimming file paths

initFileReport() — initializes the report struct

createMatchRulesMap() — Store match rules in a map

processMatchedStrings() — processes all pattern matches

buildBehavior() — creates a behavior object from rule data

handleMetadata() — processes metadata and applies overrides

updateBehavior() — updates behavior entries in the file report

fixes #751

@Ritish134
Copy link
Copy Markdown
Contributor Author

Hey @egibs, just checking in any updates on this ? Appreciate your time!

Comment thread pkg/report/report.go Outdated
caps = append(caps, v)
}
}
handleMetadata(m, b, fr, override, mrsMap, pledges, caps, syscalls)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I noticed we're missing pledges and syscalls (and most likely caps even though we don't currently have any samples with this) in the recent test diffs.

We can probably move pledges, caps, and syscalls to handleMetadata's scope.

To verify your changes locally you can run make refresh-sample-testdata to build the latest changes and refresh our sample data. If you see any diffs, you can quickly iterate and try again rather than waiting for CI.

@Ritish134 Ritish134 force-pushed the main branch 7 times, most recently from c0b64a0 to d1f27b1 Compare June 22, 2025 07:06
@Ritish134 Ritish134 force-pushed the main branch 4 times, most recently from 6012a57 to eab7421 Compare June 30, 2025 14:50
@egibs
Copy link
Copy Markdown
Member

egibs commented Jul 1, 2025

@Ritish134 -- I made a few conflicting changes in #1017 -- namely calling processor.clearFileContent() which will need to be adapted to your new processMatchedStrings method.

Once that's fixed, I think this will be in good shape.

Ritish134 added 8 commits July 1, 2025 14:43
Broken down the functionality of the generate function into modular functions:
`buildIgnoreMap()` — creates the ignore tag map

`trimDisplayPath()` — handles trimming file paths

`initFileReport()` — initializes the report struct

`createMatchRulesMap()` —  Store match rules in a map

`processMatchedStrings()` — processes all pattern matches

`buildBehavior()` — creates a behavior object from rule data

`handleMetadata()` — processes metadata and applies overrides

`updateBehavior()` — updates behavior entries in the file report

Signed-off-by: Ritish Srivastava <121374890+Ritish134@users.noreply.github.com>
Signed-off-by: Ritish Srivastava <121374890+Ritish134@users.noreply.github.com>
Signed-off-by: Ritish Srivastava <121374890+Ritish134@users.noreply.github.com>
Signed-off-by: Ritish Srivastava <121374890+Ritish134@users.noreply.github.com>
- Moved the regex for checking the version outside `getExt` func for better performance
- Created slices to check for `.elf, .gzip, .Z` files using `bytes.hasPrefix`
- Wrote Equivalent code without an anonymous function in `GetExt` for extension of size greater than 2, which is more idiomatic.


Signed-off-by: Ritish Srivastava <121374890+Ritish134@users.noreply.github.com>
Signed-off-by: Ritish Srivastava <121374890+Ritish134@users.noreply.github.com>
@Ritish134
Copy link
Copy Markdown
Contributor Author

Ritish134 commented Jul 1, 2025

@egibs Done.

I'm not sure why the commit signature verification is failing — I tried setting up GPG keys, but it didn’t resolve the issue.

Copy link
Copy Markdown
Member

@egibs egibs left a comment

Choose a reason for hiding this comment

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

Looks good, appreciate the contribution!

@egibs egibs merged commit 75df672 into chainguard-dev:main Jul 2, 2025
12 checks passed
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.

Refactor Generate in report.go

2 participants