Repository navigation
Expand file tree
/
Copy path_types.py
More file actions
285 lines (199 loc) · 6.62 KB
/
Copy path_types.py
File metadata and controls
285 lines (199 loc) · 6.62 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
"""The CycloneDX 1.6 types python-sbom writes, as typed dictionaries."""
from __future__ import annotations
from typing import NotRequired, TypedDict
# the document model is our own: cyclonedx-python-lib models neither formulation nor compositions (its model/bom.py
# holds only commented-out stubs, tracked upstream in CycloneDX/cyclonedx-python-lib#578 and #581), and its SortedSet
# collections re-order lists whose order the document keeps on purpose
class OrganizationalEntity(TypedDict):
"""
An organization that supplies or makes a component.
:ivar name: the organization's name
:ivar url: the organization's web sites
"""
name: str
url: list[str]
class Contact(TypedDict):
"""
A person who wrote or maintains a component.
:ivar name: the person's name
:ivar email: the person's email address
"""
name: NotRequired[str]
email: NotRequired[str]
class Hash(TypedDict):
"""
A digest of a component's bytes.
:ivar alg: the algorithm as CycloneDX names it, such as ``SHA-256``
:ivar content: the digest as lowercase hex
"""
alg: str
content: str
class Property(TypedDict):
"""
A name and value pair attached to a component or the document.
:ivar name: the property's name; names this package writes start with the project's prefix or ``python:``
:ivar value: the property's value
"""
name: str
value: str
class ExternalReference(TypedDict):
"""
A link from a component to something about it.
:ivar type: the CycloneDX reference type, such as ``vcs`` or ``website``
:ivar url: the link
:ivar comment: what the link is, such as the Project-URL label it came from
:ivar hashes: digests of what the link points at
"""
type: str
url: str
comment: NotRequired[str]
hashes: NotRequired[list[Hash]]
class LicenseInfo(TypedDict):
"""
One license, by SPDX id or by name.
:ivar id: the SPDX license id
:ivar name: the license's name, when it has no SPDX id
:ivar acknowledgement: ``declared`` when the metadata names it, ``concluded`` when python-sbom resolved it
"""
id: NotRequired[str]
name: NotRequired[str]
acknowledgement: str
class License(TypedDict):
"""
One license entry of a component: a license or an SPDX expression.
:ivar license: the license, by SPDX id or by name
:ivar expression: an SPDX license expression
:ivar acknowledgement: ``declared`` or ``concluded``, for an expression
"""
license: NotRequired[LicenseInfo]
expression: NotRequired[str]
acknowledgement: NotRequired[str]
class IdentityMethod(TypedDict):
"""
How a component's identity was established.
:ivar technique: the CycloneDX technique, such as ``manifest-analysis`` or ``hash-comparison``
:ivar confidence: from 0 to 1
:ivar value: what the technique read, such as the path of a ``METADATA`` file or a digest
"""
technique: str
confidence: int
value: str
class Identity(TypedDict):
"""
The evidence for one field of a component's identity.
:ivar field: the field it supports, such as ``purl`` or ``hash``
:ivar confidence: from 0 to 1
:ivar methods: how it was established
"""
field: str
confidence: int
methods: list[IdentityMethod]
class Evidence(TypedDict):
"""
Why a component is what it says it is.
:ivar identity: the evidence per field
"""
identity: list[Identity]
#: A CycloneDX 1.6 component: a distribution, an application, the interpreter or a file, as a dictionary with the keys
#: the CycloneDX component object defines, of which python-sbom uses ``type``, ``bom-ref``, ``name``, ``version``,
#: ``purl``, ``supplier``, ``authors``, ``description``, ``licenses``, ``copyright``, ``hashes``,
#: ``externalReferences``, ``properties``, ``evidence`` and the nested ``components``.
Component = TypedDict(
"Component",
{
"type": str,
"bom-ref": str,
"name": str,
"version": NotRequired[str],
"purl": NotRequired[str],
"supplier": NotRequired[OrganizationalEntity],
"authors": NotRequired[list[Contact]],
"description": NotRequired[str],
"licenses": NotRequired[list[License]],
"copyright": NotRequired[str],
"hashes": NotRequired[list[Hash]],
"externalReferences": NotRequired[list[ExternalReference]],
"properties": NotRequired[list[Property]],
"evidence": NotRequired[Evidence],
"components": NotRequired[list["Component"]],
},
)
class Dependency(TypedDict):
"""
The components one component depends on.
:ivar ref: the ``bom-ref`` of the dependent component
:ivar dependsOn: the ``bom-ref`` values of its dependencies
"""
ref: str
dependsOn: NotRequired[list[str]]
class _Reference(TypedDict):
ref: str
class _Output(TypedDict):
type: str
resource: _Reference
class _Input(TypedDict):
environmentVars: list[Property]
_Workflow = TypedDict(
"_Workflow",
{
"bom-ref": str,
"uid": str,
"name": str,
"taskTypes": list[str],
"resourceReferences": list[_Reference],
"outputs": list[_Output],
"inputs": NotRequired[list[_Input]],
},
)
#: How an artifact was built: one or more workflows, each with its tools, inputs and outputs.
Formula = TypedDict("Formula", {"bom-ref": str, "workflows": list[_Workflow]})
class Lifecycle(TypedDict):
phase: str
class Tools(TypedDict):
components: list[Component]
class Metadata(TypedDict):
timestamp: str
lifecycles: list[Lifecycle]
tools: Tools
manufacturer: NotRequired[OrganizationalEntity]
authors: NotRequired[list[Contact]]
supplier: NotRequired[OrganizationalEntity]
component: Component
licenses: NotRequired[list[License]]
properties: NotRequired[list[Property]]
class Composition(TypedDict):
aggregate: str
dependencies: list[str]
class Body(TypedDict):
metadata: Metadata
components: list[Component]
dependencies: list[Dependency]
compositions: NotRequired[list[Composition]]
formulation: NotRequired[list[Formula]]
_Header = TypedDict(
"_Header",
{"$schema": str, "bomFormat": str, "specVersion": str, "serialNumber": str, "version": int},
)
class Document(Body, _Header):
pass
__all__ = [
"Body",
"Component",
"Composition",
"Contact",
"Dependency",
"Document",
"Evidence",
"ExternalReference",
"Formula",
"Hash",
"Identity",
"IdentityMethod",
"License",
"LicenseInfo",
"Lifecycle",
"Metadata",
"OrganizationalEntity",
"Property",
"Tools",
]