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

Add experimental-download-offline-databases flag #1039

Merged
merged 9 commits into from
Jun 14, 2024
Merged

Conversation

cuixq
Copy link
Contributor

@cuixq cuixq commented Jun 12, 2024

Currently flags experimental-offline and experimental-local-db are confusing sometimes.

This PR renames experimental-local-db to experimental-download-database to make it more explicit whether to download the database or not.

For now, experimental-download-database only works when experimental-offline is set.

internal/local is also modified to reflect the change in the naming and meaning of this flag.

Copy link
Contributor

@andrewpollock andrewpollock left a comment

Choose a reason for hiding this comment

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

This is cool!

I'm often downloading one or a few ecosystems for offline validation or other examination purposes, and have this shell script I had Gemini cook up for me to make this streamlined.

Is the intention for this feature to be used independently of a scanning run, or as part of one?

Would it be possible to include another flag that accepted a subset of ecosystems to download, in the interests of saving time, bandwidth and disk space for this purpose?

docs/offline-mode.md Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.29%. Comparing base (72afdb8) to head (d9b037c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1039      +/-   ##
==========================================
+ Coverage   65.23%   65.29%   +0.05%     
==========================================
  Files         150      150              
  Lines       12497    12498       +1     
==========================================
+ Hits         8153     8160       +7     
+ Misses       3882     3878       -4     
+ Partials      462      460       -2     

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

@cuixq
Copy link
Contributor Author

cuixq commented Jun 12, 2024

For now, this flag is only valid when experimental-offline is set. The motivation is that experimental-offline and experiment-local-db is confusing, so we are trying to separate the offline part and the download part.

I think ideally, we can have some subcommand for example download to handle downloading the database, and I like the idea to specify the systems to download in the command!

@cuixq cuixq marked this pull request as ready for review June 12, 2024 05:20
@cuixq cuixq requested review from G-Rath and another-rex June 12, 2024 05:20
Copy link
Collaborator

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

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

This looks good, but the flag should be plural because there are many databases and really the number of them is an implementation detail (right now its 1:1 with ecosystems, but maybe in future they'll be sharded differently 🤷)

I also wonder if the flag should be something like --download-offline-databases, to tie it more to the --offline flag 🤔

@@ -27,8 +27,8 @@ type ZipDB struct {
Name string
// the url that the zip archive was downloaded from
ArchiveURL string
// whether this database should make any network requests
Offline bool
Copy link
Collaborator

@G-Rath G-Rath Jun 12, 2024

Choose a reason for hiding this comment

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

fwiw I think it would be better to keep the existing structure within the database logic, as it's technically possible they could be implemented to make network requests before downloading and (more practically) it means a smaller diff + aligns better with everything else (e.g. the error is ErrOfflineDatabaseNotFound, the tests say "if the db is offline", etc).

The fact that we're exposing this to the user as "download databases" is something of an implementation detail of the CLI.

Having said that, I won't block if you can't be bothered reverting 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just feel it's weird to use downloadDB to indicate offline so would like to keep consistent in the names, but I don't mind too much keeping offline in ZipDB.

pkg/osvscanner/osvscanner.go Outdated Show resolved Hide resolved
@G-Rath
Copy link
Collaborator

G-Rath commented Jun 12, 2024

Is the intention for this feature to be used independently of a scanning run, or as part of one?
Would it be possible to include another flag that accepted a subset of ecosystems to download

@andrewpollock I proposed basically this exact thing in subcommand form at our weekly catchup 😄

My thinking is especially now that we have both subcommands and interactive-ness, we could provide a very nice interface for managing these databases and their location without overloading scan with a lot of flags

Part of me now wonders if it could be worth having a dedicated offline subcommand instead of a flag? but maybe that's just trading a (flag) swing for a (subcommand) roundabout?

@cuixq cuixq changed the title Add experimental-download-database flag Add experimental-offline-download-databases flag Jun 13, 2024
@another-rex
Copy link
Collaborator

I personally think download-offline-databases makes more sense than offline-download-databases.

Copy link
Collaborator

@another-rex another-rex left a comment

Choose a reason for hiding this comment

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

LGTM, just think we should swap offline and download around in the flag.

@cuixq
Copy link
Contributor Author

cuixq commented Jun 14, 2024

@G-Rath do you mind taking another look? Thanks.

Copy link
Collaborator

@G-Rath G-Rath 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! got a minor comment about the doc wording, but it's optional :)

docs/offline-mode.md Outdated Show resolved Hide resolved
@cuixq cuixq changed the title Add experimental-offline-download-databases flag Add experimental-download-offline-databases flag Jun 14, 2024
@cuixq cuixq merged commit ace9154 into google:main Jun 14, 2024
13 checks passed
@cuixq cuixq deleted the flag branch June 14, 2024 05:11
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