Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deprecated datetime timestamps calls #16095

Merged
merged 6 commits into from May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions conans/server/crypto/jwt/jwt_manager.py
@@ -1,10 +1,10 @@
from datetime import datetime
from datetime import datetime, timezone
from calendar import timegm

import jwt


class JWTManager(object):
class JWTManager:
"""
Handles the JWT token generation and encryption.
"""
Expand All @@ -21,7 +21,8 @@ def get_token_for(self, profile_fields=None):
profile_fields = profile_fields or {}

if self.expire_time:
profile_fields["exp"] = timegm((datetime.utcnow() + self.expire_time).timetuple())
profile_fields["exp"] = timegm((datetime.now(timezone.utc)
+ self.expire_time).timetuple())

return jwt.encode(profile_fields, self.secret, algorithm="HS256")

Expand Down
2 changes: 1 addition & 1 deletion conans/test/unittests/client/util/time_test.py
Expand Up @@ -11,7 +11,7 @@ class TimeTest(unittest.TestCase):
def test_time_conversions(self):
timestamp = 1547138099
iso = from_timestamp_to_iso8601(timestamp)
self.assertEqual(iso, "2019-01-10T16:34:59Z")
self.assertEqual(iso, "2019-01-10T16:34:59+00:00")

dt = _from_iso8601_to_datetime(iso)
expected = datetime.datetime(year=2019, month=1, day=10, hour=16, minute=34, second=59,
Expand Down
4 changes: 2 additions & 2 deletions conans/util/dates.py
Expand Up @@ -9,7 +9,7 @@

def from_timestamp_to_iso8601(timestamp):
# Used exclusively by conan_server to return the date in iso format (same as artifactory)
return "%sZ" % datetime.datetime.utcfromtimestamp(timestamp).isoformat()
return "%s" % datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc).isoformat()


def _from_iso8601_to_datetime(iso_str):
Expand All @@ -34,7 +34,7 @@ def revision_timestamp_now():
def timestamp_to_str(timestamp):
# used by ref.repr_humantime() to print human readable time
assert timestamp is not None
return datetime.datetime.utcfromtimestamp(int(timestamp)).strftime('%Y-%m-%d %H:%M:%S UTC')
return datetime.datetime.fromtimestamp(int(timestamp), datetime.timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC')


def timelimit(expression):
Expand Down