Skip to content

Commit

Permalink
Add SARIF output format for report #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Coruscant11 committed Feb 25, 2023
1 parent 25088e8 commit 9eb6a54
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 1 deletion.
169 changes: 169 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ tracing-log = "0.1"
tracing-subscriber = { version = "0.3", features = ["tracing-log", "ansi"] }
url = "2.3"
walkdir = "2.3"
serde-sarif = "0.3.5"

[dev-dependencies]
assert_cmd = { version = "2.0", features = ["color-auto"] }
Expand Down
9 changes: 9 additions & 0 deletions src/bin/noseyparker/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ pub enum OutputFormat {
///
/// This is a sequence of JSON objects, one per line.
Jsonl,

/// SARIF format
///
/// This is a JSON-based format used by Microsoft's Static Application Security Testing (SAST) tool.
/// See https://github.com/microsoft/sarif-tutorials
Sarif,
}

impl std::fmt::Display for OutputFormat {
Expand All @@ -458,6 +464,7 @@ impl std::fmt::Display for OutputFormat {
OutputFormat::Human => "human",
OutputFormat::Json => "json",
OutputFormat::Jsonl => "jsonl",
OutputFormat::Sarif => "sarif",
};
write!(f, "{s}")
}
Expand All @@ -470,6 +477,7 @@ pub trait Reportable {
fn human_format<W: std::io::Write>(&self, writer: W) -> Result<()>;
fn json_format<W: std::io::Write>(&self, writer: W) -> Result<()>;
fn jsonl_format<W: std::io::Write>(&self, writer: W) -> Result<()>;
fn sarif_format<W: std::io::Write>(&self, writer: W) -> Result<()>;

fn report(&self, output_args: &OutputArgs) -> Result<()> {
let writer = output_args
Expand All @@ -480,6 +488,7 @@ pub trait Reportable {
OutputFormat::Human => self.human_format(writer),
OutputFormat::Json => self.json_format(writer),
OutputFormat::Jsonl => self.jsonl_format(writer),
OutputFormat::Sarif => self.sarif_format(writer),
};
match result {
Ok(()) => Ok(()),
Expand Down
4 changes: 4 additions & 0 deletions src/bin/noseyparker/cmd_github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ impl Reportable for RepoReporter {
}
Ok(())
}

fn sarif_format<W: std::io::Write>(&self, _writer: W) -> Result<()> {
bail!("SARIF output not supported for this command")
}
}
Loading

0 comments on commit 9eb6a54

Please sign in to comment.