Uh oh!
There was an error while loading. Please reload this page.
New API: Add Key and Role classes - #1360
Conversation
MVrachev
commented
Apr 21, 2021
There is an interesting reason for the CI failure: I used many local variables to make it clear what their purpose is. |
mnm678
commented
Apr 21, 2021
This is interesting. I think local variables generally make code more readable, so I'm in favor of disabling this warning. |
jku
commented
Apr 22, 2021
I don't think the function looks horrible but ... you could make |
jku
left a comment
There was a problem hiding this comment.
Thanks Martin. I have one potential bug (the keyids type issue which I'm not yet sure how to handle), the rest are just nits/suggestions/questions
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jku
commented
Apr 22, 2021
There are currently no Key/Role specific tests: We probably should have at least very basic ones if we now have objects? One thing that might be nice to check for is invalid data -- what does the failure look like if the metadata is not valid (say a missing required field). I don't think this needs to be exhaustively tested but would be nice to see at least an example: I assume with this code we mostly get KeyErrors? |
jku
left a comment
There was a problem hiding this comment.
Just one real issue: the keyids uniqueness checks and creation of the set still have a smell around them: I think the error isn't currently raised (when using from_dict()).
| # Add unrecognized fields to all metadata sub (helper) classes. | ||
| if metadata == "root": | ||
| for keyid in dict1["signed"]["keys"].keys(): | ||
| dict1["signed"]["keys"][keyid]["d"] = "c" | ||
| for role_str in dict1["signed"]["roles"].keys(): | ||
| dict1["signed"]["roles"][role_str]["e"] = "g" |
There was a problem hiding this comment.
this looks like it will become hard to maintain when more tests are added but I'm fine with it for now: can you make an issue about doing this in a more structured way (like automate the dictionary poisoning so that ever dictionary is injected, not just ones we list here)?
There was a problem hiding this comment.
Yes, you are right. We should automate this.
In a discussion, you showed a prototype automating this process.
Will appreciate it if you propose these changes and we can discuss them, but I don't think this is in the scope of this pr.
Uh oh!
There was an error while loading. Please reload this page.
Updated the pr by:
|
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. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
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. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
The from_dict() method simplifies the object creation. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
MVrachev
commented
Apr 27, 2021
Rebased after #1363 was merged. |
From the specification: "Clients MUST ensure that for any KEYID represented in this key list and in other files, only one unique key has that KEYID." The “only one unique key has that KEYID” is a requirement which can’t be achieved if two keyids are the same. So, in order to mandate that requirement it makes sense to use a set which will guarantee us the keyid’s uniqueness. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
jku
left a comment
There was a problem hiding this comment.
I think this looks good. I did notice one unneeded "if" that I had missed earlier (adding duplicates to a set is safe).
| if keyid not in self.roles[role].keyids: | ||
| self.roles[role].keyids.add(keyid) |
There was a problem hiding this comment.
only realized this now but the check here is not needed with a set
Verify that adding an already existing key to keyid for a particular role in Root won't create duplicate key. Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Addresses, but doesn't fix: #1139
Description of the changes being introduced by the pull request:
In the top level metadata classes, there are complex attributes such as
metain Targets and Snapshot,keyandrolesin 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.
The changes in this pr include:
Keyclass integrated into RootRolesclass integrated intoKeyandRolesPlease verify and check that the pull request fulfills the following
requirements: