hoppr-cyclonedx-models 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Lockheed Martin Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.4
2
+ Name: hoppr-cyclonedx-models
3
+ Version: 0.7.0
4
+ Summary: CycloneDX Pydantic models for easy use in your Python project.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: pydantic,models,cyclonedx,software bill of materials
8
+ Author: LMCO Open Source
9
+ Author-email: open.source@lmco.com
10
+ Requires-Python: >=3.8.0,<4.0.0
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Framework :: Pydantic
13
+ Classifier: Framework :: Pytest
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Topic :: Software Development :: Code Generators
25
+ Classifier: Typing :: Typed
26
+ Requires-Dist: pydantic[email] (>=1.10.2,<2.0.0)
27
+ Requires-Dist: typing-extensions (>=4.7.1,<5.0.0)
28
+ Project-URL: Repository, https://gitlab.com/hoppr/hoppr-cyclonedx-models
29
+ Description-Content-Type: text/markdown
30
+
31
+ # Hoppr CycloneDX Models
32
+
33
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/hoppr-cyclonedx-models?logo=python&style=plastic)
34
+ [![PyPI - Version](https://img.shields.io/pypi/v/hoppr-cyclonedx-models?style=plastic)](https://pypi.org/project/hoppr-cyclonedx-models)
35
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/hoppr-cyclonedx-models?style=plastic)](https://pypi.org/project/hoppr-cyclonedx-models)
36
+ [![PyPI - License](https://img.shields.io/pypi/l/hoppr-cyclonedx-models?style=plastic)](LICENSE)
37
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json&style=plastic)](https://python-poetry.org/)
38
+
39
+ Serializable CycloneDX Models. Quickly get up and running with models generated directly off the specification.
40
+
41
+ Current generated models can be found [here](hoppr_cyclonedx_models).
42
+
43
+ ## Installation
44
+
45
+ Install using `pip install --upgrade hoppr-cyclonedx-models` or `poetry add hoppr-cyclonedx-models`.
46
+
47
+ ## A Simple Example
48
+
49
+ ```python
50
+ >>> from hoppr_cyclonedx_models.cyclonedx_1_5 import Component
51
+ >>> data = {"type": "library", "purl": "pkg:pypi/django@1.11.1", "name": "django", "version": "1.11.1"}
52
+ >>> component = Component(**data)
53
+ >>> component
54
+ >>> print(component)
55
+ Component(
56
+ type='library',
57
+ mime_type=None,
58
+ bom_ref=None,
59
+ supplier=None,
60
+ author=None,
61
+ publisher=None,
62
+ group=None,
63
+ name='django',
64
+ version='1.11.1',
65
+ description=None,
66
+ scope=<Scope.REQUIRED: 'required'>,
67
+ hashes=None,
68
+ licenses=None,
69
+ copyright=None,
70
+ cpe=None,
71
+ purl='pkg:pypi/django@1.11.1',
72
+ swid=None,
73
+ modified=None,
74
+ pedigree=None,
75
+ externalReferences=None,
76
+ components=None,
77
+ evidence=None,
78
+ releaseNotes=None,
79
+ modelCard=None,
80
+ data=None,
81
+ properties=None,
82
+ signature=None
83
+ )
84
+ ```
85
+
86
+ ## Contributing
87
+
88
+ For guidance setting up a development environment and how to contribute to `hoppr-cyclonedx-models`,
89
+ see [Contributing to Hoppr](https://hoppr.dev/docs/development/contributing).
90
+
@@ -0,0 +1,59 @@
1
+ # Hoppr CycloneDX Models
2
+
3
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/hoppr-cyclonedx-models?logo=python&style=plastic)
4
+ [![PyPI - Version](https://img.shields.io/pypi/v/hoppr-cyclonedx-models?style=plastic)](https://pypi.org/project/hoppr-cyclonedx-models)
5
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/hoppr-cyclonedx-models?style=plastic)](https://pypi.org/project/hoppr-cyclonedx-models)
6
+ [![PyPI - License](https://img.shields.io/pypi/l/hoppr-cyclonedx-models?style=plastic)](LICENSE)
7
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json&style=plastic)](https://python-poetry.org/)
8
+
9
+ Serializable CycloneDX Models. Quickly get up and running with models generated directly off the specification.
10
+
11
+ Current generated models can be found [here](hoppr_cyclonedx_models).
12
+
13
+ ## Installation
14
+
15
+ Install using `pip install --upgrade hoppr-cyclonedx-models` or `poetry add hoppr-cyclonedx-models`.
16
+
17
+ ## A Simple Example
18
+
19
+ ```python
20
+ >>> from hoppr_cyclonedx_models.cyclonedx_1_5 import Component
21
+ >>> data = {"type": "library", "purl": "pkg:pypi/django@1.11.1", "name": "django", "version": "1.11.1"}
22
+ >>> component = Component(**data)
23
+ >>> component
24
+ >>> print(component)
25
+ Component(
26
+ type='library',
27
+ mime_type=None,
28
+ bom_ref=None,
29
+ supplier=None,
30
+ author=None,
31
+ publisher=None,
32
+ group=None,
33
+ name='django',
34
+ version='1.11.1',
35
+ description=None,
36
+ scope=<Scope.REQUIRED: 'required'>,
37
+ hashes=None,
38
+ licenses=None,
39
+ copyright=None,
40
+ cpe=None,
41
+ purl='pkg:pypi/django@1.11.1',
42
+ swid=None,
43
+ modified=None,
44
+ pedigree=None,
45
+ externalReferences=None,
46
+ components=None,
47
+ evidence=None,
48
+ releaseNotes=None,
49
+ modelCard=None,
50
+ data=None,
51
+ properties=None,
52
+ signature=None
53
+ )
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ For guidance setting up a development environment and how to contribute to `hoppr-cyclonedx-models`,
59
+ see [Contributing to Hoppr](https://hoppr.dev/docs/development/contributing).
@@ -0,0 +1,84 @@
1
+ """
2
+ Hoppr package to generate Pydantic models for CycloneDX schema
3
+
4
+ --------------------------------------------------------------------------------
5
+ SPDX-FileCopyrightText: Copyright © 2023 Lockheed Martin <open.source@lmco.com>
6
+ SPDX-FileName: hoppr_cyclonedx_models/__init__.py
7
+ SPDX-FileType: SOURCE
8
+ SPDX-License-Identifier: MIT
9
+ --------------------------------------------------------------------------------
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ THE SOFTWARE.
27
+ --------------------------------------------------------------------------------
28
+ """
29
+ from __future__ import annotations
30
+
31
+ from typing import Any
32
+
33
+ from pydantic import Extra, Field, root_validator
34
+ from typing_extensions import Annotated, Literal
35
+
36
+ from hoppr_cyclonedx_models.base import CycloneDXBaseModel
37
+ from hoppr_cyclonedx_models.cyclonedx_1_3 import CyclonedxSoftwareBillOfMaterialSpecification as Sbom_1_3
38
+ from hoppr_cyclonedx_models.cyclonedx_1_4 import CyclonedxSoftwareBillOfMaterialsStandard as Sbom_1_4
39
+ from hoppr_cyclonedx_models.cyclonedx_1_5 import CyclonedxSoftwareBillOfMaterialsStandard as Sbom_1_5
40
+
41
+
42
+ class Sbom(Sbom_1_5, Sbom_1_4, Sbom_1_3): # pylint: disable=too-few-public-methods
43
+ """
44
+ Convenience class to parse SBOM as latest spec version
45
+ """
46
+
47
+ class Config(CycloneDXBaseModel.Config):
48
+ """
49
+ Config options for Sbom
50
+ """
51
+
52
+ extra = Extra.forbid
53
+
54
+ field_schema: Annotated[
55
+ Literal[
56
+ "http://cyclonedx.org/schema/bom-1.3.schema.json",
57
+ "http://cyclonedx.org/schema/bom-1.4.schema.json",
58
+ "http://cyclonedx.org/schema/bom-1.5.schema.json",
59
+ ],
60
+ Field(alias="$schema"),
61
+ ] = "http://cyclonedx.org/schema/bom-1.5.schema.json"
62
+
63
+ specVersion: Annotated[
64
+ Literal["1.3", "1.4", "1.5"],
65
+ Field(
66
+ description="The version of the CycloneDX specification a BOM conforms to (starting at version 1.2).",
67
+ examples=["1.3", "1.4", "1.5"],
68
+ title="CycloneDX Specification Version",
69
+ ),
70
+ ] = "1.5"
71
+
72
+ @root_validator(allow_reuse=True, pre=True)
73
+ @classmethod
74
+ def validate_sbom(cls, sbom: dict[str, Any]) -> dict[str, Any]:
75
+ """
76
+ Parse SBOM as latest CycloneDX spec release
77
+ """
78
+ sbom["$schema"] = "http://cyclonedx.org/schema/bom-1.5.schema.json"
79
+ sbom["specVersion"] = "1.5"
80
+
81
+ return Sbom_1_5(**sbom).dict(exclude_none=True, exclude_unset=True)
82
+
83
+
84
+ __version__ = "0.7.0"
@@ -0,0 +1,111 @@
1
+ """
2
+ Override Pydantic's BaseModel class to ensure hashable model objects
3
+
4
+ --------------------------------------------------------------------------------
5
+ SPDX-FileCopyrightText: Copyright © 2023 Lockheed Martin <open.source@lmco.com>
6
+ SPDX-FileName: hoppr_cyclonedx_models/base.py
7
+ SPDX-FileType: SOURCE
8
+ SPDX-License-Identifier: MIT
9
+ --------------------------------------------------------------------------------
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ THE SOFTWARE.
27
+ --------------------------------------------------------------------------------
28
+ """
29
+ from __future__ import annotations
30
+
31
+ from typing import TYPE_CHECKING, Any, Callable
32
+
33
+ from pydantic import BaseConfig, BaseModel, Extra
34
+
35
+ if TYPE_CHECKING:
36
+ from pydantic.typing import AbstractSetIntStr, DictStrAny, MappingIntStrAny
37
+
38
+
39
+ class CycloneDXBaseModel(BaseModel):
40
+ """
41
+ Hoppr CycloneDX base data model
42
+ """
43
+
44
+ class Config(BaseConfig):
45
+ """
46
+ Config options for CycloneDXBaseModel
47
+ """
48
+
49
+ allow_population_by_field_name = True
50
+ arbitrary_types_allowed = True
51
+ extra = Extra.allow
52
+ use_enum_values = True
53
+
54
+ def __eq__(self, other: object) -> bool:
55
+ return hash(self) == hash(other)
56
+
57
+ def __hash__(self) -> int:
58
+ """
59
+ Define to test equality or uniqueness between objects
60
+ """
61
+ return hash(repr(self))
62
+
63
+ # Override to export by alias by default
64
+ def dict(
65
+ self,
66
+ *,
67
+ include: AbstractSetIntStr | MappingIntStrAny | None = None,
68
+ exclude: AbstractSetIntStr | MappingIntStrAny | None = None,
69
+ by_alias: bool = True,
70
+ skip_defaults: bool | None = None,
71
+ exclude_unset: bool = False,
72
+ exclude_defaults: bool = False,
73
+ exclude_none: bool = False,
74
+ ) -> DictStrAny:
75
+ return super().dict(
76
+ include=include,
77
+ exclude=exclude,
78
+ by_alias=by_alias,
79
+ skip_defaults=skip_defaults,
80
+ exclude_unset=exclude_unset,
81
+ exclude_defaults=exclude_defaults,
82
+ exclude_none=exclude_none,
83
+ )
84
+
85
+ # Override to export by alias and exclude fields that are None or unset by default
86
+ def json(
87
+ self,
88
+ *,
89
+ include: AbstractSetIntStr | MappingIntStrAny | None = None,
90
+ exclude: AbstractSetIntStr | MappingIntStrAny | None = None,
91
+ by_alias: bool = True,
92
+ skip_defaults: bool | None = None,
93
+ exclude_unset: bool = True,
94
+ exclude_defaults: bool = False,
95
+ exclude_none: bool = True,
96
+ encoder: Callable[[Any], Any] | None = None,
97
+ models_as_dict: bool = True,
98
+ **dumps_kwargs: Any,
99
+ ) -> str:
100
+ return super().json(
101
+ include=include,
102
+ exclude=exclude,
103
+ by_alias=by_alias,
104
+ skip_defaults=skip_defaults,
105
+ exclude_unset=exclude_unset,
106
+ exclude_defaults=exclude_defaults,
107
+ exclude_none=exclude_none,
108
+ encoder=encoder,
109
+ models_as_dict=models_as_dict,
110
+ **dumps_kwargs,
111
+ )