-
Notifications
You must be signed in to change notification settings - Fork 601
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
feat(outputs): allow to set multiple outputs (#648) #1346
feat(outputs): allow to set multiple outputs (#648) #1346
Conversation
002bf75
to
93474b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you able to add tests for this change?
ec1360d
to
21e25b9
Compare
I just added some tests |
21e25b9
to
1ac5a4e
Compare
Right now this doesn't seem to work when providing multiple files:
That being said, I think I can update this PR to include additional pattern changes to how we encode the final reports (which should make this change easier to make). I'll think about it this afternoon and try to get something pushed before the end of the day. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was updating this submodule intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it was not intentional, sorry for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all good 😄
grype/presenter/json/presenter.go
Outdated
} | ||
} | ||
|
||
// Present creates a JSON-based reporting | ||
func (pres *Presenter) Present(output io.Writer) error { | ||
func (pres *Presenter) Present(defaultOutput io.Writer) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately this is breaking the presenter abstraction by adding filesystem concerns.
Today the presenter acts as a two-way facade... the caller provides doesn't need to know about any format concerns (is this json, table, xml, etc) and the presenter only needs to write bytes to the writer, but does not need to know about the concerns of that writer (is it to a file, the screen, streaming to a socket, etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ultimately we should probably be getting rid of the presenter abstraction and inverting this entire flow... so instead of providing a writer to an object, we should ask the object to return bytes. If this is the way to go, we should try to do this incrementally. A good approach to this would be to take the GetPresenter() function and adapt that to return the new object and write a short generalized helper function that takes a presenter and returns bytes. Initially we'd leave all of the presenters alone and fix everything above the GetPresenter() call (maybe call it GetWriter instead since it would no longer return a presenter). Then over time we can swap all of the presenters to encoders/writers.
I haven't thought this entirely though, but these are some initial thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olivierboudet I can try out the above suggestion on your branch, as it would ultimately enable the multi -o feature (which would be awesome). Would you mind if I pushed updates to your branch? Or would you like to take a stab at these suggestions? (or of course, shout out if you have other suggestions here too!)
(Alternatively I could try and get these changes in another PR then rebase this, which isn't a problem, but I feel the rebase would be nasty and the features on this branch nicely motivate the need for the change.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review ! Of course you can push on my branch
1ac5a4e
to
79cf8d0
Compare
Signed-off-by: Olivier Boudet <[email protected]> Signed-off-by: Olivier Boudet <[email protected]> Signed-off-by: Alex Goodman <[email protected]>
review Signed-off-by: Olivier Boudet <[email protected]> Signed-off-by: Alex Goodman <[email protected]>
79cf8d0
to
46c543c
Compare
@olivierboudet I updated the PR based on #1346 (comment) by leveraging the multi-writer patterns in syft. In doing so I needed to change some underlying eventing and presentation functionality, which we were overdue for. This doesn't address larger concerns with the presenter pattern and how it works with the execution flow, but instead nudges grype in the right direction (larger refactors can be done in future PRs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one has been a long time coming!
Signed-off-by: Alex Goodman <[email protected]>
01f98d8
to
269f7f0
Compare
Thanks a lot @wagoodman |
I tried to resolve #648 with this PR but I am not a Go developer so you may have remarks...
This PR allows to specify multiple outputs like in syft, for example
-o json=report.json -o template=report.html -t template.html
I need to add more tests but if someone could tell me if it looks ok overall ?