Skip to content

Commit 705ebb0

Browse files
authored
Adjust comments about deployment_config and semgrep ci HTTP requests (#338)
test plan: wait for green CI checks and see related PR in semgrep - [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.50.0. See https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades Note that the types related to the semgrep-core JSON output or the semgrep-core RPC do not need to be backward compatible! --------- Co-authored-by: pad <[email protected]>
1 parent 41bdd7f commit 705ebb0

4 files changed

+398
-394
lines changed

semgrep_output_v1.atd

+90-86
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(* Prelude *)
33
(*****************************************************************************)
44
(* Specification of the Semgrep CLI JSON output formats using ATD
5-
* (see https://atd.readthedocs.io/en/latest/ for more information on ATD).
5+
* (see https://atd.readthedocs.io/en/latest/ for information on ATD).
66
*
77
* This file specifies mainly the JSON formats of:
88
* - the output of the 'semgrep scan --json' command
@@ -1124,16 +1124,13 @@ type killing_parent = {
11241124
* types used to communicate with the Semgrep backend and are not meant
11251125
* to be consumed directly by Semgrep users or tools wrapping Semgrep.
11261126
*
1127-
* The sequence of HTTP requests for 'semgrep ci' is mostly:
1128-
* - /api/agent/deployments/current with token
1129-
* and response with deployment name in a deployment config
1130-
* (TODO? get rid of this one? useful?)
1127+
* The sequence of HTTP requests for 'semgrep ci' is:
11311128
* - /api/cli/scans when starting a scan, with information about the project
1132-
* and response with scan_id and scan_config including the rules to use
1133-
* - /results to send the findings to the backend
1129+
* and response with scan_id and scan_response including the rules to use
1130+
* - /api/agent/scans/<scan_id>/results to send the findings to the backend
11341131
* and response with errors and task_id
1135-
* - /complete when done, with the exit code and a few more information
1136-
* and response with app_block_override and reason
1132+
* - /api/agent/scans/<scan_id>/complete when done, with the exit code and a
1133+
* few more information and response with app_block_override and reason
11371134
*
11381135
* alt: we could move all of this in a separate semgrep_posts_v1.atd file
11391136
* or semgrep_webapp_v1.atd
@@ -1143,14 +1140,6 @@ type killing_parent = {
11431140
(* Features *)
11441141
(* ----------------------------- *)
11451142

1146-
(* whether a certain feature is available for a deployment *)
1147-
type has_features = {
1148-
~has_autofix : bool;
1149-
~has_deepsemgrep : bool;
1150-
~has_triage_via_comment : bool;
1151-
~has_dependency_query : bool;
1152-
}
1153-
11541143
type features = {
11551144
~autofix: bool;
11561145
~deepsemgrep: bool;
@@ -1192,64 +1181,8 @@ type action = [
11921181
]
11931182

11941183
(* ----------------------------- *)
1195-
(* CI configurations *)
1184+
(* CI scan response *)
11961185
(* ----------------------------- *)
1197-
1198-
(* Response by the backend to the CLI to the POST deployments/current *)
1199-
type deployment_config <ocaml attr="deriving show"> = {
1200-
id : int;
1201-
(* the important piece, the deployment name (e.g., "returntocorp" *)
1202-
name : string;
1203-
~organization_id : int;
1204-
(* All three below seem similar to 'name' mostly (e.g., "returntocorp") *)
1205-
~display_name : string;
1206-
~scm_name : string;
1207-
~slug : string;
1208-
(* ex: "github" *)
1209-
~source_type : string;
1210-
(* ex: "member" *)
1211-
~default_user_role : string;
1212-
(* TODO? factorize in ci_config_from_cloud instead of here and scan_config? *)
1213-
inherit has_features;
1214-
}
1215-
1216-
(* Content of a possible .semgrepconfig.yml in the repository.
1217-
*
1218-
* This config allows to configure Semgrep per repo, e.g., to store
1219-
* a category/tag like "webapp" in a repo so that the Semgrep WebApp can
1220-
* return a set of relevant rules automatically for this repo in scan_config
1221-
* later when given this ci_config_from_repo in the scan_request.
1222-
*)
1223-
type ci_config_from_repo = {
1224-
(* version of the .semgrepconfig.yml format. "v1" right now (useful?) *)
1225-
~version <python default="Version('v1')"> <ts default="'v1'">: version;
1226-
?tags: tag list option;
1227-
}
1228-
(* ex: "webapp" *)
1229-
type tag = string
1230-
1231-
(* Response by the backend to the CLI to the POST deployments/scans/config
1232-
* DEPRECATED? seems to be used only by semgrep lsp.
1233-
*)
1234-
type scan_config = {
1235-
deployment_id: int;
1236-
deployment_name: string;
1237-
(* ex: "audit", "comment", "block" TODO use enum? TODO: seems dead *)
1238-
policy_names: string list;
1239-
(* rules raw content in JSON format (but still sent as a string) *)
1240-
rule_config: string;
1241-
inherit features;
1242-
inherit triage_ignored;
1243-
(* glob patterns *)
1244-
~ignored_files: string list;
1245-
(* since 1.37.0 *)
1246-
?enabled_products: product list option;
1247-
(* since 1.64.0 *)
1248-
~actions: action list;
1249-
(* since 1.47.0 but not created by the backend (nor used by the CLI) *)
1250-
?ci_config_from_cloud: ci_config_from_cloud option;
1251-
}
1252-
12531186
(* Response from the backend to the CLI to the POST /api/cli/scans *)
12541187
type scan_response = {
12551188
info: scan_info;
@@ -1262,16 +1195,15 @@ type scan_response = {
12621195
type scan_info = {
12631196
?id: int option; (* the scan id, null for dry-runs *)
12641197
enabled_products: product list;
1265-
(* redundant with deployment_config?
1266-
* TODO? remove the intermediate call to get the deployment and
1267-
* start a scan to /api/cli/scans/ without first accessing
1268-
* api/agent/deployments/current?
1198+
(* Those fields are also in deployment_config but they are also
1199+
* here so that 'semgrep ci' does not need an extra HTTP request to the
1200+
* deployment endpoint to get this info.
12691201
*)
12701202
deployment_id: int;
12711203
deployment_name: string;
12721204
}
12731205

1274-
(* config specific to the scan, eg *)
1206+
(* config specific to the scan *)
12751207
type scan_configuration = {
12761208
rules: raw_json; (* can we type this better *)
12771209
inherit triage_ignored;
@@ -1308,13 +1240,6 @@ type historical_configuration = {
13081240
?lookback_days: int option;
13091241
}
13101242

1311-
(* ----------------------------- *)
1312-
(* CI Deployment response *)
1313-
(* ----------------------------- *)
1314-
type deployment_response = {
1315-
deployment: deployment_config;
1316-
}
1317-
13181243
(* ----------------------------- *)
13191244
(* CI Scan request *)
13201245
(* ----------------------------- *)
@@ -1416,6 +1341,21 @@ type scan_metadata = {
14161341
?sms_scan_id: string option;
14171342
}
14181343

1344+
(* Content of a possible .semgrepconfig.yml in the repository.
1345+
*
1346+
* This config allows to configure Semgrep per repo, e.g., to store
1347+
* a category/tag like "webapp" in a repo so that the Semgrep WebApp can
1348+
* return a set of relevant rules automatically for this repo in scan_config
1349+
* later when given this ci_config_from_repo in the scan_request.
1350+
*)
1351+
type ci_config_from_repo = {
1352+
(* version of the .semgrepconfig.yml format. "v1" right now (useful?) *)
1353+
~version <python default="Version('v1')"> <ts default="'v1'">: version;
1354+
?tags: tag list option;
1355+
}
1356+
(* ex: "webapp" *)
1357+
type tag = string
1358+
14191359
(* ----------------------------- *)
14201360
(* Findings *)
14211361
(* ----------------------------- *)
@@ -1729,6 +1669,70 @@ type ci_scan_failure = {
17291669
stderr: string;
17301670
}
17311671

1672+
(* ----------------------------- *)
1673+
(* Other comms *)
1674+
(* ----------------------------- *)
1675+
1676+
(* Response by the backend to the CLI to the POST api/agent/deployments/current
1677+
* Some of the information in deployment_config is now returned
1678+
* directly in scan_response (e.g., the deployment_name)
1679+
* TODO: deprecate this endpoint as it is now used only in 'semgrep login' and
1680+
* in 'semgrep show whoami' to just check whether the token is valid.
1681+
*)
1682+
type deployment_config <ocaml attr="deriving show"> = {
1683+
id : int;
1684+
(* the important piece, the deployment name (e.g., "returntocorp" *)
1685+
name : string;
1686+
~organization_id : int;
1687+
(* All three below seem similar to 'name' mostly (e.g., "returntocorp") *)
1688+
~display_name : string;
1689+
~scm_name : string;
1690+
~slug : string;
1691+
(* ex: "github" *)
1692+
~source_type : string;
1693+
(* ex: "member" *)
1694+
~default_user_role : string;
1695+
inherit has_features;
1696+
}
1697+
1698+
(* whether a certain feature is available for a deployment *)
1699+
type has_features = {
1700+
~has_autofix : bool;
1701+
~has_deepsemgrep : bool;
1702+
~has_triage_via_comment : bool;
1703+
~has_dependency_query : bool;
1704+
}
1705+
1706+
type deployment_response = {
1707+
deployment: deployment_config;
1708+
}
1709+
1710+
(* Response by the backend to the CLI to the POST deployments/scans/config
1711+
* The record is similar to scan_response.
1712+
* TODO: deprecate this endpoint/record. Is is used by semgrep lsp and possibly
1713+
* semgrep scan --config policy|supply-chain but we should remove
1714+
* those --config policy|supply-chain and migrate semgrep lsp to
1715+
* /api/cli/scans with dryrun=true
1716+
*)
1717+
type scan_config = {
1718+
deployment_id: int;
1719+
deployment_name: string;
1720+
(* ex: "audit", "comment", "block" TODO use enum? TODO: seems dead *)
1721+
policy_names: string list;
1722+
(* rules raw content in JSON format (but still sent as a string) *)
1723+
rule_config: string;
1724+
inherit features;
1725+
inherit triage_ignored;
1726+
(* glob patterns *)
1727+
~ignored_files: string list;
1728+
(* since 1.37.0 *)
1729+
?enabled_products: product list option;
1730+
(* since 1.64.0 *)
1731+
~actions: action list;
1732+
(* since 1.47.0 but not created by the backend (nor used by the CLI) *)
1733+
?ci_config_from_cloud: ci_config_from_cloud option;
1734+
}
1735+
17321736
(* ----------------------------- *)
17331737
(* TODO a better CI config from cloud *)
17341738
(* ----------------------------- *)

0 commit comments

Comments
 (0)