diff --git a/aries_cloudagent/messaging/util.py b/aries_cloudagent/messaging/util.py index 4cb6669eb7..e6c2ebcb98 100644 --- a/aries_cloudagent/messaging/util.py +++ b/aries_cloudagent/messaging/util.py @@ -95,7 +95,7 @@ def epoch_to_str(epoch: int) -> str: def datetime_now() -> datetime: """Timestamp in UTC.""" - return datetime.utcnow().replace(tzinfo=timezone.utc) + return datetime.now(tz=timezone.utc) def time_now() -> str: diff --git a/aries_cloudagent/multitenant/base.py b/aries_cloudagent/multitenant/base.py index c71eb8ac8c..1d9add0a9a 100644 --- a/aries_cloudagent/multitenant/base.py +++ b/aries_cloudagent/multitenant/base.py @@ -1,7 +1,7 @@ """Manager for multitenancy.""" from abc import ABC, abstractmethod -from datetime import datetime +from datetime import datetime, timezone import logging from typing import Iterable, List, Optional, cast, Tuple @@ -297,7 +297,7 @@ async def create_auth_token( str: JWT auth token """ - iat = int(round(datetime.utcnow().timestamp())) + iat = int(round(datetime.now(tz=timezone.utc).timestamp())) jwt_payload = {"wallet_id": wallet_record.wallet_id, "iat": iat} jwt_secret = self._profile.settings.get("multitenant.jwt_secret") diff --git a/aries_cloudagent/multitenant/tests/test_base.py b/aries_cloudagent/multitenant/tests/test_base.py index 4d572c9a83..61a974cc17 100644 --- a/aries_cloudagent/multitenant/tests/test_base.py +++ b/aries_cloudagent/multitenant/tests/test_base.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timezone from unittest import IsolatedAsyncioTestCase from aries_cloudagent.tests import mock @@ -374,7 +374,7 @@ async def test_create_auth_token_managed(self): save=mock.CoroutineMock(), ) - utc_now = datetime(2020, 1, 1, 0, 0, 0) + utc_now = datetime(2020, 1, 1, 0, 0, 0, tzinfo=timezone.utc) iat = int(round(utc_now.timestamp())) expected_token = jwt.encode( @@ -382,7 +382,7 @@ async def test_create_auth_token_managed(self): ) with mock.patch.object(test_module, "datetime") as mock_datetime: - mock_datetime.utcnow.return_value = utc_now + mock_datetime.now.return_value = utc_now token = await self.manager.create_auth_token(wallet_record) assert wallet_record.jwt_iat == iat @@ -398,7 +398,7 @@ async def test_create_auth_token_unmanaged(self): save=mock.CoroutineMock(), ) - utc_now = datetime(2020, 1, 1, 0, 0, 0) + utc_now = datetime(2020, 1, 1, 0, 0, 0, tzinfo=timezone.utc) iat = int(round(utc_now.timestamp())) expected_token = jwt.encode( @@ -411,7 +411,7 @@ async def test_create_auth_token_unmanaged(self): ) with mock.patch.object(test_module, "datetime") as mock_datetime: - mock_datetime.utcnow.return_value = utc_now + mock_datetime.now.return_value = utc_now token = await self.manager.create_auth_token(wallet_record, "test_key") assert wallet_record.jwt_iat == iat diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py index 745f51c42f..fad679bbd8 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py @@ -102,7 +102,7 @@ class TestConfig: routing_keys=[], service_endpoint=test_endpoint, ) - NOW_8601 = datetime.utcnow().replace(tzinfo=timezone.utc).isoformat(" ", "seconds") + NOW_8601 = datetime.now(tz=timezone.utc).isoformat(" ", "seconds") TEST_INVI_MESSAGE_TYPE = "out-of-band/1.1/invitation" NOW_EPOCH = str_to_epoch(NOW_8601) CD_ID = "GMm4vMw8LLrLJjp81kRRLp:3:CL:12:tag" diff --git a/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_request.py b/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_request.py index 3a71200006..fe1bf557da 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_request.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_request.py @@ -12,7 +12,7 @@ from ..presentation_request import PresentationRequest -NOW_8601 = datetime.utcnow().replace(tzinfo=timezone.utc).isoformat(" ", "seconds") +NOW_8601 = datetime.now(tz=timezone.utc).isoformat(" ", "seconds") NOW_EPOCH = str_to_epoch(NOW_8601) CD_ID = "GMm4vMw8LLrLJjp81kRRLp:3:CL:12:tag" INDY_PROOF_REQ = json.loads( diff --git a/aries_cloudagent/resolver/did_resolver.py b/aries_cloudagent/resolver/did_resolver.py index 4dcdfa03ef..ee8f9f419b 100644 --- a/aries_cloudagent/resolver/did_resolver.py +++ b/aries_cloudagent/resolver/did_resolver.py @@ -5,7 +5,7 @@ """ import asyncio -from datetime import datetime +from datetime import datetime, timezone from itertools import chain import logging from typing import List, Optional, Sequence, Text, Tuple, Union @@ -91,11 +91,11 @@ async def resolve_with_metadata( self, profile: Profile, did: Union[str, DID], *, timeout: Optional[int] = None ) -> ResolutionResult: """Resolve a DID and return the ResolutionResult.""" - resolution_start_time = datetime.utcnow() + resolution_start_time = datetime.now(tz=timezone.utc) resolver, doc = await self._resolve(profile, did, timeout=timeout) - time_now = datetime.utcnow() + time_now = datetime.now(tz=timezone.utc) duration = int((time_now - resolution_start_time).total_seconds() * 1000) retrieved_time = time_now.strftime("%Y-%m-%dT%H:%M:%SZ") resolver_metadata = ResolutionMetadata(