Skip to content

Commit

Permalink
make internal: get_now_utc
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck committed Dec 5, 2023
1 parent f2ba532 commit 7898485
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
27 changes: 27 additions & 0 deletions cyclonedx/_internal/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.


"""
!!! ALL CLASSES IN HERE ARE INTERNAL.
Everything might change without any notice.
"""


from datetime import datetime, timezone


def get_now_utc() -> datetime:
return datetime.now(tz=timezone.utc)
6 changes: 1 addition & 5 deletions cyclonedx/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""

import re
from datetime import datetime, timezone
from datetime import datetime
from enum import Enum
from functools import reduce
from json import loads as json_loads
Expand Down Expand Up @@ -51,10 +51,6 @@
)


def get_now_utc() -> datetime:
return datetime.now(tz=timezone.utc)


@serializable.serializable_enum
class DataFlow(str, Enum):
"""
Expand Down
17 changes: 9 additions & 8 deletions cyclonedx/model/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import serializable
from sortedcontainers import SortedSet

from .._internal.time import get_now_utc as _get_now_utc
from ..exception.model import LicenseExpressionAlongWithOthersException, UnknownComponentDependencyException
from ..schema.schema import (
SchemaVersion1Dot0,
Expand All @@ -35,7 +36,7 @@
SchemaVersion1Dot5,
)
from ..serialization import LicenseRepositoryHelper, UrnUuidHelper
from . import ExternalReference, OrganizationalContact, OrganizationalEntity, Property, ThisTool, Tool, get_now_utc
from . import ExternalReference, OrganizationalContact, OrganizationalEntity, Property, ThisTool, Tool
from .bom_ref import BomRef
from .component import Component
from .dependency import Dependable, Dependency
Expand Down Expand Up @@ -63,7 +64,7 @@ def __init__(self, *, tools: Optional[Iterable[Tool]] = None,
licenses: Optional[Iterable[License]] = None,
properties: Optional[Iterable[Property]] = None,
timestamp: Optional[datetime] = None) -> None:
self.timestamp = timestamp or get_now_utc()
self.timestamp = timestamp or _get_now_utc()
self.tools = tools or [] # type: ignore
self.authors = authors or [] # type: ignore
self.component = component
Expand Down Expand Up @@ -277,13 +278,13 @@ def __init__(self, *, components: Optional[Iterable[Component]] = None,
New, empty `cyclonedx.model.bom.Bom` instance.
"""
self.serial_number = serial_number or uuid4()
self.metadata = metadata or BomMetaData()
self.components = components or [] # type: ignore
self.services = services or [] # type: ignore
self.external_references = SortedSet(external_references or [])
self.vulnerabilities = SortedSet(vulnerabilities or [])
self.version = version
self.dependencies = SortedSet(dependencies) or SortedSet()
self.metadata = metadata or BomMetaData()
self.components = components or [] # type:ignore[assignment]
self.services = services or [] # type:ignore[assignment]
self.external_references = external_references or [] # type:ignore[assignment]
self.vulnerabilities = vulnerabilities or [] # type:ignore[assignment]
self.dependencies = dependencies or SortedSet() # type:ignore[assignment]

@property
@serializable.type_mapping(UrnUuidHelper)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_real_world_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@patch('cyclonedx.model.ThisTool._version', 'TESTING')
@patch('cyclonedx.model.bom.get_now_utc', return_value=datetime.fromisoformat('2023-01-07 13:44:32.312678+00:00'))
@patch('cyclonedx.model.bom._get_now_utc', return_value=datetime.fromisoformat('2023-01-07 13:44:32.312678+00:00'))
class TestDeserializeeRealWorldExamples(unittest.TestCase):

def test_webgoat_6_1(self, *_: Any, **__: Any) -> None:
Expand Down

0 comments on commit 7898485

Please sign in to comment.