question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reading some attributes of a delegated targets role after loading a repository throws a KeyError

See original GitHub issue

Description of issue or feature request:

After loading a repository, reading the threshold of a delegated targets role throws a KeyError.

Current behavior:

  1. Create a new repository with a delegated targets role.
  2. Load the repository.
  3. Try to read the threshold of this delegated targets role:
(Pdb) delegated_targets_role.threshold
*** KeyError: 'threshold'
  1. Try to read the keys of this delegated targets role:
  File "/usr/lib/python3.6/site-packages/tuf/repository_tool.py", line 1008, in keys
    keyids = roleinfo['keyids']
KeyError: 'keyids'

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
vladimir-v-diazcommented, Jan 12, 2018

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).

Should we add a wrapper for this? repository.get_roleinfo("rolename")? The returned dict should contain all of the metadata fields you’d want.

1reaction
vladimir-v-diazcommented, Jan 12, 2018

Asking about the threshold and keyids of a delegated role (e.g., my_role.threshold) is complicated by the fact that my_role can be a delegation of more than one role. For instance, foo can delegate to my_role some paths with a threshold of X and keyids A, B, C. The bar role can also delegate to my_role some different paths with a threshold of Y and keyids D, E.

So when you give the my_role.threshold query, which value do you expect?

my_role.threshold was actually a thing in the past, back when delegations resembled a tree rather than a graph. I suppose it’s clear which value is meant via repository.targets.foo.my_role.threshold. Unfortunately, it was decided that this command was unweildy, so it was replaced by, for example, repository.targets("my_role").delegate() and repository.targets("foo").version = 2).

What should the interface be to modify a delegation?

Is this good?

repository.targets("foo").revoke("my_role")
repository.targets("foo").delegate("my_role", new_threshold, new_keyids...)

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 repository.targets.threshold. It is allowed because there is a definitive value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading some attributes of a delegated targets role after ...
Description of issue or feature request: After loading a repository, reading the threshold of a delegated targets role throws a KeyError . Current...
Read more >
Python KeyError Exceptions and How to Handle Them
Python's official documentation says that the KeyError is raised when a mapping key is accessed and isn't found in the mapping.
Read more >
KeyError caused by a wrong attribute assignment within the ...
After the creation of your graph: G = nx.from_pandas_edgelist(filtered, 'Source', 'Target', edge_attr=True) df_pos = nx.spring_layout(G,k ...
Read more >
All other Tokyo fixes - Product Documentation | ServiceNow
Console error for users without roles or any active assessments or surveys to take, when navigating to the My Assessments and Surveys module....
Read more >
API Reference — fsspec 2022.11.0+13.g0974514.dirty ...
To read from multiple files you can pass a globstring or a list of paths, ... will be regarded as missing keys and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found