-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsemgrep_output_v1.py
More file actions
13937 lines (10778 loc) · 477 KB
/
semgrep_output_v1.py
File metadata and controls
13937 lines (10778 loc) · 477 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Generated by atdpy from type definitions in semgrep_output_v1.atd.
This implements classes for the types defined in 'semgrep_output_v1.atd', providing
methods and functions to convert data from/to JSON.
Specification of the Semgrep CLI JSON output formats using ATD (see
https://atd.readthedocs.io/en/latest/ for information on ATD).
This file specifies mainly the JSON formats of:
- the output of the ``semgrep scan --json`` command
- the output of the ``semgrep test --json`` command
- the messages exchanged with the Semgrep backend by the ``semgrep ci``
command
It's also (ab)used to specify the JSON input and output of semgrep-core,
some RPC between pysemgrep and semgrep-core, and a few more internal
things. We should use separate .atd for those different purposes but ATD
does not have a proper module system yet and many types are shared so it
is simpler for now to have everything in one file.
There are other important form of outputs which are not specified here:
- The semgrep metrics sent to https://metrics.semgrep.dev in
semgrep_metrics.atd
- The parsing stats of semgrep-core -parsing_stats -json have its own
Parsing_stats.atd
For the definition of the Semgrep input (the rules), see
rule_schema_v2.atd
This file has the _v1 suffix to explicitely represent the version of this
JSON format. If you need to extend this file, please be careful because
you may break consumers of this format (e.g., the Semgrep playground or
Semgrep backend or external users of this JSON). See
https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades
for more information on how to smoothly extend the types in this file.
Any backward incompatible changes should require to upgrade the major
version of Semgrep as this JSON output is part of the "API" of Semgrep
(any incompatible changes to the rule format should also require a major
version upgrade). Hopefully, we will always be backward compatible.
However, a few fields are tagged with [EXPERIMENTAL] meaning external
users should not rely on them as those fields may be changed or removed.
They are not part of the "API" of Semgrep.
Again, keep in mind that this file is used both by the CLI to *produce* a
JSON output, and by our backends to *consume* the JSON, including to
consume the JSON produced by old versions of the CLI. As of Nov 2024, our
backend is still supporting as far as Semgrep 1.50.0 released Nov 2023.
(see server/semgrep_app/util/cli_version_support.py in the semgrep-app
repo)
This file is translated in OCaml modules by atdgen. Look for the
corresponding Semgrep_output_v1_[tj].ml[i] generated files under dune's
_build/ folder. A few types below have the 'deriving show' decorator
because those types are reused in semgrep core data structures and we make
heavy use of 'deriving show' in OCaml to help debug things.
This file is also translated in Python modules by atdpy. For Python, a few
types have the 'dataclass(frozen=True)' decorator so that the class can be
hashed and put in set. Indeed, with 'Frozen=True' the class is immutable
and dataclass can autogenerate a hash function for it.
Finally this file is translated in jsonschema/openapi spec by atdcat, and
in Typescript modules by atdts.
History:
- the types in this file were originally inferred from JSON_report.ml for
use by spacegrep when it was separate from semgrep-core. It's now also
useds in JSON_report.ml (now called Core_json_output.ml)
- it was extended to not only support semgrep-core JSON output but also
(py)semgrep CLI output!
- it was then simplified with the osemgrep migration effort by removing
gradually the semgrep-core JSON output.
- it was extended to support 'semgrep ci' output to type most messages
sent between the Semgrep CLI and the Semgrep backend
- we use this file to specify RPCs between pysemgrep and semgrep-core for
the gradual migration effort of osemgrep
- merged what was in Input_to_core.atd here
"""
# Disable flake8 entirely on this file:
# flake8: noqa
# Import annotations to allow forward references
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, List, NoReturn, Optional, Tuple, Union
import json
############################################################################
# Private functions
############################################################################
def _atd_missing_json_field(type_name: str, json_field_name: str) -> NoReturn:
raise ValueError(f"missing field '{json_field_name}'"
f" in JSON object of type '{type_name}'")
def _atd_bad_json(expected_type: str, json_value: Any) -> NoReturn:
value_str = str(json_value)
if len(value_str) > 200:
value_str = value_str[:200] + '…'
raise ValueError(f"incompatible JSON value where"
f" type '{expected_type}' was expected: '{value_str}'")
def _atd_bad_python(expected_type: str, json_value: Any) -> NoReturn:
value_str = str(json_value)
if len(value_str) > 200:
value_str = value_str[:200] + '…'
raise ValueError(f"incompatible Python value where"
f" type '{expected_type}' was expected: '{value_str}'")
def _atd_read_unit(x: Any) -> None:
if x is None:
return x
else:
_atd_bad_json('unit', x)
def _atd_read_bool(x: Any) -> bool:
if isinstance(x, bool):
return x
else:
_atd_bad_json('bool', x)
def _atd_read_int(x: Any) -> int:
if isinstance(x, int):
return x
else:
_atd_bad_json('int', x)
def _atd_read_float(x: Any) -> float:
if isinstance(x, (int, float)):
return x
else:
_atd_bad_json('float', x)
def _atd_read_string(x: Any) -> str:
if isinstance(x, str):
return x
else:
_atd_bad_json('str', x)
def _atd_read_list(
read_elt: Callable[[Any], Any]
) -> Callable[[List[Any]], List[Any]]:
def read_list(elts: List[Any]) -> List[Any]:
if isinstance(elts, list):
return [read_elt(elt) for elt in elts]
else:
_atd_bad_json('array', elts)
return read_list
def _atd_read_assoc_array_into_dict(
read_key: Callable[[Any], Any],
read_value: Callable[[Any], Any],
) -> Callable[[List[Any]], Dict[Any, Any]]:
def read_assoc(elts: List[List[Any]]) -> Dict[str, Any]:
if isinstance(elts, list):
return {read_key(elt[0]): read_value(elt[1]) for elt in elts}
else:
_atd_bad_json('array', elts)
raise AssertionError('impossible') # keep mypy happy
return read_assoc
def _atd_read_assoc_object_into_dict(
read_value: Callable[[Any], Any]
) -> Callable[[Dict[str, Any]], Dict[str, Any]]:
def read_assoc(elts: Dict[str, Any]) -> Dict[str, Any]:
if isinstance(elts, dict):
return {_atd_read_string(k): read_value(v)
for k, v in elts.items()}
else:
_atd_bad_json('object', elts)
raise AssertionError('impossible') # keep mypy happy
return read_assoc
def _atd_read_assoc_object_into_list(
read_value: Callable[[Any], Any]
) -> Callable[[Dict[str, Any]], List[Tuple[str, Any]]]:
def read_assoc(elts: Dict[str, Any]) -> List[Tuple[str, Any]]:
if isinstance(elts, dict):
return [(_atd_read_string(k), read_value(v))
for k, v in elts.items()]
else:
_atd_bad_json('object', elts)
raise AssertionError('impossible') # keep mypy happy
return read_assoc
def _atd_read_nullable(read_elt: Callable[[Any], Any]) \
-> Callable[[Optional[Any]], Optional[Any]]:
def read_nullable(x: Any) -> Any:
if x is None:
return None
else:
return read_elt(x)
return read_nullable
def _atd_read_option(read_elt: Callable[[Any], Any]) \
-> Callable[[Optional[Any]], Optional[Any]]:
def read_option(x: Any) -> Any:
if x == 'None':
return None
elif isinstance(x, List) and len(x) == 2 and x[0] == 'Some':
return read_elt(x[1])
else:
_atd_bad_json('option', x)
raise AssertionError('impossible') # keep mypy happy
return read_option
def _atd_write_unit(x: Any) -> None:
if x is None:
return x
else:
_atd_bad_python('unit', x)
def _atd_write_bool(x: Any) -> bool:
if isinstance(x, bool):
return x
else:
_atd_bad_python('bool', x)
def _atd_write_int(x: Any) -> int:
if isinstance(x, int):
return x
else:
_atd_bad_python('int', x)
def _atd_write_float(x: Any) -> float:
if isinstance(x, (int, float)):
return x
else:
_atd_bad_python('float', x)
def _atd_write_string(x: Any) -> str:
if isinstance(x, str):
return x
else:
_atd_bad_python('str', x)
def _atd_write_list(
write_elt: Callable[[Any], Any]
) -> Callable[[List[Any]], List[Any]]:
def write_list(elts: List[Any]) -> List[Any]:
if isinstance(elts, list):
return [write_elt(elt) for elt in elts]
else:
_atd_bad_python('list', elts)
return write_list
def _atd_write_assoc_dict_to_array(
write_key: Callable[[Any], Any],
write_value: Callable[[Any], Any]
) -> Callable[[Dict[Any, Any]], List[Tuple[Any, Any]]]:
def write_assoc(elts: Dict[str, Any]) -> List[Tuple[str, Any]]:
if isinstance(elts, dict):
return [(write_key(k), write_value(v)) for k, v in elts.items()]
else:
_atd_bad_python('Dict[str, <value type>]]', elts)
raise AssertionError('impossible') # keep mypy happy
return write_assoc
def _atd_write_assoc_dict_to_object(
write_value: Callable[[Any], Any]
) -> Callable[[Dict[str, Any]], Dict[str, Any]]:
def write_assoc(elts: Dict[str, Any]) -> Dict[str, Any]:
if isinstance(elts, dict):
return {_atd_write_string(k): write_value(v)
for k, v in elts.items()}
else:
_atd_bad_python('Dict[str, <value type>]', elts)
raise AssertionError('impossible') # keep mypy happy
return write_assoc
def _atd_write_assoc_list_to_object(
write_value: Callable[[Any], Any],
) -> Callable[[List[Any]], Dict[str, Any]]:
def write_assoc(elts: List[List[Any]]) -> Dict[str, Any]:
if isinstance(elts, list):
return {_atd_write_string(elt[0]): write_value(elt[1])
for elt in elts}
else:
_atd_bad_python('List[Tuple[<key type>, <value type>]]', elts)
raise AssertionError('impossible') # keep mypy happy
return write_assoc
def _atd_write_nullable(write_elt: Callable[[Any], Any]) \
-> Callable[[Optional[Any]], Optional[Any]]:
def write_nullable(x: Any) -> Any:
if x is None:
return None
else:
return write_elt(x)
return write_nullable
def _atd_write_option(write_elt: Callable[[Any], Any]) \
-> Callable[[Optional[Any]], Optional[Any]]:
def write_option(x: Any) -> Any:
if x is None:
return 'None'
else:
return ['Some', write_elt(x)]
return write_option
############################################################################
# Public classes
############################################################################
@dataclass
class Datetime:
"""Original type: datetime
RFC 3339 format
"""
value: str
@classmethod
def from_json(cls, x: Any) -> 'Datetime':
return cls(_atd_read_string(x))
def to_json(self) -> Any:
return _atd_write_string(self.value)
@classmethod
def from_json_string(cls, x: str) -> 'Datetime':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class DependencyChild:
"""Original type: dependency_child = { ... }
"""
package: str
version: str
@classmethod
def from_json(cls, x: Any) -> 'DependencyChild':
if isinstance(x, dict):
return cls(
package=_atd_read_string(x['package']) if 'package' in x else _atd_missing_json_field('DependencyChild', 'package'),
version=_atd_read_string(x['version']) if 'version' in x else _atd_missing_json_field('DependencyChild', 'version'),
)
else:
_atd_bad_json('DependencyChild', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
res['package'] = _atd_write_string(self.package)
res['version'] = _atd_write_string(self.version)
return res
@classmethod
def from_json_string(cls, x: str) -> 'DependencyChild':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Direct:
"""Original type: dependency_kind = [ ... | Direct | ... ]
we depend directly on the 3rd-party library mentioned in the lockfile
(e.g., use of log4j library and concrete calls to log4j in 1st-party
code). log4j must be declared as a direct dependency in the manifest file.
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Direct'
@staticmethod
def to_json() -> Any:
return 'direct'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Transitive:
"""Original type: dependency_kind = [ ... | Transitive | ... ]
we depend indirectly (transitively) on the 3rd-party library (e.g., if we
use lodash which itself uses internally log4j then lodash is a Direct
dependency and log4j a Transitive one)
alt: Indirect
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Transitive'
@staticmethod
def to_json() -> Any:
return 'transitive'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Unknown:
"""Original type: dependency_kind = [ ... | Unknown | ... ]
If there is insufficient information to determine the transitivity, such
as a requirements.txt file without a requirements.in manifest, we leave it
Unknown.
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Unknown'
@staticmethod
def to_json() -> Any:
return 'unknown'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class DependencyKind:
"""Original type: dependency_kind = [ ... ]
"""
value: Union[Direct, Transitive, Unknown]
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return self.value.kind
@classmethod
def from_json(cls, x: Any) -> 'DependencyKind':
if isinstance(x, str):
if x == 'direct':
return cls(Direct())
if x == 'transitive':
return cls(Transitive())
if x == 'unknown':
return cls(Unknown())
_atd_bad_json('DependencyKind', x)
_atd_bad_json('DependencyKind', x)
def to_json(self) -> Any:
return self.value.to_json()
@classmethod
def from_json_string(cls, x: str) -> 'DependencyKind':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Npm:
"""Original type: ecosystem = [ ... | Npm | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Npm'
@staticmethod
def to_json() -> Any:
return 'npm'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Pypi:
"""Original type: ecosystem = [ ... | Pypi | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Pypi'
@staticmethod
def to_json() -> Any:
return 'pypi'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Gem:
"""Original type: ecosystem = [ ... | Gem | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Gem'
@staticmethod
def to_json() -> Any:
return 'gem'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Gomod:
"""Original type: ecosystem = [ ... | Gomod | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Gomod'
@staticmethod
def to_json() -> Any:
return 'gomod'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Cargo:
"""Original type: ecosystem = [ ... | Cargo | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Cargo'
@staticmethod
def to_json() -> Any:
return 'cargo'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Maven:
"""Original type: ecosystem = [ ... | Maven | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Maven'
@staticmethod
def to_json() -> Any:
return 'maven'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Composer:
"""Original type: ecosystem = [ ... | Composer | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Composer'
@staticmethod
def to_json() -> Any:
return 'composer'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Nuget:
"""Original type: ecosystem = [ ... | Nuget | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Nuget'
@staticmethod
def to_json() -> Any:
return 'nuget'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Pub:
"""Original type: ecosystem = [ ... | Pub | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Pub'
@staticmethod
def to_json() -> Any:
return 'pub'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class SwiftPM:
"""Original type: ecosystem = [ ... | SwiftPM | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'SwiftPM'
@staticmethod
def to_json() -> Any:
return 'swiftpm'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Cocoapods:
"""Original type: ecosystem = [ ... | Cocoapods | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Cocoapods'
@staticmethod
def to_json() -> Any:
return 'cocoapods'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Mix:
"""Original type: ecosystem = [ ... | Mix | ... ]
Deprecated: Mix is a build system, should use Hex, which is the ecosystem
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Mix'
@staticmethod
def to_json() -> Any:
return 'mix'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Hex:
"""Original type: ecosystem = [ ... | Hex | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Hex'
@staticmethod
def to_json() -> Any:
return 'hex'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Opam:
"""Original type: ecosystem = [ ... | Opam | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Opam'
@staticmethod
def to_json() -> Any:
return 'opam'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class Ecosystem:
"""Original type: ecosystem = [ ... ]
both ecosystem and transitivity below have frozen=True so the generated
classes can be hashed and put in sets (see calls to reachable_deps.add()
in semgrep SCA code)
alt: type package_manager
"""
value: Union[Npm, Pypi, Gem, Gomod, Cargo, Maven, Composer, Nuget, Pub, SwiftPM, Cocoapods, Mix, Hex, Opam]
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return self.value.kind
@classmethod
def from_json(cls, x: Any) -> 'Ecosystem':
if isinstance(x, str):
if x == 'npm':
return cls(Npm())
if x == 'pypi':
return cls(Pypi())
if x == 'gem':
return cls(Gem())
if x == 'gomod':
return cls(Gomod())
if x == 'cargo':
return cls(Cargo())
if x == 'maven':
return cls(Maven())
if x == 'composer':
return cls(Composer())
if x == 'nuget':
return cls(Nuget())
if x == 'pub':
return cls(Pub())
if x == 'swiftpm':
return cls(SwiftPM())
if x == 'cocoapods':
return cls(Cocoapods())
if x == 'mix':
return cls(Mix())
if x == 'hex':
return cls(Hex())
if x == 'opam':
return cls(Opam())
_atd_bad_json('Ecosystem', x)
_atd_bad_json('Ecosystem', x)
def to_json(self) -> Any:
return self.value.to_json()
@classmethod
def from_json_string(cls, x: str) -> 'Ecosystem':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True, order=True)
class Fpath:
"""Original type: fpath
"""
value: str
@classmethod
def from_json(cls, x: Any) -> 'Fpath':
return cls(_atd_read_string(x))
def to_json(self) -> Any:
return _atd_write_string(self.value)
@classmethod
def from_json_string(cls, x: str) -> 'Fpath':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class FoundDependency:
"""Original type: found_dependency = { ... }
:param allowed_hashes: ???
:param manifest_path: Path to the manifest file that defines the project
containing this dependency. Examples: package.json, nested/folder/pom.xml
:param lockfile_path: Path to the lockfile that contains this dependency.
Examples: package-lock.json, nested/folder/requirements.txt, go.mod. Since
1.87.0
:param line_number: The line number of the dependency in the lockfile.
When combined with the lockfile_path, this can identify the location of
the dependency in the lockfile.
:param children: If we have dependency relationship information for this
dependency, this field will include the name and version of other
found_dependency items that this dependency requires. These fields must
match values in `package` and `version` of another `found_dependency` in
the same set
:param git_ref: Git ref of the dependency if the dependency comes directly
from a git repo. Examples: refs/heads/main, refs/tags/v1.0.0,
e5c704df4d308690fed696faf4c86453b4d88a95. Since 1.66.0
"""
package: str
version: str
ecosystem: Ecosystem
allowed_hashes: Dict[str, List[str]]
transitivity: DependencyKind
resolved_url: Optional[str] = None
manifest_path: Optional[Fpath] = None
lockfile_path: Optional[Fpath] = None
line_number: Optional[int] = None
children: Optional[List[DependencyChild]] = None
git_ref: Optional[str] = None
@classmethod
def from_json(cls, x: Any) -> 'FoundDependency':
if isinstance(x, dict):
return cls(
package=_atd_read_string(x['package']) if 'package' in x else _atd_missing_json_field('FoundDependency', 'package'),
version=_atd_read_string(x['version']) if 'version' in x else _atd_missing_json_field('FoundDependency', 'version'),
ecosystem=Ecosystem.from_json(x['ecosystem']) if 'ecosystem' in x else _atd_missing_json_field('FoundDependency', 'ecosystem'),
allowed_hashes=_atd_read_assoc_object_into_dict(_atd_read_list(_atd_read_string))(x['allowed_hashes']) if 'allowed_hashes' in x else _atd_missing_json_field('FoundDependency', 'allowed_hashes'),
transitivity=DependencyKind.from_json(x['transitivity']) if 'transitivity' in x else _atd_missing_json_field('FoundDependency', 'transitivity'),
resolved_url=_atd_read_string(x['resolved_url']) if 'resolved_url' in x else None,
manifest_path=Fpath.from_json(x['manifest_path']) if 'manifest_path' in x else None,
lockfile_path=Fpath.from_json(x['lockfile_path']) if 'lockfile_path' in x else None,
line_number=_atd_read_int(x['line_number']) if 'line_number' in x else None,
children=_atd_read_list(DependencyChild.from_json)(x['children']) if 'children' in x else None,
git_ref=_atd_read_string(x['git_ref']) if 'git_ref' in x else None,
)
else:
_atd_bad_json('FoundDependency', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
res['package'] = _atd_write_string(self.package)
res['version'] = _atd_write_string(self.version)
res['ecosystem'] = (lambda x: x.to_json())(self.ecosystem)
res['allowed_hashes'] = _atd_write_assoc_dict_to_object(_atd_write_list(_atd_write_string))(self.allowed_hashes)
res['transitivity'] = (lambda x: x.to_json())(self.transitivity)
if self.resolved_url is not None:
res['resolved_url'] = _atd_write_string(self.resolved_url)
if self.manifest_path is not None:
res['manifest_path'] = (lambda x: x.to_json())(self.manifest_path)
if self.lockfile_path is not None:
res['lockfile_path'] = (lambda x: x.to_json())(self.lockfile_path)
if self.line_number is not None:
res['line_number'] = _atd_write_int(self.line_number)
if self.children is not None:
res['children'] = _atd_write_list((lambda x: x.to_json()))(self.children)
if self.git_ref is not None:
res['git_ref'] = _atd_write_string(self.git_ref)
return res
@classmethod
def from_json_string(cls, x: str) -> 'FoundDependency':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class PipRequirementsTxt:
"""Original type: lockfile_kind = [ ... | PipRequirementsTxt | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'PipRequirementsTxt'
@staticmethod
def to_json() -> Any:
return 'PipRequirementsTxt'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class PoetryLock:
"""Original type: lockfile_kind = [ ... | PoetryLock | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'PoetryLock'
@staticmethod
def to_json() -> Any:
return 'PoetryLock'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class PipfileLock:
"""Original type: lockfile_kind = [ ... | PipfileLock | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'PipfileLock'
@staticmethod
def to_json() -> Any:
return 'PipfileLock'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass(frozen=True)
class UvLock:
"""Original type: lockfile_kind = [ ... | UvLock | ... ]
"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'UvLock'
@staticmethod
def to_json() -> Any:
return 'UvLock'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)