-
Notifications
You must be signed in to change notification settings - Fork 275
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
Remove iso8601 dependency #1065
Comments
The spec says
My naive understanding is that because of the zero offset requirement this might be easy to parse with standard library functions. |
That said, now that I've looked at iso8601 module itself... It's tiny, literally 215 lines of code. So vendoring it might not be a problem. |
#1060 makes use of dateutil. A quick browse of their docs made me think we could probably replace iso8601 with functionality in dateutil. |
oh, that would be even better! |
For the pip use case dateutil would be worse than iso8601 as it's much larger -- but I guess #1060 wouldn't necessarily mean updater changes? Oh and for reference: securesystemslib does use dateutil but AFAICS only in one place in gpg code |
In the short term, no. However, my current thought process is that the work in #1060 could become a low-level abstraction around TUF metadata that we build client/updater and repository APIs on top of. Therefore I'd like to make/keep those APIs as minimal (with as minimal dependencies) as possible so that they can be comfortably vendored into pip. Note to self (or whoever picks up this issue): look at the use of dateutil in tuf/api and figure out if we can achieve the same with the standard library. Specifically in tuf/api/metadata we're currently using
💯 Thanks for looking into this. |
The |
@joshuagl suggests to create a helper for the iso8601 replacing call datetime.strptime(exires, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=None) |
Use builtin datetime instead of external iso6801 for simple datetime string parsing. Also see theupdateframework#1065 Signed-off-by: Lukas Puehringer <[email protected]>
Use builtin datetime instead of external iso6801 for simple datetime string parsing. Also see theupdateframework#1065 Signed-off-by: Lukas Puehringer <[email protected]>
I've just reviewed the iso8601 test suite and have come to the conclusion that using the iso8601 module is in fact not compliant with the (spirit of the) tuf spec: current implementation allows for timestamps that I would not expect to work after reading the spec, such as "2006-10-20T15:34:56.123+02:30". The spec currently says:
I think the paragraph is fairly clear but first sentence could be better: we want to support only this very specific format of the ISO8601 not the whole iso8601 spec. As for the implementation, I think the helper idea is good. I don't think the |
Adding one more thing: the Securesystemslib schema for "iso8601 datetime string" is very strict: datetime can definitely parse that. I think the review is over... but since there's good discussion here I'm not closing: I'll just rename this to "Remove iso8601 dependency" |
Our 'expires' strings are constrained by the ISO8601_DATETIME_SCHEMA which matches regex '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z'. This can be parsed with just a datetime.strptime(): iso8601 module is not needed. * Add formats.expiry_string_to_datetime() helper function * Modify the 3 locations that used iso8601 and the api/metadata.py usage of datetime.strptime() * Remove related unnecessary logger setup * Add the missing exception documentation to relevant functions (in many cases the exception is rather unlikely as the schema has been verified many times before this though...) Fixes theupdateframework#1065 Signed-off-by: Jussi Kukkonen <[email protected]>
Great observation. Please send a PR to the spec 🙂 |
Our 'expires' strings are constrained by the ISO8601_DATETIME_SCHEMA which matches regex '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z'. This can be parsed with just a datetime.strptime(): iso8601 module is not needed. * Add formats.expiry_string_to_datetime() helper function * Modify the 3 locations that used iso8601 and the api/metadata.py usage of datetime.strptime() * Remove related unnecessary logger setup * Add the missing exception documentation to relevant functions (in many cases the exception is rather unlikely as the schema has been verified many times before this though...) Fixes theupdateframework#1065 Signed-off-by: Jussi Kukkonen <[email protected]>
Our 'expires' strings are constrained by the ISO8601_DATETIME_SCHEMA which matches regex '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z'. This can be parsed with just a datetime.strptime(): iso8601 module is not needed. * Add formats.expiry_string_to_datetime() helper function * Modify the 3 locations that used iso8601 and the api/metadata.py usage of datetime.strptime() * Remove related unnecessary logger setup * Add the missing exception documentation to relevant functions (in many cases the exception is rather unlikely as the schema has been verified many times before this though...) Fixes theupdateframework#1065 Signed-off-by: Jussi Kukkonen <[email protected]>
I've been going through the tuf dependency chain with an eye on integrating tuf with pip: The issue with pip is that it's a package manager so needs to vendor everything it needs -- so being conservative with dependencies is a good idea. The good news is that tuf does not have many direct or indirect dependencies that would be a problem (good work!).
The one that possibly sticks out is "iso8601". The module is currently used in two places:
I'm mostly interested in that last one. it's used to compare the expiration stamp to current time and to format the error message:
I'm not familiar with date handling in python so my question is: Is this dependency valid or could this code be replaced with something that did not depend on iso8601?
The text was updated successfully, but these errors were encountered: