You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Metadata API validation: validate root roles dictionary content #1516
A role for each of "root", "snapshot", "timestamp", and "targets" MUST be specified in the key list. The role of "mirror" is OPTIONAL.
The reference to "key list" seems like a mistake (maybe referring to an earlier design?) but the intent seems clear: the roles dictionary is allowed to contain either the roles for ["root", "snapshot", "timestamp", "targets"] or the roles for ["root", "snapshot", "timestamp", "targets", "mirror"] (and I suppose we are not going to implement mirror for now)). Other roles are not valid and not having the first four roles is not valid.
It makes sense to validate this in Root construction/deserialization.
Aside/thought: maybe it also makes sense to validate in serialization but I think documenting that roles dict is not intended to be modified goes a long way.
changed the title [-]Metadata API validation: validate root roles keys[/-][+]Metadata API validation: validate root roles dictionary content[/+]on Aug 9, 2021
I guess this is a good time to think if the Root constructor signature makes sense: roles could be just a Tuple[Role, Role, Role, Role] or the individual roles could be named arguments themselves -- there's no need for roles to be a dict since we know what the keys are.
This would make Constructing Root from scratch a little easier, and from_dict() could still do the validation of keys -- but I'm not sure if this is still worth it: I'm fine with just doing what the previous comment says. For reference this is how weird the construction of an empty Root looks like now:
I guess this is a good time to think if the Root constructor signature makes sense: roles could be just a Tuple[Role, Role, Role, Role] or the individual roles could be named arguments themselves -- there's no need for roles to be a dict since we know what the keys are.
Maybe then we should add additional validation that roles contain exactly four roles representing the top-level metadata roles?
It's said in the spec that: A role for each of "root", "snapshot", "timestamp", and "targets" MUST be specified in the roles object.
The only drawback I see is that we will have always to provide 4 roles even during testing.
Also about what you said above:
update failing tests (at leasts test_metadata_serialization valid_roots dataset makes assumptions about this)
If we leave it as it is and don't check that root contains exactly 4 roles with the correct naming, then I don't see what do we have to update in that dataset.
Maybe then we should add additional validation that roles contain exactly four roles representing the top-level metadata roles?
Are you now talking about my off the cuff idea of changing the constructor or the current situation? Whenever we take a dictionary as input we should validate that the four correct keys are there -- A Root object without exactly four correct roles is invalid and shouldn't never exist IMO. So as a minimum we need to do it on from_dict() but if the constructor takes a dict as it does now and if we store the dict, then it makes sense to do the validation in the constructor instead.
Now, I would like to make the constructors easier to use for the repository use case but there is no concrete proposal so I don't think you should worry about that too much in this issues. Anyway, possibly we can avoid big API changes (like the one I proposed above) and e.g. just accept None as roles in constructor : then it's easier to create a new Root (and the constructor would generate the default roles in my example).
Are you now talking about my off the cuff idea of changing the constructor or the current situation?
I wanted to raise discussion for all of the topics you mentioned.
Whenever we take a dictionary as input we should validate that the four correct keys are there -- A Root object without exactly four correct roles is invalid and shouldn't never exist IMO.
Agree. Validation for this should be added as well and this will require changing the valid_roots dataset in test_metadata_serialization.py.
Now, I would like to make the constructors easier to use for the repository use case but there is no concrete proposal so I don't think you should worry about that too much in this issues. Anyway, possibly we can avoid big API changes (like the one I proposed above)
I agree with this, but I am not sure about this part:
and e.g. just accept None as roles in constructor : then it's easier to create a new Root (and the constructor would generate the default roles in my example).
you don't suggest doing that API change in this issue right?
you don't suggest doing that API change in this issue right?
I don't: only reason to discuss these here is just in case they would make the validation obsolete... That doesn't seem likely so let's just forget it for now.
Activity
[-]Metadata API validation: validate root roles keys[/-][+]Metadata API validation: validate root roles dictionary content[/+]jku commentedon Aug 10, 2021
These seem to be the steps:
rolesdictionary keys inRoot.__init__(): keys should be ["root", "snapshot", "timestamp", "targets"]Additionally:
jku commentedon Aug 25, 2021
I guess this is a good time to think if the Root constructor signature makes sense:
rolescould be just aTuple[Role, Role, Role, Role]or the individual roles could be named arguments themselves -- there's no need forrolesto be a dict since we know what the keys are.This would make Constructing Root from scratch a little easier, and
from_dict()could still do the validation of keys -- but I'm not sure if this is still worth it: I'm fine with just doing what the previous comment says. For reference this is how weird the construction of an empty Root looks like now:MVrachev commentedon Oct 20, 2021
Maybe then we should add additional validation that
rolescontain exactly four roles representing the top-level metadata roles?It's said in the spec that:
A role for each of "root", "snapshot", "timestamp", and "targets" MUST be specified in the roles object.The only drawback I see is that we will have always to provide 4 roles even during testing.
Also about what you said above:
If we leave it as it is and don't check that root contains exactly 4 roles with the correct naming, then I don't see what do we have to update in that dataset.
jku commentedon Oct 20, 2021
Are you now talking about my off the cuff idea of changing the constructor or the current situation? Whenever we take a dictionary as input we should validate that the four correct keys are there -- A Root object without exactly four correct roles is invalid and shouldn't never exist IMO. So as a minimum we need to do it on
from_dict()but if the constructor takes a dict as it does now and if we store the dict, then it makes sense to do the validation in the constructor instead.Now, I would like to make the constructors easier to use for the repository use case but there is no concrete proposal so I don't think you should worry about that too much in this issues. Anyway, possibly we can avoid big API changes (like the one I proposed above) and e.g. just accept
Noneas roles in constructor : then it's easier to create a new Root (and the constructor would generate the default roles in my example).MVrachev commentedon Oct 20, 2021
I wanted to raise discussion for all of the topics you mentioned.
Agree. Validation for this should be added as well and this will require changing the
valid_rootsdataset intest_metadata_serialization.py.I agree with this, but I am not sure about this part:
you don't suggest doing that API change in this issue right?
jku commentedon Oct 21, 2021
I don't: only reason to discuss these here is just in case they would make the validation obsolete... That doesn't seem likely so let's just forget it for now.
MVrachev commentedon Oct 21, 2021
Okay, then I can fix this issue because it's connected with another one I am already involved in #1356.