-
Notifications
You must be signed in to change notification settings - Fork 278
New metadata API: add MetaFile and TargetFile classes #1329
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
Conversation
24e014d
to
98c73b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the PR description you say that it will:
Rename a few instances of the update method in our classes and use a more verbose name.
but there is only one commit with marked TODOs.
My general comment is about removing hardcoded file extensions and mentions of "json" throughout the code. After the abstract (de)serialization was implemented, TUF supposedly supports other file formats too.
def194a
to
5380720
Compare
I rebased and fixed your two small comments @sechkova about other issues besides the hard-coded file names. I fixed the problem of hardcoded Created an issue about the hardcoded filename problems: #1333 |
0f582dc
to
fc51eba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for not looking at this before. I've gone through most, but maybe not quite processed all of it.
Martin knows of this but for others information: the changes to .pop()
usage are going to clash with another PR #1345: they need to be coordinated. In general I think this PR could have been several smaller instead -- I get that it means annoying depending PRs... but this way means I feel bad for leaving so many comments 😁
Would be great to see a bit more prose about the design and usability of the specific API classes somewhere: If we go through the trouble of creating objects for everything, we should try to make them more usable than the dictionaries they replace. As examples, see question in code about snapshot_info attribute and ideas like 'should Targets maybe implement abc.Mapping so caller could access targets.signed["target_name"] instead of targets.signed.targets["target_name"]' -- that last one may not be a good idea but it would be good to see some ideas and discussion before we start maintaining more code.
This feels like a lot to ask on a big PR but would be nice to see how the code now copes without broken input in tests (missing fields, extra fields, etc) -- to confirm the benefits that we should be getting from this work.
Also grumpy yesterday me sounds like he is unsatisfied with this PR but that's not true so I'll say it now: |
After further discussion, this opinion seems to go against previous decisions to keep the API as close to file format as possible -- so possibly we need to discuss further or implement this as "faithful reproduction of spec" (disregarding my comments) and think about potential usability improvements afterwards... |
dae8909
to
75ad593
Compare
I have rebased and made changes in this pr after "develop" has evolved a lot. Some of the changes I made:
|
1a4f05d
to
d13522b
Compare
A question on the |
In the top-level metadata classes, there are complex attributes such as "meta" in Targets and Snapshot, "key" and "roles" in Root etc. We want to represent those complex attributes with a class to allow easier verification and support for metadata with unrecognized fields. For more context read ADR 0004 and ADR 0008 in the docs/adr folder. In TargetFile, after a suggestion made by Jussi here: theupdateframework#1329 (comment) I realized that "custom" has the same purpose as "unrecognized_fields" and can replace it. I removed the "unrecognized_field" attribute and added a property for unrecognized_fields which actually access "custom". Signed-off-by: Martin Vrachev <[email protected]>
Updated the pr addressing almost all of the comments @jku made with the only exceptions when commenting on the Additionally, I added a new commit where I remove the |
In the top-level metadata classes, there are complex attributes such as "meta" in Targets and Snapshot, "key" and "roles" in Root etc. We want to represent those complex attributes with a class to allow easier verification and support for metadata with unrecognized fields. For more context read ADR 0004 and ADR 0008 in the docs/adr folder. In TargetFile, after a suggestion made by Jussi here: theupdateframework#1329 (comment) I realized that "custom" has the same purpose as "unrecognized_fields" and can replace it. I removed the "unrecognized_field" attribute and added a property for unrecognized_fields which actually access "custom". Signed-off-by: Martin Vrachev <[email protected]>
a289347
to
bea222c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything else is a style comment (feel free to disregard) but I think there's a bug in the "custom" handling
3a6403b
to
9fe0808
Compare
Addressed all of @jku commets, and additionally I wanted to make sure that each of the commits passes the CI and makes sense.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my comment in-source won't show up since it's in a resolved discussion but:
The __eq__()
implementation is still not complete: if it is there, it should compare unrecognized_fields instead of custom.
Altogether this looks good, thanks. The docstrings are very verbose but let's trim those later... I'm marking this approved already, but please fix __eq__()
still in this PR.
I thought I had removed the |
I was about to merge but now it has conflicts with a bug fix I merged yesterday. Sorry. Could you rebase? |
In the top-level metadata classes, there are complex attributes such as "meta" in Targets and Snapshot, "key" and "roles" in Root etc. We want to represent those complex attributes with a class to allow easier verification and support for metadata with unrecognized fields. For more context read ADR 0004 and ADR 0008 in the docs/adr folder. Additionally, after adding the MetaFile class, when we create an object we are now calling from dict twice - one for the main class (Timestamp, Snapshot) and one for the pacticular complex attribute - MetaFile.from_dict(). Given that the "from_dict" methods have the side effect of destroying the given dictionary, we would need to start using deepcopy() for our tests. Signed-off-by: Martin Vrachev <[email protected]>
In the top-level metadata classes, there are complex attributes such as "meta" in Targets and Snapshot, "key" and "roles" in Root etc. We want to represent those complex attributes with a class to allow easier verification and support for metadata with unrecognized fields. For more context read ADR 0004 and ADR 0008 in the docs/adr folder. As written in the spec "targets" in "targets.json" has defined the "custom" field serving the same purpose as "unrecognized_fields" in the implementation. That's why to conform against the spec and support "custom" and allow "unrecognized_fields" everywhere where it's not sensitive we can define custom as property which actually access data stored in unrecognized_fields. For context read ADR 8 in tuf/docs/adr. Additionally, after adding the TargetFile class, when we create a Targets an object we are now calling from dict twice - one for the main Targets class and one for each of the complex attributes TargetFile.from_dict() and Delegations.from_dict(). Given that the "from_dict" methods have the side effect of destroying the given dictionary, we would need to start using deepcopy() for our tests. Signed-off-by: Martin Vrachev <[email protected]>
Signed-off-by: Martin Vrachev <[email protected]>
Disable the "C0302: Too many lines in module" warning which warns for modules with more 1000 lines, because all of the code here is logically connected and currently, we are above 1000 lines by a small margin. Signed-off-by: Martin Vrachev <[email protected]>
Currently, when we call Targets/Snapshot/Timestamp.update() we are passing all of the necessary values to create MetaFile/Targets File respectively. This is not needed, given that one of the reasons we have created MetaFile and TargetFile is to make the API easier to use. Signed-off-by: Martin Vrachev <[email protected]>
We have tests which make sure we can use `Timestamp.update()` and `Snapshot.update()` with MetaFile instance storing only version (because length and hashes are optional). Those tests were created to make sure that we are actually supporting optional hashes and length when we call `update` for those classes, but after we changed the `update()` signature to accept `MetaFile` instance the tests are obsolete. The reason is that length and hashes can be optional because of the MetaFile implementation, no the update function itself and we have other tests validating creating a MetaFie instance without hashes and length. Signed-off-by: Martin Vrachev <[email protected]>
Done. |
This pr is a continuation from pr #1223
This is the final pr planned for #1139,
Description of the changes being introduced by the pull request:
In the top-level metadata classes, there are complex attributes such as
"meta" in Targets and Snapshot, "key" and "roles" in Root etc.
We want to represent those complex attributes with a class to allow
easier verification and support for metadata with unrecognized fields.
For more context read ADR 0004 and ADR 0008 in the docs/adr folder.
Please verify and check that the pull request fulfills the following
requirements: