-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsemgrep_metrics.py
1129 lines (889 loc) · 38.5 KB
/
semgrep_metrics.py
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_metrics.atd.
This implements classes for the types defined in 'semgrep_metrics.atd', providing
methods and functions to convert data from/to JSON.
"""
# 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
############################################################################
from dataclasses import field
@dataclass
class SupplyChainConfig:
"""Original type: supply_chain_config = { ... }"""
_rfu: Optional[int] = None
@classmethod
def from_json(cls, x: Any) -> 'SupplyChainConfig':
if isinstance(x, dict):
return cls(
_rfu=_atd_read_int(x['_rfu']) if '_rfu' in x else None,
)
else:
_atd_bad_json('SupplyChainConfig', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
if self._rfu is not None:
res['_rfu'] = _atd_write_int(self._rfu)
return res
@classmethod
def from_json_string(cls, x: str) -> 'SupplyChainConfig':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Any_:
"""Original type: secrets_origin = [ ... | Any | ... ]"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Any_'
@staticmethod
def to_json() -> Any:
return 'Any'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Semgrep:
"""Original type: secrets_origin = [ ... | Semgrep | ... ]"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Semgrep'
@staticmethod
def to_json() -> Any:
return 'Semgrep'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class NoCommunity:
"""Original type: secrets_origin = [ ... | NoCommunity | ... ]"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'NoCommunity'
@staticmethod
def to_json() -> Any:
return 'NoCommunity'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class SecretsOrigin:
"""Original type: secrets_origin = [ ... ]"""
value: Union[Any_, Semgrep, NoCommunity]
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return self.value.kind
@classmethod
def from_json(cls, x: Any) -> 'SecretsOrigin':
if isinstance(x, str):
if x == 'Any':
return cls(Any_())
if x == 'Semgrep':
return cls(Semgrep())
if x == 'NoCommunity':
return cls(NoCommunity())
_atd_bad_json('SecretsOrigin', x)
_atd_bad_json('SecretsOrigin', x)
def to_json(self) -> Any:
return self.value.to_json()
@classmethod
def from_json_string(cls, x: str) -> 'SecretsOrigin':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class SecretsConfig:
"""Original type: secrets_config = { ... }"""
permitted_origins: SecretsOrigin
@classmethod
def from_json(cls, x: Any) -> 'SecretsConfig':
if isinstance(x, dict):
return cls(
permitted_origins=SecretsOrigin.from_json(x['permitted_origins']) if 'permitted_origins' in x else _atd_missing_json_field('SecretsConfig', 'permitted_origins'),
)
else:
_atd_bad_json('SecretsConfig', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
res['permitted_origins'] = (lambda x: x.to_json())(self.permitted_origins)
return res
@classmethod
def from_json_string(cls, x: str) -> 'SecretsConfig':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class ProFeatures:
"""Original type: pro_features = { ... }"""
diffDepth: Optional[int] = None
numInterfileDiffScanned: Optional[List[Tuple[str, int]]] = None
@classmethod
def from_json(cls, x: Any) -> 'ProFeatures':
if isinstance(x, dict):
return cls(
diffDepth=_atd_read_int(x['diffDepth']) if 'diffDepth' in x else None,
numInterfileDiffScanned=_atd_read_assoc_object_into_list(_atd_read_int)(x['numInterfileDiffScanned']) if 'numInterfileDiffScanned' in x else None,
)
else:
_atd_bad_json('ProFeatures', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
if self.diffDepth is not None:
res['diffDepth'] = _atd_write_int(self.diffDepth)
if self.numInterfileDiffScanned is not None:
res['numInterfileDiffScanned'] = _atd_write_assoc_list_to_object(_atd_write_int)(self.numInterfileDiffScanned)
return res
@classmethod
def from_json_string(cls, x: str) -> 'ProFeatures':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class CodeConfig:
"""Original type: code_config = { ... }"""
_rfu: Optional[int] = None
@classmethod
def from_json(cls, x: Any) -> 'CodeConfig':
if isinstance(x, dict):
return cls(
_rfu=_atd_read_int(x['_rfu']) if '_rfu' in x else None,
)
else:
_atd_bad_json('CodeConfig', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
if self._rfu is not None:
res['_rfu'] = _atd_write_int(self._rfu)
return res
@classmethod
def from_json_string(cls, x: str) -> 'CodeConfig':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Intraprocedural:
"""Original type: analysis_type = [ ... | Intraprocedural | ... ]"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Intraprocedural'
@staticmethod
def to_json() -> Any:
return 'Intraprocedural'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Interprocedural:
"""Original type: analysis_type = [ ... | Interprocedural | ... ]"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Interprocedural'
@staticmethod
def to_json() -> Any:
return 'Interprocedural'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Interfile:
"""Original type: analysis_type = [ ... | Interfile | ... ]"""
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Interfile'
@staticmethod
def to_json() -> Any:
return 'Interfile'
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class AnalysisType:
"""Original type: analysis_type = [ ... ]"""
value: Union[Intraprocedural, Interprocedural, Interfile]
@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return self.value.kind
@classmethod
def from_json(cls, x: Any) -> 'AnalysisType':
if isinstance(x, str):
if x == 'Intraprocedural':
return cls(Intraprocedural())
if x == 'Interprocedural':
return cls(Interprocedural())
if x == 'Interfile':
return cls(Interfile())
_atd_bad_json('AnalysisType', x)
_atd_bad_json('AnalysisType', x)
def to_json(self) -> Any:
return self.value.to_json()
@classmethod
def from_json_string(cls, x: str) -> 'AnalysisType':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class EngineConfig:
"""Original type: engine_config = { ... }"""
analysis_type: AnalysisType
pro_langs: bool
code_config: Optional[CodeConfig] = None
secrets_config: Optional[SecretsConfig] = None
supply_chain_config: Optional[SupplyChainConfig] = None
@classmethod
def from_json(cls, x: Any) -> 'EngineConfig':
if isinstance(x, dict):
return cls(
analysis_type=AnalysisType.from_json(x['analysis_type']) if 'analysis_type' in x else _atd_missing_json_field('EngineConfig', 'analysis_type'),
pro_langs=_atd_read_bool(x['pro_langs']) if 'pro_langs' in x else _atd_missing_json_field('EngineConfig', 'pro_langs'),
code_config=CodeConfig.from_json(x['code_config']) if 'code_config' in x else None,
secrets_config=SecretsConfig.from_json(x['secrets_config']) if 'secrets_config' in x else None,
supply_chain_config=SupplyChainConfig.from_json(x['supply_chain_config']) if 'supply_chain_config' in x else None,
)
else:
_atd_bad_json('EngineConfig', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
res['analysis_type'] = (lambda x: x.to_json())(self.analysis_type)
res['pro_langs'] = _atd_write_bool(self.pro_langs)
if self.code_config is not None:
res['code_config'] = (lambda x: x.to_json())(self.code_config)
if self.secrets_config is not None:
res['secrets_config'] = (lambda x: x.to_json())(self.secrets_config)
if self.supply_chain_config is not None:
res['supply_chain_config'] = (lambda x: x.to_json())(self.supply_chain_config)
return res
@classmethod
def from_json_string(cls, x: str) -> 'EngineConfig':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Value:
"""Original type: value = { ... }"""
features: List[str]
proFeatures: Optional[ProFeatures] = None
numFindings: Optional[int] = None
numFindingsByProduct: Optional[List[Tuple[str, int]]] = None
numIgnored: Optional[int] = None
ruleHashesWithFindings: Optional[List[Tuple[str, int]]] = None
engineRequested: str = field(default_factory=lambda: 'OSS')
engineConfig: Optional[EngineConfig] = None
interfileLanguagesUsed: Optional[List[str]] = None
@classmethod
def from_json(cls, x: Any) -> 'Value':
if isinstance(x, dict):
return cls(
features=_atd_read_list(_atd_read_string)(x['features']) if 'features' in x else _atd_missing_json_field('Value', 'features'),
proFeatures=ProFeatures.from_json(x['proFeatures']) if 'proFeatures' in x else None,
numFindings=_atd_read_int(x['numFindings']) if 'numFindings' in x else None,
numFindingsByProduct=_atd_read_assoc_object_into_list(_atd_read_int)(x['numFindingsByProduct']) if 'numFindingsByProduct' in x else None,
numIgnored=_atd_read_int(x['numIgnored']) if 'numIgnored' in x else None,
ruleHashesWithFindings=_atd_read_assoc_object_into_list(_atd_read_int)(x['ruleHashesWithFindings']) if 'ruleHashesWithFindings' in x else None,
engineRequested=_atd_read_string(x['engineRequested']) if 'engineRequested' in x else 'OSS',
engineConfig=EngineConfig.from_json(x['engineConfig']) if 'engineConfig' in x else None,
interfileLanguagesUsed=_atd_read_list(_atd_read_string)(x['interfileLanguagesUsed']) if 'interfileLanguagesUsed' in x else None,
)
else:
_atd_bad_json('Value', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
res['features'] = _atd_write_list(_atd_write_string)(self.features)
if self.proFeatures is not None:
res['proFeatures'] = (lambda x: x.to_json())(self.proFeatures)
if self.numFindings is not None:
res['numFindings'] = _atd_write_int(self.numFindings)
if self.numFindingsByProduct is not None:
res['numFindingsByProduct'] = _atd_write_assoc_list_to_object(_atd_write_int)(self.numFindingsByProduct)
if self.numIgnored is not None:
res['numIgnored'] = _atd_write_int(self.numIgnored)
if self.ruleHashesWithFindings is not None:
res['ruleHashesWithFindings'] = _atd_write_assoc_list_to_object(_atd_write_int)(self.ruleHashesWithFindings)
res['engineRequested'] = _atd_write_string(self.engineRequested)
if self.engineConfig is not None:
res['engineConfig'] = (lambda x: x.to_json())(self.engineConfig)
if self.interfileLanguagesUsed is not None:
res['interfileLanguagesUsed'] = _atd_write_list(_atd_write_string)(self.interfileLanguagesUsed)
return res
@classmethod
def from_json_string(cls, x: str) -> 'Value':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Uuid:
"""Original type: uuid"""
value: str
@classmethod
def from_json(cls, x: Any) -> 'Uuid':
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) -> 'Uuid':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Sha256:
"""Original type: sha256"""
value: str
@classmethod
def from_json(cls, x: Any) -> 'Sha256':
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) -> 'Sha256':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class RuleStats:
"""Original type: rule_stats = { ... }"""
ruleHash: str
bytesScanned: int
matchTime: Optional[float] = None
@classmethod
def from_json(cls, x: Any) -> 'RuleStats':
if isinstance(x, dict):
return cls(
ruleHash=_atd_read_string(x['ruleHash']) if 'ruleHash' in x else _atd_missing_json_field('RuleStats', 'ruleHash'),
bytesScanned=_atd_read_int(x['bytesScanned']) if 'bytesScanned' in x else _atd_missing_json_field('RuleStats', 'bytesScanned'),
matchTime=_atd_read_float(x['matchTime']) if 'matchTime' in x else None,
)
else:
_atd_bad_json('RuleStats', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
res['ruleHash'] = _atd_write_string(self.ruleHash)
res['bytesScanned'] = _atd_write_int(self.bytesScanned)
if self.matchTime is not None:
res['matchTime'] = _atd_write_float(self.matchTime)
return res
@classmethod
def from_json_string(cls, x: str) -> 'RuleStats':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class FileStats:
"""Original type: file_stats = { ... }"""
size: int
numTimesScanned: int
parseTime: Optional[float] = None
matchTime: Optional[float] = None
runTime: Optional[float] = None
@classmethod
def from_json(cls, x: Any) -> 'FileStats':
if isinstance(x, dict):
return cls(
size=_atd_read_int(x['size']) if 'size' in x else _atd_missing_json_field('FileStats', 'size'),
numTimesScanned=_atd_read_int(x['numTimesScanned']) if 'numTimesScanned' in x else _atd_missing_json_field('FileStats', 'numTimesScanned'),
parseTime=_atd_read_float(x['parseTime']) if 'parseTime' in x else None,
matchTime=_atd_read_float(x['matchTime']) if 'matchTime' in x else None,
runTime=_atd_read_float(x['runTime']) if 'runTime' in x else None,
)
else:
_atd_bad_json('FileStats', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
res['size'] = _atd_write_int(self.size)
res['numTimesScanned'] = _atd_write_int(self.numTimesScanned)
if self.parseTime is not None:
res['parseTime'] = _atd_write_float(self.parseTime)
if self.matchTime is not None:
res['matchTime'] = _atd_write_float(self.matchTime)
if self.runTime is not None:
res['runTime'] = _atd_write_float(self.runTime)
return res
@classmethod
def from_json_string(cls, x: str) -> 'FileStats':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Performance:
"""Original type: performance = { ... }"""
numRules: Optional[int] = None
numTargets: Optional[int] = None
totalBytesScanned: Optional[int] = None
fileStats: Optional[List[FileStats]] = None
ruleStats: Optional[List[RuleStats]] = None
profilingTimes: Optional[List[Tuple[str, float]]] = None
maxMemoryBytes: Optional[int] = None
@classmethod
def from_json(cls, x: Any) -> 'Performance':
if isinstance(x, dict):
return cls(
numRules=_atd_read_int(x['numRules']) if 'numRules' in x else None,
numTargets=_atd_read_int(x['numTargets']) if 'numTargets' in x else None,
totalBytesScanned=_atd_read_int(x['totalBytesScanned']) if 'totalBytesScanned' in x else None,
fileStats=_atd_read_list(FileStats.from_json)(x['fileStats']) if 'fileStats' in x else None,
ruleStats=_atd_read_list(RuleStats.from_json)(x['ruleStats']) if 'ruleStats' in x else None,
profilingTimes=_atd_read_assoc_object_into_list(_atd_read_float)(x['profilingTimes']) if 'profilingTimes' in x else None,
maxMemoryBytes=_atd_read_int(x['maxMemoryBytes']) if 'maxMemoryBytes' in x else None,
)
else:
_atd_bad_json('Performance', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
if self.numRules is not None:
res['numRules'] = _atd_write_int(self.numRules)
if self.numTargets is not None:
res['numTargets'] = _atd_write_int(self.numTargets)
if self.totalBytesScanned is not None:
res['totalBytesScanned'] = _atd_write_int(self.totalBytesScanned)
if self.fileStats is not None:
res['fileStats'] = _atd_write_list((lambda x: x.to_json()))(self.fileStats)
if self.ruleStats is not None:
res['ruleStats'] = _atd_write_list((lambda x: x.to_json()))(self.ruleStats)
if self.profilingTimes is not None:
res['profilingTimes'] = _atd_write_assoc_list_to_object(_atd_write_float)(self.profilingTimes)
if self.maxMemoryBytes is not None:
res['maxMemoryBytes'] = _atd_write_int(self.maxMemoryBytes)
return res
@classmethod
def from_json_string(cls, x: str) -> 'Performance':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class ParseStat:
"""Original type: parse_stat = { ... }"""
targets_parsed: int
num_targets: int
bytes_parsed: int
num_bytes: int
@classmethod
def from_json(cls, x: Any) -> 'ParseStat':
if isinstance(x, dict):
return cls(
targets_parsed=_atd_read_int(x['targets_parsed']) if 'targets_parsed' in x else _atd_missing_json_field('ParseStat', 'targets_parsed'),
num_targets=_atd_read_int(x['num_targets']) if 'num_targets' in x else _atd_missing_json_field('ParseStat', 'num_targets'),
bytes_parsed=_atd_read_int(x['bytes_parsed']) if 'bytes_parsed' in x else _atd_missing_json_field('ParseStat', 'bytes_parsed'),
num_bytes=_atd_read_int(x['num_bytes']) if 'num_bytes' in x else _atd_missing_json_field('ParseStat', 'num_bytes'),
)
else:
_atd_bad_json('ParseStat', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
res['targets_parsed'] = _atd_write_int(self.targets_parsed)
res['num_targets'] = _atd_write_int(self.num_targets)
res['bytes_parsed'] = _atd_write_int(self.bytes_parsed)
res['num_bytes'] = _atd_write_int(self.num_bytes)
return res
@classmethod
def from_json_string(cls, x: str) -> 'ParseStat':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Extension:
"""Original type: extension = { ... }"""
machineId: Optional[str] = None
isNewAppInstall: Optional[bool] = None
sessionId: Optional[str] = None
version: Optional[str] = None
ty: Optional[str] = None
autofixCount: Optional[int] = None
ignoreCount: Optional[int] = None
@classmethod
def from_json(cls, x: Any) -> 'Extension':
if isinstance(x, dict):
return cls(
machineId=_atd_read_string(x['machineId']) if 'machineId' in x else None,
isNewAppInstall=_atd_read_bool(x['isNewAppInstall']) if 'isNewAppInstall' in x else None,
sessionId=_atd_read_string(x['sessionId']) if 'sessionId' in x else None,
version=_atd_read_string(x['version']) if 'version' in x else None,
ty=_atd_read_string(x['ty']) if 'ty' in x else None,
autofixCount=_atd_read_int(x['autofixCount']) if 'autofixCount' in x else None,
ignoreCount=_atd_read_int(x['ignoreCount']) if 'ignoreCount' in x else None,
)
else:
_atd_bad_json('Extension', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
if self.machineId is not None:
res['machineId'] = _atd_write_string(self.machineId)
if self.isNewAppInstall is not None:
res['isNewAppInstall'] = _atd_write_bool(self.isNewAppInstall)
if self.sessionId is not None:
res['sessionId'] = _atd_write_string(self.sessionId)
if self.version is not None:
res['version'] = _atd_write_string(self.version)
if self.ty is not None:
res['ty'] = _atd_write_string(self.ty)
if self.autofixCount is not None:
res['autofixCount'] = _atd_write_int(self.autofixCount)
if self.ignoreCount is not None:
res['ignoreCount'] = _atd_write_int(self.ignoreCount)
return res
@classmethod
def from_json_string(cls, x: str) -> 'Extension':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Error:
"""Original type: error"""
value: str
@classmethod
def from_json(cls, x: Any) -> 'Error':
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) -> 'Error':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Errors:
"""Original type: errors = { ... }"""
returnCode: Optional[int] = None
errors: Optional[List[Error]] = None
@classmethod
def from_json(cls, x: Any) -> 'Errors':
if isinstance(x, dict):
return cls(
returnCode=_atd_read_int(x['returnCode']) if 'returnCode' in x else None,
errors=_atd_read_list(Error.from_json)(x['errors']) if 'errors' in x else None,
)
else:
_atd_bad_json('Errors', x)
def to_json(self) -> Any:
res: Dict[str, Any] = {}
if self.returnCode is not None:
res['returnCode'] = _atd_write_int(self.returnCode)
if self.errors is not None:
res['errors'] = _atd_write_list((lambda x: x.to_json()))(self.errors)
return res
@classmethod
def from_json_string(cls, x: str) -> 'Errors':
return cls.from_json(json.loads(x))
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
@dataclass
class Environment:
"""Original type: environment = { ... }"""
version: str
os: str
isTranspiledJS: bool
projectHash: Optional[Sha256]
configNamesHash: Sha256
ci: Optional[str]
rulesHash: Optional[Sha256] = None
isDiffScan: bool = field(default_factory=lambda: False)
integrationName: Optional[str] = None
isAuthenticated: bool = field(default_factory=lambda: False)
deployment_id: Optional[int] = None
@classmethod
def from_json(cls, x: Any) -> 'Environment':
if isinstance(x, dict):
return cls(
version=_atd_read_string(x['version']) if 'version' in x else _atd_missing_json_field('Environment', 'version'),
os=_atd_read_string(x['os']) if 'os' in x else _atd_missing_json_field('Environment', 'os'),
isTranspiledJS=_atd_read_bool(x['isTranspiledJS']) if 'isTranspiledJS' in x else _atd_missing_json_field('Environment', 'isTranspiledJS'),
projectHash=_atd_read_nullable(Sha256.from_json)(x['projectHash']) if 'projectHash' in x else _atd_missing_json_field('Environment', 'projectHash'),
configNamesHash=Sha256.from_json(x['configNamesHash']) if 'configNamesHash' in x else _atd_missing_json_field('Environment', 'configNamesHash'),
ci=_atd_read_nullable(_atd_read_string)(x['ci']) if 'ci' in x else _atd_missing_json_field('Environment', 'ci'),
rulesHash=Sha256.from_json(x['rulesHash']) if 'rulesHash' in x else None,