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 ignore file option #27

Merged
merged 6 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ $ mix deps.audit
| `--format` | String | `"human"` | The format of the report to generate (`"json"` or `"human"`) |
| `--ignore-advisory-ids` | String | `""` | Comma-separated list of advisory IDs to ignore |
| `--ignore-package-names` | String | `""` | Comma-separated list of package names to ignore |
| `--ignore-file` | String | `.mix-audit-skips` | Path of the ignore file |

## Example

Expand Down
1 change: 1 addition & 0 deletions lib/mix_audit/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule MixAudit.CLI do
switches: [
ignore_advisory_ids: :string,
ignore_package_names: :string,
ignore_file: :string,
version: :boolean,
help: :boolean,
format: :string,
Expand Down
10 changes: 10 additions & 0 deletions lib/mix_audit/cli/audit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ defmodule MixAudit.CLI.Audit do
format = Keyword.get(opts, :format)
ignored_advisory_ids = ignored_advisory_ids(opts)
ignored_package_names = ignored_package_names(opts)
ignored_ids_from_file = ignored_ids_from_file(opts)

# Synchronize and get security advisories
advisories =
MixAudit.Repo.advisories()
|> Enum.reject(&(&1.id in ignored_advisory_ids))
|> Enum.reject(&(&1.id in ignored_ids_from_file))
|> Enum.group_by(& &1.package)

# Get project dependencies
Expand Down Expand Up @@ -45,4 +47,12 @@ defmodule MixAudit.CLI.Audit do
|> String.split(",")
|> Enum.map(&String.trim/1)
end

defp ignored_ids_from_file(opts) do
opts
|> Keyword.get(:ignore_file, ".mix-audit-skips")
|> File.read!()
Copy link
Member

Choose a reason for hiding this comment

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

If the user doesn’t specify the --ignore-file option, it will still try to read the .mix-audit-skips file. But if it doesn’t exist, it will raise an error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe should read from file only if the option if specified...

Copy link
Contributor Author

@baldarn baldarn Mar 15, 2024

Choose a reason for hiding this comment

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

I copied bundle audit system.
the file will be evaluated only if the option is passed

see a92312e

what do you think?

|> String.split("\n")
|> Enum.reject(fn line -> String.starts_with?(line, "#") || String.trim(line) == "" end)
end
end
1 change: 1 addition & 0 deletions lib/mix_audit/cli/help.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule MixAudit.CLI.Help do
IO.puts("--format The format of the report to generate (human, json)")
IO.puts("--ignore-advisory-ids A comma-separated list of advisory IDs to ignore")
IO.puts("--ignore-package-names A comma-separated list of package names to ignore")
IO.puts("--ignore-file Path of the ignore file")
IO.puts("")
System.halt(0)
end
Expand Down
Loading