-
Notifications
You must be signed in to change notification settings - Fork 276
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
Create constructor(s) for creating Metadata from scratch #1459
Comments
To make this a bit more concrete: I have another PR that creates a root from scratch that looks like this: root = Root(1, SPEC_VER, expiry, {}, {}, True)
for role in ["root", "timestamp", "snapshot", "targets"]:
key, signer = self.create_key()
root.roles[role] = Role([], 1)
root.add_key(role, key)
# store role:signer elsewhere
self.md_root = Metadata(root, OrderedDict()) Not pretty: it calls three constructors with at least one useless argument. It could look like self.md_root = Metadata.new_root(expiry)
for role in self.md_root.signed.roles.keys():
key, signer = self.create_key()
self.md_root.signed.add_key(role, key)
# store role:signer elsewhere better? other ideas? |
I have an alternative suggestion that would not add new API: md_root = Metadata(Root(expires=expiry_date))
I think I like this. The only disadvantage is that it makes the constructor signatures even longer, but I can live with that. I think creating a minimal initial repo would look like targets = Metadata(Targets(expires=expiry_date))
snapshot = Metadata(Snapshot(expires=expiry_date))
timestamp = Metadata(Timestamp(expires=expiry_date))
root = Metadata(Root(expires=expiry_date))
for role in TOP_LEVEL_ROLE_NAMES:
key, signer = create_key()
root.signed.add_key(role, key)
# TODO store signer
# TODO: run snapshot/timestamp update |
Nice. It's hard to argue with a one-liner! |
I think we should have method(s) that make creating new valid metadata from scratch easier as the current constructor has really been designed for the deserialization use case
These would be useful for testing but also will make any repository tools and tutorials better.
Back of envelope proposal with a single method:
Metadata.new_with_defaults(signed_type: Type, expires: datetime) -> Metadata
This would do roughly
This might require a bit of experimentation to find a reasonable solution
The text was updated successfully, but these errors were encountered: