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

Metadata API: include target target name in TargetFile #1514

Merged
merged 2 commits into from Aug 27, 2021

Conversation

MVrachev
Copy link
Collaborator

@MVrachev MVrachev commented Aug 3, 2021

Related to #1411, but it's not yet clear if it closes it.

Description of the changes being introduced by the pull request:

Currently, TargetFile instances do not contain the filename of the file
they represent. The API itself does not need it but it could be useful
for users of the API.

As an example, the current client returns a dict for
get_one_valid_targetinfo(): that dict contains a filepath field and
a targetinfo field (essentially TargetFile).
We would like to keep a similar API, but avoid hand-crafted dicts.
It would be much nicer to return a TargetFile that would contain the
full "metadata" of the targetfile.

Signed-off-by: Martin Vrachev mvrachev@vmware.com

Please verify and check that the pull request fulfills the following
requirements
:

  • 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

@MVrachev MVrachev changed the title Metadata API: include target name in targetfile Metadata API: include target target name in TargetFile Aug 3, 2021
tuf/ngclient/updater.py Outdated Show resolved Hide resolved
unrecognized_fields: Dictionary of all unrecognized fields.
"""

def __init__(
self,
length: int,
hashes: Dict[str, str],
targetname: Optional[str] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan ofTargetFile.targetname. How about TargetFile.filename, TargetFile.path or TargetFile.targetpath if we insist on being verbose and stick to the spec.

Copy link
Member

Choose a reason for hiding this comment

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

(this is just a drive by comment, will have to think about the justification for thw whole thing a bit still... but thanks for starting this, I think it's useful to make discussion more concrete)

What teodora said, let's not use even more different names for the same thing... I think "targetpath" is used for this already so the attribute should probably be targetpath or path.

I believe it should not be optional though. Or is there a use case of a TargetFile without a targetpath?

Copy link
Collaborator Author

@MVrachev MVrachev Aug 4, 2021

Choose a reason for hiding this comment

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

I'm not a fan of TargetFile.targetname. How about TargetFile.filename, TargetFile.path or TargetFile.targetpath if we insist on being verbose and stick to the spec.

I had a misconception and didn't want to call it targetpath thinking it's not an actual path, but a file name.
Now, I read the spec and it clearly this is called TARGETPATH:
https://theupdateframework.github.io/specification/latest/#targetpath.

So, from both options to call it targetpath or path I would prefer path given it's shorter.

I believe it should not be optional though. Or is there a use case of a TargetFile without a targetpath?

I wasn't sure when I added it as optional. I did that because it's not required by the spec, but we can use TargetFile
in such a way that we would always pass the path.

So, in conclusion, I will rename the attribute to path and make it non-optional.

@jku
Copy link
Member

jku commented Aug 6, 2021

I think this makes sense and implementation looks fine. You will have to do something about Targets.update() though (I still think removing it is correct -- at least currently it seems to have no purpose other than creating apparent complexity -- but I guess fixing it to match the new API is an option as well)

Maybe it would be good to document target path a little more: that it is a "path-relative-URL string" that will be used as part of the final download url to fetch the target

The high level question is whether anyone objects to making objects like this a bit smarter (in this case be aware of the path) even if the file format does not include that. I think this is a good way forward and seems immediately understandable by the reader -- it definitely makes the Updater API much better...

@sechkova sechkova mentioned this pull request Aug 6, 2021
3 tasks
@jku
Copy link
Member

jku commented Aug 9, 2021

For those not following that closely: this PR changes TargetFile interface (which on it's own is a minor change in the Metadata API implementation) but also the whole ngclient API so that TargetFile is returned and expected as argument instead of an undefined dictionary.

I think this is going in the right direction and allows us to continue with something like #1317 (comment): I believe the core Updater should not handle caching: this would make it much clearer what is actually part of the spec implementation and what is an additional thing we just wanted to implement in the same source directory

@joshuagl
Copy link
Member

The high level question is whether anyone objects to making objects like this a bit smarter (in this case be aware of the path) even if the file format does not include that. I think this is a good way forward and seems immediately understandable by the reader -- it definitely makes the Updater API much better...

I do not object, in fact looking at it now having an object which describes a file without being able to explicitly identify the file does look odd. +1 from me.

@jku
Copy link
Member

jku commented Aug 10, 2021

@MVrachev can you suggest a solution for Targets.update(): at the very least the function arguments need to be updated.

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.

marking changes requested for Targets.update() issue

@MVrachev
Copy link
Collaborator Author

MVrachev commented Aug 17, 2021

I had to rebase to fix merge conflicts after the simplification of _preorder_depth_first_walk.
I updated the Targets.update() argument accordingly.
I will prefer if other changes or removal of the update method are done for all classes when resolving #1230.

@jku jku added this to the Sprint 6 milestone Aug 18, 2021
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 nice. I left a couple of comments and a question.

tuf/ngclient/updater.py Show resolved Hide resolved
tuf/ngclient/updater.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
Currently, TargetFile instances do not contain the path relative URL of
the file they represent. The API itself does not need it but it could be
useful for users of the API.

As an example, the current client returns a dict for
get_one_valid_targetinfo(): that dict contains a filepath field and
a targetinfo field (essentially TargetFile).
We would like to keep a similar API, but avoid hand-crafted dicts.
It would be much nicer to return a TargetFile that would contain the
full "metadata" of the targetfile.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
After the addition of "path" argument in the TargetFile class the
filename argument in Targets.update() became redundant.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
@jku jku merged commit 7731738 into theupdateframework:develop Aug 27, 2021
@MVrachev MVrachev deleted the filename-in-targetfile branch September 1, 2021 11:53
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.

None yet

4 participants