-
Notifications
You must be signed in to change notification settings - Fork 278
Reading some attributes of a delegated targets role after loading a repository throws a KeyError #574
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
Comments
Unfortunately, this one is a bit of a showstopper. As a workaround, I am forced to use a kludge (e.g., manually reading from |
What should the interface look like?
…On Thu, Dec 28, 2017 at 7:39 PM, Trishank Karthik Kuppusamy < ***@***.***> wrote:
Unfortunately, this one is a bit of a showstopper. As a workaround, I am
forced to use a kludge (e.g., manually reading from
tuf.roledb.get_roleinfo('targets', 'default') to get the keyids and
threshold for a delegated targets role off the top-level targets role).
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#574 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA0XDzkj63ipYJrxqvVQnlMhDF1JxiQTks5tFDTTgaJpZM4ROwXK>
.
|
The interface is already there (e.g., |
Asking about the So when you give the
What should the interface be to modify a delegation? Is this good?
Hopefully we can settle on a design that doesn't negatively impact code maintainability and my well being :) FYI: I think you can still give a |
Should we add a wrapper for this? |
I don't know, I have to think about this a bit. Your proposal for modifying a delegation looks fine to me. In general, I'm in favour of being explicit. My original question, though, was simply about reading the properties of existing delegations loaded from a repository off disk. For example, why do the following not work? print(str(repository.targets("foo").threshold))
print(str(repository.targets("foo".keys))) Am I missing something? |
(As an aside: I, too, am in favour of any solution that maintains your well-being.) |
The problem is that a delegated role doesn't have one threshold value. It is set by one or more delegators. When a delegated targets file is loaded from disk, the repository cannot, for example, set Nevertheless, we should probably still have an interface to inspect all fields of metadata. Does |
Vlad, I understand what you mean, but I still don't see why we can't read the threshold without ambiguity. Let me use an example to clarify what I mean. Suppose that:
Now why can't I read the threshold of 2 using something like Personally, I much prefer the more Pythonic array indexing, but this should work, no? I'm explicitly walking through the graph to get exactly the delegation chain I want. Maybe I missed some reason why this wouldn't work? |
Sebastien and I discussed this issue today. He noted that it's unclear what is meant by the I wonder if it might be simpler to remove these getter and setter functions and give users the metadata itself (exactly as it appears in the specification). What do you think of the following interface for accessing and updating a delegations field? from tuf.repository_tool import *
repo = load_repository("/repo_dir", "my_repo")
targets_metadata = repo.get_metadata("targets")
delegation1 = targets_medatata["delegations"]["roles"][0]
delegation1["threshold"] = 2
repo.update_metadata("targets", targets_metadata) What I like about this approach (for the low-level repo tool) is that there is no ambiguity and users are given a data structure that matches exactly what's in the specification. |
Without having thought deeply about it, my gut response is that there should be harmony between the read and write interfaces. Let me think about it a bit more, and get back to you, please... |
I see what you're saying, but that approach seems a bit "un-Pythonic" (requires explicitly knowing the metadata specification, whereas I think a more ORM approach would be nice).The proposed read interface is also radically different from the write interface. What do you think about the following? repository["targets"]["A"]["C"].targets #gives you targets
repository["targets"]["A"]["C"].threshold #gives you threshold
repository["targets"]["A"]["C"].version #gives you version number
# and so on and so forth I hope what I'm proposing is not too onerous. What do you think? |
I have several problems with this notation.
It might be best to load metadata and give it to the integrator, in my opinion. Of course, we would still provide functions to handle things like performing a delegation, fetching specific metadata, etc. A command-line tool can be provided to make it easier to work with a TUF repository, and the calls under discussion for integrators that want something more low-level. The low-level calls should be kept low level, and the CLI should focus on usability. Isn't the interface provided by Notary, and its Flynn.io predecessor, a CLI? I'm curious what others think? @JustinCappos @awwad @lukpueh @SantiagoTorres P.S. The Zen of Python:
|
Re the proposed interface (roles[A][C] style): I think my concerns are
covered in your response, Vlad. (: That's a good way to put it: it should
be clear when we're dealing with A's delegation to C (in A's role metadata)
rather than C's role metadata, and that's not the case for A['C'].version (C's
metadata) and A['C'].threshold (A's metadata) or similar constructs.
For another confusing example, "roles['A']['C'].version" might mean the
same thing as "roles['C'].version", but "roles['A']['C'].threshold" can't
mean the same thing as "roles['C'].threshold", which has to either refer to
nothing at all or a property of the unnamed Targets role's delegation to C
....
You'd translate "roles['A']['C'].version" into something like "Get role A's
metadata, go to its delegation section and find the delegation to role C.
Assuming that delegation exists, go back and grab the role metadata for C
instead. Return the version listed in C's metadata."
Setting aside that particular proposed interface, though, here are the two
more general questions in the past few emails:
1. whether or not to use get_metadata and update_metadata to retrieve
and assign dictionaries containing a role's full metadata (from and into
role_db or whatever its successor is)
2. whether or not to construct a simplified interface for getting and
setting thresholds, versions, etc. from a dictionary containing a role's
metadata
# 1 is what you're concerned about, Trishank, I gather? It might make
sense to forego the get and update functions and index directly into
role_db metadata, though I think that having two functions there to copy
out and back in might be clearer and safer. *shrug*
# 2: The existing interface of getters and setters provided for users made
a lot more sense when roles and delegations were roughly the same thing,
operating in a tree. That is no longer the case, as we're using more
general graphs now, where the A->C and B->C point to the same C role, but
may possess different thresholds and key expectations. This will only get
more complicated for multi-role delegations....
I agree with Vlad that operating within that role metadata in low-level
code (if not in general) should probably look like indexing into the
existing dictionary structure of the metadata. *The metadata structure is
specified in the spec, and if operating with the metadata looks like
walking through the same structure, that makes sense. Doing otherwise might
result in too much code complexity, even before TAP 3.
We should probably have some functions to perform common actions in a
higher level interface, but low level things operating with the dictionary
structures specified in the spec seems wise.
|
Oh, I see what you guys are saying now. Yeah, using dictionary-like methods to get/set is fine with me, as long as it is consistent (both read/write uses this interface). Thanks! |
Closing this issue as it was filed against (what is now known as) the legacy codebase: issue seems to not be relevant anymore. Please re-open or file a new issue if you feel that the issue is revelant to current python-tuf.
More details Current source code (and upcoming 1.0 release) only contains the modern components
Legacy components (e.g. tuf.client, tuf.repository_tool, tuf.repository_lib as well as the repo and client scripts) are no longer included. See announcement and API reference for more details. |
Uh oh!
There was an error while loading. Please reload this page.
Description of issue or feature request:
After loading a repository, reading the threshold of a delegated targets role throws a
KeyError
.Current behavior:
Expected behavior:
Should return the threshold / keys of the delegated targets role. I suspect this is due to missing assignments [1].
Ideally, the fix should include checking the schema of the delegated targets role after assignments.
The text was updated successfully, but these errors were encountered: