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

fix(cli): error on missing config file #7154

Merged
merged 5 commits into from
Jul 25, 2024

Conversation

sgaist
Copy link
Contributor

@sgaist sgaist commented Jul 12, 2024

Description

This PR will make trivy error if the configuration file passed in parameter cannot be found.

However, to stay consistent with the current behaviour

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@sgaist sgaist requested a review from knqyf263 as a code owner July 12, 2024 20:04
pkg/commands/app.go Outdated Show resolved Hide resolved
@simar7
Copy link
Member

simar7 commented Jul 16, 2024

Thank you for the PR. Couple of comments:

  1. The level should be Warning. The user should be notified that the results aren't as desired given their input isn't right/missing.
  2. This should be extended to other config files that trivy uses, for instance the .trivyignore.yaml. Ultimately, any specified user input, if not correct, should be flagged by Trivy so users know what to expect.

@sgaist
Copy link
Contributor Author

sgaist commented Jul 16, 2024

@simar7

  1. I'll update the code suggestion and submit it

  2. I agree. I'd suggest making a dedicated task list to ensure we don't miss such an option

@knqyf263
Copy link
Collaborator

@simar7 It currently returns an error when a user specifies --config and it is not found. It should be fine.

$ trivy image --config trivy.yaml alpine:3.20
2024-07-16T11:49:31+04:00       FATAL   Fatal error     config file "trivy.yaml" loading error: open trivy.yaml: no such file or directory

Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

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

We can fix the logger initialization problem in another PR. This change is already valuable. We should merge this PR.

.gitignore Outdated Show resolved Hide resolved
pkg/commands/app.go Outdated Show resolved Hide resolved
sgaist added 2 commits July 17, 2024 11:17
The current behavior is to log a debug message and continue which
means that the scan that will happen will not match the expectation
of the user.

Now, if a user explicitly set the config file path, an error will be
raised otherwise, the original behavior will apply.
This will inform the user better when the default configuration file is not found.
@sgaist sgaist force-pushed the error_on_missing_config_file branch from dda5824 to 28c1cc2 Compare July 17, 2024 09:17
pkg/commands/app.go Outdated Show resolved Hide resolved
@sgaist sgaist force-pushed the error_on_missing_config_file branch from 28c1cc2 to 3d397f0 Compare July 18, 2024 09:19
Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@knqyf263 knqyf263 enabled auto-merge July 18, 2024 11:00
Part of the message is OS dependent so remove it to ensure it passes
on all platforms.
auto-merge was automatically disabled July 18, 2024 11:42

Head branch was pushed to by a user without write access

@sgaist
Copy link
Contributor Author

sgaist commented Jul 18, 2024

@knqyf263 You're welcome !

I just fixed the test issue: it's the OS specific part of the string that makes it fail.

I removed that part from the string check however would you rather have a fixed message ?

@knqyf263
Copy link
Collaborator

I removed that part from the string check however would you rather have a fixed message ?

It looks good to me.

@knqyf263 knqyf263 enabled auto-merge July 18, 2024 11:46
@sgaist
Copy link
Contributor Author

sgaist commented Jul 25, 2024

I missed that the tests have failed and I can't see the content anymore, is there something I can do trigger them again beside rebasing my branch ?

@knqyf263
Copy link
Collaborator

You can merge the main branch and let's see how it goes.

@sgaist
Copy link
Contributor Author

sgaist commented Jul 25, 2024

Done as requested

@knqyf263 knqyf263 added this pull request to the merge queue Jul 25, 2024
Merged via the queue into aquasecurity:main with commit 7fa5e7d Jul 25, 2024
12 checks passed
@sgaist sgaist deleted the error_on_missing_config_file branch July 25, 2024 10:01
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.

feat(logging): Add warning in case missing config file
3 participants