2
2
(* Prelude *)
3
3
(*****************************************************************************)
4
4
(* 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).
6
6
*
7
7
* This file specifies mainly the JSON formats of:
8
8
* - the output of the 'semgrep scan --json' command
@@ -1124,16 +1124,13 @@ type killing_parent = {
1124
1124
* types used to communicate with the Semgrep backend and are not meant
1125
1125
* to be consumed directly by Semgrep users or tools wrapping Semgrep.
1126
1126
*
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:
1131
1128
* - /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
1134
1131
* 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
1137
1134
*
1138
1135
* alt: we could move all of this in a separate semgrep_posts_v1.atd file
1139
1136
* or semgrep_webapp_v1.atd
@@ -1143,14 +1140,6 @@ type killing_parent = {
1143
1140
(* Features *)
1144
1141
(* ----------------------------- *)
1145
1142
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
-
1154
1143
type features = {
1155
1144
~autofix: bool;
1156
1145
~deepsemgrep: bool;
@@ -1192,64 +1181,8 @@ type action = [
1192
1181
]
1193
1182
1194
1183
(* ----------------------------- *)
1195
- (* CI configurations *)
1184
+ (* CI scan response *)
1196
1185
(* ----------------------------- *)
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
-
1253
1186
(* Response from the backend to the CLI to the POST /api/cli/scans *)
1254
1187
type scan_response = {
1255
1188
info: scan_info;
@@ -1262,16 +1195,15 @@ type scan_response = {
1262
1195
type scan_info = {
1263
1196
?id: int option; (* the scan id, null for dry-runs *)
1264
1197
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.
1269
1201
*)
1270
1202
deployment_id: int;
1271
1203
deployment_name: string;
1272
1204
}
1273
1205
1274
- (* config specific to the scan, eg *)
1206
+ (* config specific to the scan *)
1275
1207
type scan_configuration = {
1276
1208
rules: raw_json; (* can we type this better *)
1277
1209
inherit triage_ignored;
@@ -1308,13 +1240,6 @@ type historical_configuration = {
1308
1240
?lookback_days: int option;
1309
1241
}
1310
1242
1311
- (* ----------------------------- *)
1312
- (* CI Deployment response *)
1313
- (* ----------------------------- *)
1314
- type deployment_response = {
1315
- deployment: deployment_config;
1316
- }
1317
-
1318
1243
(* ----------------------------- *)
1319
1244
(* CI Scan request *)
1320
1245
(* ----------------------------- *)
@@ -1416,6 +1341,21 @@ type scan_metadata = {
1416
1341
?sms_scan_id: string option;
1417
1342
}
1418
1343
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
+
1419
1359
(* ----------------------------- *)
1420
1360
(* Findings *)
1421
1361
(* ----------------------------- *)
@@ -1729,6 +1669,70 @@ type ci_scan_failure = {
1729
1669
stderr: string;
1730
1670
}
1731
1671
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
+
1732
1736
(* ----------------------------- *)
1733
1737
(* TODO a better CI config from cloud *)
1734
1738
(* ----------------------------- *)
0 commit comments