Skip to content

feat: add function to unregister post analyzers #8844

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

Closed

Conversation

samuelvl
Copy link

@samuelvl samuelvl commented May 7, 2025

Description

Analogous to DeregisterAnalyzer but for post analyzers:

// DeregisterAnalyzer is mainly for testing
func DeregisterAnalyzer(t Type) {
delete(analyzers, t)
}

@CLAassistant
Copy link

CLAassistant commented May 7, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@simar7
Copy link
Member

simar7 commented May 7, 2025

hi @samuelvl - I'm curious but what's the use case for this?

@samuelvl
Copy link
Author

samuelvl commented May 8, 2025

Hey @simar7, we are using Trivy as a library and we need to deregister analyzers before enabling them to avoid Analyzer is registered twice errors. For example https://github.com/castai/image-analyzer/blob/main/apk/apk.go#L25-L26

Since dpkg is now a post analyzer we need to do a similar thing but with DeregisterPostAnalyzer. Let me know if it makes sense or if there is a better way of doing this.

Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

Although these functions are mainly used for testing, users can also use them.
We have Disable* functions for analyzers and configAnalyzers.
So i think we can add this function.
cc. @knqyf263

@samuelvl there is 1 more way (and i think this is more correct way):
you can use DisabledAnalyzers field.
But your analyzers should use different names.

@DmitriyLewen DmitriyLewen changed the title Allow deregistering post-analyzers feat: add function to unregister post analyzers May 12, 2025
@knqyf263
Copy link
Collaborator

@samuelvl As Dmitriy mentioned, doesn't DisabledAnalzyers work for you? You can use a different name and disable the existing one.

Also, since Trivy is a CLI tool, not a library, we do not guarantee source code compatibility, so using it as a library is not recommended. However, users may use it as a library at their own risk.

@samuelvl
Copy link
Author

This is finally not needed, thanks for the support 🙏

@samuelvl samuelvl closed this May 22, 2025
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.

5 participants