Skip to content

Commit

Permalink
Pass format_context also to RPC CallSarifFormat (#318)
Browse files Browse the repository at this point in the history
This will enable to gate some fields with is_logged_in

test plan:
see related PR in semgrep-pro


- [x] I ran `make setup && make` to update the generated code after
editing a `.atd` file (TODO: have a CI check)
- [x] I made sure we're still backward compatible with old versions of
the CLI.
For example, the Semgrep backend need to still be able to *consume* data
generated
	  by Semgrep 1.17.0.
See
https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades

Co-authored-by: pad <[email protected]>
  • Loading branch information
aryx and aryx authored Dec 11, 2024
1 parent 3171f20 commit f71d99f
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 180 deletions.
34 changes: 14 additions & 20 deletions semgrep_output_v1.atd
Original file line number Diff line number Diff line change
Expand Up @@ -1937,32 +1937,24 @@ type apply_fixes_return <python decorator="dataclass(frozen=True)"> = {
fixed_lines: (int * string list) list;
}

(* TODO: remove many fields so that CallSarifFormat gets close to CallFormatter.
* I think we just need the 'rules: fpath' as it can't be reconstructed
* from cli_output.
*)
type sarif_format_params <python decorator="dataclass(frozen=True)"> = {
hide_nudge: bool;
engine_label: string;

(* Path the the rules file *)
rules: fpath;

(* Semgrep-core matches along with their match based ids,
* which are needed here because the ocaml implementation
* of fingerprints currently doesn't match python yet.
*)
(* TODO: remove, just use cli_output *)
cli_matches: cli_match list;

(* We use cli_error instead of core_error because it has
* extra info from the python side that cannot be fully
* recovered cleanly on the ocaml side just by the available
* info in core_error.
*)
cli_errors: cli_error list;

(* This field was added later and had to be optional to make it
* backward-compatible and pass PR checks.
*)
?show_dataflow_traces: bool option;
(* TODO: remove, should be able to derive those from format_context *)
hide_nudge: bool;
engine_label: string;
show_dataflow_traces: bool;
}

(* TODO: remove, reuse RetFormatter *)
type sarif_format_return <python decorator="dataclass(frozen=True)"> = {
(* The formatted output. *)
output: string;
Expand Down Expand Up @@ -2151,7 +2143,8 @@ type resolution_result = [
type function_call <python decorator="dataclass(frozen=True)"> = [
| CallContributions
| CallApplyFixes of apply_fixes_params
| CallSarifFormat of sarif_format_params
(* TODO: merge with CallFormatter at some point *)
| CallSarifFormat of (format_context * sarif_format_params)
| CallFormatter of (output_format * format_context * cli_output)
(* NOTE: fpath is most likely a temporary file that contains all the rules in
JSON format. In the future, we could send the rules via a big string through
Expand All @@ -2169,8 +2162,9 @@ type function_call <python decorator="dataclass(frozen=True)"> = [
type function_return <python decorator="dataclass(frozen=True)"> = [
| RetError of string
| RetApplyFixes of apply_fixes_return
| RetSarifFormat of sarif_format_return
| RetContributions of contributions
(* TODO: remove and use RetFormatter for the return of CallSarifFormat too *)
| RetSarifFormat of sarif_format_return
| RetFormatter of string
| RetValidate of bool
| RetResolveDependencies of (dependency_source * resolution_result) list
Expand Down
25 changes: 17 additions & 8 deletions semgrep_output_v1.jsonschema

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

6 changes: 3 additions & 3 deletions semgrep_output_v1.proto

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

51 changes: 25 additions & 26 deletions semgrep_output_v1.py

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

34 changes: 17 additions & 17 deletions semgrep_output_v1.ts

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

Loading

0 comments on commit f71d99f

Please sign in to comment.