From 91e516bc0881411c3c8f82ae7667e07f6dc9169d Mon Sep 17 00:00:00 2001 From: Marten Ringwelski Date: Tue, 9 Apr 2024 11:38:38 +0200 Subject: [PATCH] fix(schema): Resolve circular imports in schema Ref: https://github.com/koxudaxi/datamodel-code-generator/issues/836 --- fkie_cve_make_release/schema/__init__.py | 218 ++++------------------- fkie_cve_make_release/schema/cvss_v2.py | 7 +- fkie_cve_make_release/schema/cvss_v3.py | 7 +- fkie_cve_make_release/schema/enums.py | 179 +++++++++++++++++++ fkie_cve_make_release/schema/types.py | 5 + 5 files changed, 228 insertions(+), 188 deletions(-) create mode 100644 fkie_cve_make_release/schema/enums.py create mode 100644 fkie_cve_make_release/schema/types.py diff --git a/fkie_cve_make_release/schema/__init__.py b/fkie_cve_make_release/schema/__init__.py index 7e776ba..2857834 100644 --- a/fkie_cve_make_release/schema/__init__.py +++ b/fkie_cve_make_release/schema/__init__.py @@ -12,185 +12,40 @@ from . import cvss_v2, cvss_v3 - -class Type(Enum): - primary = 'Primary' - secondary = 'Secondary' - - -class AccessVectorType(Enum): - network = 'NETWORK' - adjacent_network = 'ADJACENT_NETWORK' - local = 'LOCAL' - - -class AccessComplexityType(Enum): - high = 'HIGH' - medium = 'MEDIUM' - low = 'LOW' - - -class AuthenticationType(Enum): - multiple = 'MULTIPLE' - single = 'SINGLE' - none = 'NONE' - - -class CiaType(Enum): - none = 'NONE' - partial = 'PARTIAL' - complete = 'COMPLETE' - - -class ExploitabilityType(Enum): - unproven = 'UNPROVEN' - proof_of_concept = 'PROOF_OF_CONCEPT' - functional = 'FUNCTIONAL' - high = 'HIGH' - not_defined = 'NOT_DEFINED' - - -class RemediationLevelType(Enum): - official_fix = 'OFFICIAL_FIX' - temporary_fix = 'TEMPORARY_FIX' - workaround = 'WORKAROUND' - unavailable = 'UNAVAILABLE' - not_defined = 'NOT_DEFINED' - - -class ReportConfidenceType(Enum): - unconfirmed = 'UNCONFIRMED' - uncorroborated = 'UNCORROBORATED' - confirmed = 'CONFIRMED' - not_defined = 'NOT_DEFINED' - - -class CollateralDamagePotentialType(Enum): - none = 'NONE' - low = 'LOW' - low_medium = 'LOW_MEDIUM' - medium_high = 'MEDIUM_HIGH' - high = 'HIGH' - not_defined = 'NOT_DEFINED' - - -class TargetDistributionType(Enum): - none = 'NONE' - low = 'LOW' - medium = 'MEDIUM' - high = 'HIGH' - not_defined = 'NOT_DEFINED' - - -class CiaRequirementType(Enum): - low = 'LOW' - medium = 'MEDIUM' - high = 'HIGH' - not_defined = 'NOT_DEFINED' - - -ScoreType = Annotated[float, Meta(ge=0.0, le=10.0)] - - -class AttackVectorType(Enum): - network = 'NETWORK' - adjacent_network = 'ADJACENT_NETWORK' - local = 'LOCAL' - physical = 'PHYSICAL' - - -class ModifiedAttackVectorType(Enum): - network = 'NETWORK' - adjacent_network = 'ADJACENT_NETWORK' - local = 'LOCAL' - physical = 'PHYSICAL' - not_defined = 'NOT_DEFINED' - - -class AttackComplexityType(Enum): - high = 'HIGH' - low = 'LOW' - - -class ModifiedAttackComplexityType(Enum): - high = 'HIGH' - low = 'LOW' - not_defined = 'NOT_DEFINED' - - -class PrivilegesRequiredType(Enum): - high = 'HIGH' - low = 'LOW' - none = 'NONE' - - -class ModifiedPrivilegesRequiredType(Enum): - high = 'HIGH' - low = 'LOW' - none = 'NONE' - not_defined = 'NOT_DEFINED' - - -class UserInteractionType(Enum): - none = 'NONE' - required = 'REQUIRED' - - -class ModifiedUserInteractionType(Enum): - none = 'NONE' - required = 'REQUIRED' - not_defined = 'NOT_DEFINED' - - -class ScopeType(Enum): - unchanged = 'UNCHANGED' - changed = 'CHANGED' - - -class ModifiedScopeType(Enum): - unchanged = 'UNCHANGED' - changed = 'CHANGED' - not_defined = 'NOT_DEFINED' - - -class CiaTypeModel(Enum): - none = 'NONE' - low = 'LOW' - high = 'HIGH' - - -class ModifiedCiaType(Enum): - none = 'NONE' - low = 'LOW' - high = 'HIGH' - not_defined = 'NOT_DEFINED' - - -class ExploitCodeMaturityType(Enum): - unproven = 'UNPROVEN' - proof_of_concept = 'PROOF_OF_CONCEPT' - functional = 'FUNCTIONAL' - high = 'HIGH' - not_defined = 'NOT_DEFINED' - - -class ConfidenceType(Enum): - unknown = 'UNKNOWN' - reasonable = 'REASONABLE' - confirmed = 'CONFIRMED' - not_defined = 'NOT_DEFINED' - - -class SeverityType(Enum): - none = 'NONE' - low = 'LOW' - medium = 'MEDIUM' - high = 'HIGH' - critical = 'CRITICAL' - - -CveId = Annotated[str, Meta(pattern='^CVE-[0-9]{4}-[0-9]{4,}$')] - +from .enums import ( + AccessComplexityType, + AccessVectorType, + AttackComplexityType, + AttackVectorType, + AuthenticationType, + CiaRequirementType, + CiaType, + CiaTypeModel, + CollateralDamagePotentialType, + ConfidenceType, + ExploitabilityType, + ExploitCodeMaturityType, + ModifiedAttackComplexityType, + ModifiedAttackVectorType, + ModifiedCiaType, + ModifiedPrivilegesRequiredType, + ModifiedScopeType, + ModifiedUserInteractionType, + Operator, + PrivilegesRequiredType, + RemediationLevelType, + ReportConfidenceType, + ScopeType, + SeverityType, + TargetDistributionType, + Type, + UserInteractionType, +) + +from .types import ( + CveId, + ScoreType, +) class LangString(Struct): lang: str @@ -215,11 +70,6 @@ class Weakness(Struct): description: List[LangString] -class Operator(Enum): - and_ = 'AND' - or_ = 'OR' - - class CpeMatch(Struct): vulnerable: bool criteria: str diff --git a/fkie_cve_make_release/schema/cvss_v2.py b/fkie_cve_make_release/schema/cvss_v2.py index ca47c7b..f96fe81 100644 --- a/fkie_cve_make_release/schema/cvss_v2.py +++ b/fkie_cve_make_release/schema/cvss_v2.py @@ -10,7 +10,7 @@ from msgspec import Meta, Struct, field from typing_extensions import Annotated -from . import ( +from .enums import ( AccessComplexityType, AccessVectorType, AuthenticationType, @@ -20,10 +20,13 @@ ExploitabilityType, RemediationLevelType, ReportConfidenceType, - ScoreType, TargetDistributionType, ) +from .types import ( + ScoreType, +) + class Version(Enum): field_2_0 = '2.0' diff --git a/fkie_cve_make_release/schema/cvss_v3.py b/fkie_cve_make_release/schema/cvss_v3.py index 3e8508e..6609a2d 100644 --- a/fkie_cve_make_release/schema/cvss_v3.py +++ b/fkie_cve_make_release/schema/cvss_v3.py @@ -10,7 +10,7 @@ from msgspec import Meta, Struct, field from typing_extensions import Annotated -from . import ( +from .enums import ( AttackComplexityType, AttackVectorType, CiaRequirementType, @@ -26,11 +26,14 @@ PrivilegesRequiredType, RemediationLevelType, ScopeType, - ScoreType, SeverityType, UserInteractionType, ) +from .types import ( + ScoreType, +) + class Version(Enum): field_3_0 = '3.0' diff --git a/fkie_cve_make_release/schema/enums.py b/fkie_cve_make_release/schema/enums.py new file mode 100644 index 0000000..517db87 --- /dev/null +++ b/fkie_cve_make_release/schema/enums.py @@ -0,0 +1,179 @@ +from enum import Enum + + +class Type(Enum): + primary = 'Primary' + secondary = 'Secondary' + + +class AccessVectorType(Enum): + network = 'NETWORK' + adjacent_network = 'ADJACENT_NETWORK' + local = 'LOCAL' + + +class AccessComplexityType(Enum): + high = 'HIGH' + medium = 'MEDIUM' + low = 'LOW' + + +class AuthenticationType(Enum): + multiple = 'MULTIPLE' + single = 'SINGLE' + none = 'NONE' + + +class CiaType(Enum): + none = 'NONE' + partial = 'PARTIAL' + complete = 'COMPLETE' + + +class ExploitabilityType(Enum): + unproven = 'UNPROVEN' + proof_of_concept = 'PROOF_OF_CONCEPT' + functional = 'FUNCTIONAL' + high = 'HIGH' + not_defined = 'NOT_DEFINED' + + +class RemediationLevelType(Enum): + official_fix = 'OFFICIAL_FIX' + temporary_fix = 'TEMPORARY_FIX' + workaround = 'WORKAROUND' + unavailable = 'UNAVAILABLE' + not_defined = 'NOT_DEFINED' + + +class ReportConfidenceType(Enum): + unconfirmed = 'UNCONFIRMED' + uncorroborated = 'UNCORROBORATED' + confirmed = 'CONFIRMED' + not_defined = 'NOT_DEFINED' + + +class CollateralDamagePotentialType(Enum): + none = 'NONE' + low = 'LOW' + low_medium = 'LOW_MEDIUM' + medium_high = 'MEDIUM_HIGH' + high = 'HIGH' + not_defined = 'NOT_DEFINED' + + +class TargetDistributionType(Enum): + none = 'NONE' + low = 'LOW' + medium = 'MEDIUM' + high = 'HIGH' + not_defined = 'NOT_DEFINED' + + +class CiaRequirementType(Enum): + low = 'LOW' + medium = 'MEDIUM' + high = 'HIGH' + not_defined = 'NOT_DEFINED' + + +class AttackVectorType(Enum): + network = 'NETWORK' + adjacent_network = 'ADJACENT_NETWORK' + local = 'LOCAL' + physical = 'PHYSICAL' + + +class ModifiedAttackVectorType(Enum): + network = 'NETWORK' + adjacent_network = 'ADJACENT_NETWORK' + local = 'LOCAL' + physical = 'PHYSICAL' + not_defined = 'NOT_DEFINED' + + +class AttackComplexityType(Enum): + high = 'HIGH' + low = 'LOW' + + +class ModifiedAttackComplexityType(Enum): + high = 'HIGH' + low = 'LOW' + not_defined = 'NOT_DEFINED' + + +class PrivilegesRequiredType(Enum): + high = 'HIGH' + low = 'LOW' + none = 'NONE' + + +class ModifiedPrivilegesRequiredType(Enum): + high = 'HIGH' + low = 'LOW' + none = 'NONE' + not_defined = 'NOT_DEFINED' + + +class UserInteractionType(Enum): + none = 'NONE' + required = 'REQUIRED' + + +class ModifiedUserInteractionType(Enum): + none = 'NONE' + required = 'REQUIRED' + not_defined = 'NOT_DEFINED' + + +class ScopeType(Enum): + unchanged = 'UNCHANGED' + changed = 'CHANGED' + + +class ModifiedScopeType(Enum): + unchanged = 'UNCHANGED' + changed = 'CHANGED' + not_defined = 'NOT_DEFINED' + + +class CiaTypeModel(Enum): + none = 'NONE' + low = 'LOW' + high = 'HIGH' + + +class ModifiedCiaType(Enum): + none = 'NONE' + low = 'LOW' + high = 'HIGH' + not_defined = 'NOT_DEFINED' + + +class ExploitCodeMaturityType(Enum): + unproven = 'UNPROVEN' + proof_of_concept = 'PROOF_OF_CONCEPT' + functional = 'FUNCTIONAL' + high = 'HIGH' + not_defined = 'NOT_DEFINED' + + +class ConfidenceType(Enum): + unknown = 'UNKNOWN' + reasonable = 'REASONABLE' + confirmed = 'CONFIRMED' + not_defined = 'NOT_DEFINED' + + +class SeverityType(Enum): + none = 'NONE' + low = 'LOW' + medium = 'MEDIUM' + high = 'HIGH' + critical = 'CRITICAL' + + +class Operator(Enum): + and_ = 'AND' + or_ = 'OR' diff --git a/fkie_cve_make_release/schema/types.py b/fkie_cve_make_release/schema/types.py new file mode 100644 index 0000000..6091e75 --- /dev/null +++ b/fkie_cve_make_release/schema/types.py @@ -0,0 +1,5 @@ +from msgspec import Meta +from typing_extensions import Annotated + +ScoreType = Annotated[float, Meta(ge=0.0, le=10.0)] +CveId = Annotated[str, Meta(pattern='^CVE-[0-9]{4}-[0-9]{4,}$')]