Skip to content
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

Update ngclient to return loaded metadata #1680

Merged

Conversation

ivanayov
Copy link
Collaborator

This changes TrustedMetadataSet to return new trusted Metadata
on successful calls of the update_<role> functions and also
changes Updater._load_targets to return loaded metadata as well

Fixes #1507

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature - n/a

Copy link
Collaborator

@MVrachev MVrachev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some small suggestions.
Will review it tomorrow more precisely.

tuf/ngclient/_internal/trusted_metadata_set.py Outdated Show resolved Hide resolved
tuf/ngclient/_internal/trusted_metadata_set.py Outdated Show resolved Hide resolved
tuf/ngclient/_internal/trusted_metadata_set.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Nov 16, 2021

Pull Request Test Coverage Report for Build 1490182832

  • 18 of 18 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 97.466%

Totals Coverage Status
Change from base Build 1476295870: 0.002%
Covered Lines: 3953
Relevant Lines: 4037

💛 - Coveralls

Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good... in addition to the annotation comment Martin made (that applies everywhere where we know the contained type):

  • it looks like we'll only use the return values from update_delegated_targets() but I agree it still makes sense to make all TrustedMetadataSet.update_*() methods return values in the same way: it keeps the TrustedMetadataSet API consistent
  • TrustedMetadataSet.update_targets() does not return a value yet, it should
  • I wonder about Updater._load_*() functions though -- they are internal to Updater... maybe it does not make sense to modify a function unless we actually want to use the return value. So this would mean we'd only modify _load_targets(), and not the other methods. I'm fine with other opinions in this one though

tuf/ngclient/updater.py Outdated Show resolved Hide resolved
@ivanayov
Copy link
Collaborator Author

Thanks for the reviews!

The reason I left _load_root unchanged is because it needs to collect metadata from all root versions and I'm not sure if we need such collection and if we actually want to create it. The only reason for creating one is just to make all _load_* functions unified, which I don't find strong enough argument, but I'd be happy to hear feedback if it really makes sense.

@ivanayov
Copy link
Collaborator Author

We agreed with @jku on returning metadata from all update_* functions to keep the API consistent and return it only from _load_delegated_targets within the Updater, as the output from others is never used.

@ivanayov ivanayov force-pushed the ivanayov/ngclient_loaded_metadata branch from f778d36 to ff5ddce Compare November 17, 2021 12:57
tuf/ngclient/updater.py Outdated Show resolved Hide resolved
@MVrachev
Copy link
Collaborator

I realized that probably there is no sense in annotating the return type as Metadata[Root], Metadata[Timestamp]or otherMetadata[T]when we actually returnRoot, Timestampfromupdate_root, update_timestamp`, etc.
Do you agree with me @jku?

@jku
Copy link
Member

jku commented Nov 18, 2021

I realized that probably there is no sense in annotating the return type as Metadata[Root], Metadata[Timestamp]or otherMetadata[T]when we actually returnRoot, Timestampfromupdate_root, update_timestamp`, etc. Do you agree with me @jku?

We should return Metadata[T] and it seems we do, I don't see a problem.

If we returned Root from update_root() mypy should complain as well.

Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks nice. Quite a bit of work to avoid one single dict lookup, but I think the end result is a better TrustedMetadataSet API (and might be useful in the repository work later).

I just had one nit about the return value docstring

tests/test_trusted_metadata_set.py Outdated Show resolved Hide resolved
tuf/ngclient/_internal/trusted_metadata_set.py Outdated Show resolved Hide resolved
@MVrachev
Copy link
Collaborator

I realized that probably there is no sense in annotating the return type as Metadata[Root], Metadata[Timestamp]or otherMetadata[T]when we actually returnRoot, Timestampfromupdate_root, update_timestamp`, etc. Do you agree with me @jku?

Apologize for my review here. I made a wrong assumption.
You should annotate the return type as Metadata[Root], instead of Root as in update_root you are returning new_root which is initialized as new_root = Metadata[Root].from_bytes(data).
It's the same situation for the other cases I discuss here as well.

@ivanayov ivanayov force-pushed the ivanayov/ngclient_loaded_metadata branch from ff5ddce to a0d412f Compare November 18, 2021 10:47
Copy link
Collaborator

@MVrachev MVrachev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my comments!
LGTM!

Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Left a really minor comment but no need to update just for that

tuf/ngclient/_internal/trusted_metadata_set.py Outdated Show resolved Hide resolved
This changes `TrustedMetadataSet` to return new trusted Metadata
on successful calls of the `update_<role>` functions and also
changes `Updater._load_targets` to return loaded metadata as well

Signed-off-by: Ivana Atanasova <iyovcheva@iyovcheva-a02.vmware.com>
@ivanayov ivanayov force-pushed the ivanayov/ngclient_loaded_metadata branch from a0d412f to 9c2bf6e Compare November 22, 2021 12:36
@jku jku merged commit acb201d into theupdateframework:develop Nov 22, 2021
@lukpueh lukpueh mentioned this pull request Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngclient: return loaded metadata from Updater._load_targets
4 participants