Skip to content

Commit

Permalink
Remove deprecated 6.0.0 (#493)
Browse files Browse the repository at this point in the history
* bc: remove deprecated functionality

Signed-off-by: Jan Kowalleck <[email protected]>

* tests: remove unused/outdated tests

Signed-off-by: Jan Kowalleck <[email protected]>

---------

Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck authored Nov 28, 2023
1 parent cb0d5b6 commit e9cc5ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 126 deletions.
41 changes: 5 additions & 36 deletions cyclonedx/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.

import warnings

from enum import Enum
from os.path import exists
from typing import Any, Iterable, Optional, Set, Union
Expand Down Expand Up @@ -51,7 +51,7 @@
from .bom_ref import BomRef
from .dependency import Dependable
from .issue import IssueType
from .license import License, LicenseExpression, LicenseRepository
from .license import License, LicenseRepository
from .release_note import ReleaseNotes


Expand Down Expand Up @@ -789,7 +789,8 @@ def for_file(absolute_file_path: str, path_for_bom: Optional[str]) -> 'Component
)
)

def __init__(self, *, name: str, type: ComponentType = ComponentType.LIBRARY,
def __init__(self, *,
name: str, type: ComponentType = ComponentType.LIBRARY,
mime_type: Optional[str] = None, bom_ref: Optional[Union[str, BomRef]] = None,
supplier: Optional[OrganizationalEntity] = None, author: Optional[str] = None,
publisher: Optional[str] = None, group: Optional[str] = None, version: Optional[str] = None,
Expand All @@ -800,9 +801,7 @@ def __init__(self, *, name: str, type: ComponentType = ComponentType.LIBRARY,
properties: Optional[Iterable[Property]] = None, release_notes: Optional[ReleaseNotes] = None,
cpe: Optional[str] = None, swid: Optional[Swid] = None, pedigree: Optional[Pedigree] = None,
components: Optional[Iterable['Component']] = None, evidence: Optional[ComponentEvidence] = None,
modified: bool = False,
# Deprecated parameters kept for backwards compatibility
namespace: Optional[str] = None, license_str: Optional[str] = None
modified: bool = False
) -> None:
self.type = type
self.mime_type = mime_type
Expand Down Expand Up @@ -832,24 +831,6 @@ def __init__(self, *, name: str, type: ComponentType = ComponentType.LIBRARY,
self.evidence = evidence
self.release_notes = release_notes

# Deprecated for 1.4, but kept for some backwards compatibility
if namespace:
warnings.warn(
'`namespace` is deprecated and has been replaced with `group` to align with the CycloneDX standard',
category=DeprecationWarning, stacklevel=1
)
if not group:
self.group = namespace

if license_str:
warnings.warn(
'`license_str` is deprecated and has been'
' replaced with `licenses` to align with the CycloneDX standard',
category=DeprecationWarning, stacklevel=1
)
if not licenses:
self.licenses = LicenseRepository([LicenseExpression(license_str)])

@property
@serializable.xml_attribute()
def type(self) -> ComponentType:
Expand Down Expand Up @@ -1344,15 +1325,3 @@ def __hash__(self) -> int:
def __repr__(self) -> str:
return f'<Component bom-ref={self.bom_ref}, group={self.group}, name={self.name}, ' \
f'version={self.version}, type={self.type}>'

# Deprecated methods
def get_namespace(self) -> Optional[str]:
"""
Get the namespace of this Component.
Returns:
Declared namespace of this Component as `str` if declared, else `None`.
"""
warnings.warn('`Component.get_namespace()` is deprecated - use `Component.group`',
category=DeprecationWarning, stacklevel=1)
return self._group
40 changes: 9 additions & 31 deletions cyclonedx/model/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.


import re
import warnings
from datetime import datetime
from decimal import Decimal
from enum import Enum
Expand Down Expand Up @@ -634,12 +634,12 @@ class VulnerabilityRating:
they are redundant if you have the vector (the vector allows you to calculate the scores).
"""

def __init__(self, *, source: Optional[VulnerabilitySource] = None, score: Optional[Decimal] = None,
def __init__(self, *,
source: Optional[VulnerabilitySource] = None, score: Optional[Decimal] = None,
severity: Optional[VulnerabilitySeverity] = None,
method: Optional[VulnerabilityScoreSource] = None, vector: Optional[str] = None,
justification: Optional[str] = None,
# Deprecated parameters follow that are left to aid backwards compatability
score_base: Optional[float] = None) -> None:
justification: Optional[str] = None
) -> None:
if not source and not score and not severity and not method and not vector and not justification:
raise NoPropertiesProvidedException(
'At least one property must be provided when creating a VulnerabilityRating - none supplied.'
Expand All @@ -652,15 +652,6 @@ def __init__(self, *, source: Optional[VulnerabilitySource] = None, score: Optio
self.vector = vector
self.justification = justification

if score_base:
warnings.warn('`score_base` is deprecated - use `score`',
category=DeprecationWarning, stacklevel=1)
if score:
warnings.warn('Both `score` and `score_base` supplied - the deprecated `score_base` will be discarded',
category=DeprecationWarning, stacklevel=1)
else:
self.score = Decimal(score_base)

if vector and method:
self.vector = method.get_localised_vector(vector=vector)

Expand Down Expand Up @@ -842,7 +833,8 @@ class Vulnerability:
See the CycloneDX schema: https://cyclonedx.org/docs/1.4/#type_vulnerabilityType
"""

def __init__(self, *, bom_ref: Optional[Union[str, BomRef]] = None, id: Optional[str] = None,
def __init__(self, *,
bom_ref: Optional[Union[str, BomRef]] = None, id: Optional[str] = None,
source: Optional[VulnerabilitySource] = None,
references: Optional[Iterable[VulnerabilityReference]] = None,
ratings: Optional[Iterable[VulnerabilityRating]] = None, cwes: Optional[Iterable[int]] = None,
Expand All @@ -852,10 +844,8 @@ def __init__(self, *, bom_ref: Optional[Union[str, BomRef]] = None, id: Optional
credits: Optional[VulnerabilityCredits] = None,
tools: Optional[Iterable[Tool]] = None, analysis: Optional[VulnerabilityAnalysis] = None,
affects: Optional[Iterable[BomTarget]] = None,
properties: Optional[Iterable[Property]] = None,
# Deprecated Parameters kept for backwards compatibility
source_name: Optional[str] = None, source_url: Optional[str] = None,
recommendations: Optional[Iterable[str]] = None) -> None:
properties: Optional[Iterable[Property]] = None
) -> None:
if isinstance(bom_ref, BomRef):
self._bom_ref = bom_ref
else:
Expand All @@ -878,18 +868,6 @@ def __init__(self, *, bom_ref: Optional[Union[str, BomRef]] = None, id: Optional
self.affects = affects or [] # type: ignore
self.properties = properties or [] # type: ignore

if source_name or source_url:
warnings.warn('`source_name` and `source_url` are deprecated - use `source`',
category=DeprecationWarning, stacklevel=1)
if not source:
self.source = VulnerabilitySource(name=source_name, url=XsUri(source_url) if source_url else None)

if recommendations:
warnings.warn('`recommendations` is deprecated - use `recommendation`',
category=DeprecationWarning, stacklevel=1)
if not recommendation:
self.recommendation = next(iter(recommendations))

@property
@serializable.json_name('bom-ref')
@serializable.type_mapping(BomRefHelper)
Expand Down
11 changes: 0 additions & 11 deletions cyclonedx/output/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""

import os
import warnings
from abc import ABC, abstractmethod
from itertools import chain
from random import random
Expand Down Expand Up @@ -139,16 +138,6 @@ def make_outputter(bom: 'Bom', output_format: OutputFormat, schema_version: Sche
return klass(bom)


def get_instance(bom: 'Bom', output_format: OutputFormat = OutputFormat.XML,
schema_version: SchemaVersion = LATEST_SUPPORTED_SCHEMA_VERSION) -> BaseOutput:
"""DEPRECATED. use :func:`make_outputter` instead!"""
warnings.warn(
'function `get_instance()` is deprecated, use `make_outputter()` instead.',
category=DeprecationWarning, stacklevel=1
)
return make_outputter(bom, output_format, schema_version)


class BomRefDiscriminator:

def __init__(self, bomrefs: Iterable['BomRef'], prefix: str = 'BomRef') -> None:
Expand Down
48 changes: 0 additions & 48 deletions tests/test_output_generic.py

This file was deleted.

0 comments on commit e9cc5ee

Please sign in to comment.