mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Fixes wrong schema when adding an expiration that contains microseconds
In the case we want a different expiration date on any role, we are adviced to do this: repo.role.expiration = datetime.datetime(some value). In the case we want to use a date somewhere in the future, a normal approach would be to use time deltas: repo.role.expiration = datetime.today() + timedelta(weeks=x) If we use this method we won't be able to set the value since we are most probably producing a datetime object that contains *microseconds*. According to the python specification, the timestamp produced will contain the microseconds value unless it is 0. The simple fix for this issue is to force the microseconds value to be 0 before working with the datetime object.
This commit is contained in:
parent
c16b1fdd80
commit
46fbfb3bc2
1 changed files with 4 additions and 0 deletions
|
|
@ -1141,6 +1141,10 @@ def expiration(self, datetime_object):
|
|||
message = repr(datetime_object) + ' is not a datetime.datetime() object.'
|
||||
raise tuf.FormatError(message)
|
||||
|
||||
# truncate the microseconds value to produce a correct schema string
|
||||
# of the form yyyy-mm-ddThh:mm:ssZ
|
||||
datetime_object = datetime_object.replace(microsecond = 0)
|
||||
|
||||
# Ensure the expiration has not already passed.
|
||||
current_datetime_object = \
|
||||
tuf.formats.unix_timestamp_to_datetime(int(time.time()))
|
||||
|
|
|
|||
Loading…
Reference in a new issue