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

Add missing method args docs in metadata API #1620

Merged
merged 1 commit into from
Oct 20, 2021

Conversation

lukpueh
Copy link
Member

@lukpueh lukpueh commented Oct 14, 2021

Fixes #1599

Description of the changes being introduced by the pull request:
Affected methods are:

  • Root.add_key()
  • Root.remove_key()
  • Targets.add_key()
  • Targets.remove_key()
  • DelegatedRole.is_delegated_path()
  • Key.from_securesystemslib_key()

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

Affected methods are:

- Root.add_key()
- Root.remove_key()
- Targets.add_key()
- Targets.remove_key()
- DelegatedRole.is_delegated_path()
- Key.from_securesystemslib_key()

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
@coveralls
Copy link

coveralls commented Oct 14, 2021

Pull Request Test Coverage Report for Build 1341144219

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.36%

Totals Coverage Status
Change from base Build 1337495560: 0.0%
Covered Lines: 3718
Relevant Lines: 3746

💛 - Coveralls

removing the private key from keyval.

Args:
key_dict: A key in securesystemlib dict representation.
Copy link
Member Author

Choose a reason for hiding this comment

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

I admit that the description I added is not particularly helpful, but I'm unsure what to do. Can we maybe quickly rethink the API design here?

From what I see, the relevant difference between from_dict and from_securesystemslib_key is that the former accepts any keyval (including private ones ... in the long run we will probably want to choke here, right?), whereas the latter removes keyval["private"], if present.

So maybe we can rename from_securesystemslib_key to from_private_key?

Also, the method becomes a lot easier if we just pop keyval["private"] instead of calling the mystic format_keyval_to_metadata function, which does other things that we don't really care for (e.g. vet values using schema, temporarily assign keyid_hash_algorithms, etc.).

@avelichka, would you care to weigh in? I'm happy to re-phrase the docs here or with #1600, once I understand the purpose of this method better. :)

Copy link
Member

Choose a reason for hiding this comment

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

Adding the method was my suggestion, and avoiding poking the securesystemslib key_dict internals may have been as well: none of us were probably entirely sure how much of the dict return value is sort of "implicitly API" or if it's a secursystemslib implementation detail -- are we going to be in trouble later if we just start removing things there. I think you've got a much better idea of this so feel free to propose something.

The purpose is that we have needed roughly the following code in multiple places (this is from test RepositorySimulator where we generate new Metadata):

    def create_key(self) -> Tuple[Key, SSlibSigner]:
        sslib_key = generate_ed25519_key()
        return Key.from_securesystemslib_key(sslib_key), SSlibSigner(sslib_key)

It turned out quite easy to make the mistake of including the private key in the TUF metadata :) and I wanted to make it easier to avoid that...

Other solutions for this are totally fine too.

Copy link
Member

Choose a reason for hiding this comment

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

oh, and if it wasn't clear: some of the places where this is needed are outside of python-tuf: so developers using python-tuf need to be able to do this so it felt like a function in Metadata API was a good idea even if del sslib_key["private"] probably would have worked fine

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the context, @jku! I'll try to condense some of this in the docstring with #1600.

@lukpueh
Copy link
Member Author

lukpueh commented Oct 14, 2021

While skimming the the API Reference on RTD I noticed more missing args oneliners in:

{Target,Timestamp,Snapshot}.update
MetadataDeserializer.deserialize
MetadataSerializer.serialize
SignedSerializer.serialize
JSONDeserializer.deserialize
JSONSerializer.serialize
CanonicalJSONSerializer.serialize

Our style guide says, that these oneliners may be omitted if obvious, but if we do so, we should probably fix the RTD-rendering, see e.g. incomplete Parameters sections in tuf.api.serialization).

Happy to fix here or ticketize and fix in a follow-up.

@jku
Copy link
Member

jku commented Oct 20, 2021

On the other missing args, no strong opinions on the documentation but I'll share my thoughts...

I've avoided working on the serialization so far: it is sort of part of the same API but still not as critical as the metadata module itself. Looking at serialization is only necessary if

  1. there's a bug so you're looking at code anyway
  2. you're creating a new serialization implementation... so you're looking at code anyway

{Targets,Timestamp,Snapshot}.update() would be good to document, but they are also something I'd like to take a good hard look at: some of them are not great API in my opinion. As an example Targets.update():

  • the current implementation is literally a one-liner that modifies a public dict attribute: we could document doing that instead and have a smaller API surface
  • it inserts or replaces the TargetFile... but a Targets handles both TargetFiles and delegations: what if I wanted to modify delegations instead? is it obvious that TargetFile needs a function but delegations do not?

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.

LGTM.

If you'd like the sslib-key-to-tuf-public-key transform to be redesigned, maybe a new issue/pr makes sense?

@lukpueh
Copy link
Member Author

lukpueh commented Oct 20, 2021

Thanks for the review, @jku!

Re serialization API: I'm fine with leaving the docstrings as they are.
Re {Targets,Timestamp,Snapshot}.update(): I agree with you and I remember that we had a discussion about this in a related PR. Let me dig that up and create an issue.
Re from_securesystemslib_key: I'm fine with leaving it as is and will try to add some of you insights from above to the docs in #1600

@lukpueh lukpueh merged commit 0cf6ba2 into theupdateframework:develop Oct 20, 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.

metadata API: add missing arguments docs
3 participants