Coverage for spdx_lint/lint.py: 84.62%
16 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 22:24:03 +00:00
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 22:24:03 +00:00
1from typing import no_type_check
3SPDX_2_2_DCI_TV = {
4 'SPDXVersion': 'SPDX-2.2',
5 'DataLicense': 'CC0-1.0',
6 'SPDXID': 'SPDXRef-DOCUMENT',
7 'DocumentName': '$_SINGLE_LINE',
8 'DocumentNamespace': '$_URI_MINUS_PART',
9 '[ExternalDocumentRef]': [
10 'DocumentRef-$_IDSTRING $_SPDX_DOCUMENT_URI $_PREFIX_COLON_CHECKSUM',
11 ],
12 '[LicenseListVersion]': '$_MAJOR.$_MINOR',
13 'Creator': [
14 'Person: $_PERSON_NAME [($_EMAIL)]',
15 'Organization: $_ORGANIZATION [($_EMAIL)]',
16 'Tool: $_TOOL_IDENTIFIED-$_VERSION',
17 ],
18 'Created': '%Y-%m-%dT%H:%M:%SZ',
19 '[CreatorComment]': '<text>$_MULTI_LINE_TEXT</text>',
20 '[DocumentComment]': '<text>$_MULTI_LINE_TEXT</text>',
21}
23SPDX_2_2_DCI_JSON = { # Reversed engineered from round trip conversion - TODO(sthagen) later use json schema
24 'SPDXID': 'SPDXRef-DOCUMENT',
25 'spdxVersion': 'SPDX-2.2',
26 'creationInfo': {
27 'created': '%Y-%m-%dT%H:%M:%SZ',
28 'creators': [
29 'Person: $_PERSON_NAME [($_EMAIL)]',
30 'Organization: $_ORGANIZATION [($_EMAIL)]',
31 'Tool: $_TOOL_IDENTIFIED-$_VERSION',
32 ],
33 },
34 'name': '$_SINGLE_LINE',
35 'dataLicense': 'CC0-1.0',
36 'documentNamespace': '$_URI_MINUS_PART',
37}
40@no_type_check
41def spdx_dci_is_valid(sbom):
42 """Shallow key level validation for DCI part of SPDX documents."""
43 if not sbom:
44 return False
45 for key in SPDX_2_2_DCI_JSON.keys():
46 if key.startswith('['): 46 ↛ 47line 46 didn't jump to line 47, because the condition on line 46 was never true
47 continue
48 try:
49 if not sbom.get(key):
50 return False
51 except AttributeError as e:
52 print(str(sbom), e) # TODO(sthagen) when I am a grown up, I want to really log
54 return True