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

Simplified interface for custom metadata #104

Merged
merged 7 commits into from
Feb 7, 2024
Merged

Simplified interface for custom metadata #104

merged 7 commits into from
Feb 7, 2024

Conversation

dennisvang
Copy link
Owner

@dennisvang dennisvang commented Feb 7, 2024

Custom metadata as described in the TUF spec can be specified when adding a new bundle to a repository.

The high-level interface has been simplified slightly w.r.t. #100: users can now only add custom metadata to the archive, not to the patch (if any).

This makes sense, because the archive is the only thing a typical user should be interested in (patches are considered an internal implementation detail). If really necessary, the low-level Roles.add_or_update_target() can still be used to add custom metadata to patches.

Examples

On the repo side:

...
repo.add_bundle(
    new_version='2.3.4',
    new_bundle_dir='dist/myapp',
    custom_metadata=dict(foo='bar'),  # optional
)
...

The custom metadata ends up in the targets.json file as follows:

{
  "signatures": [
    "..."
  ],
  "signed": {
    "...": "...",
    "targets": {
      "...": {},
      "myapp-2.3.4.tar.gz": {
        "custom": {
          "foo": "bar"
        },
        "hashes": {
          "sha256": "..."
        },
        "length": 12345
      },
      "...": {}
    }
  }
}

On the client side, this metadata is made available via the TargetMeta class. Note that Client.check_for_updates() only ever returns a TargetMeta instance for the archive, regardless of whether a patch update or a full update will be performed.

For example,

...
new_archive_meta = client.check_for_updates()
if new_archive_meta:
    ...
    if new_archive_meta.custom:
        ...

fixes #99

and rename the other arg to custom_metadata
even though the keys are not used in current unit tests, they must be present for reproducibility, in case we want to update test data from a fresh installation
(otherwise we would get a mismatch between keys and metadata, so we would need to create all new keys and metadata every time)
@dennisvang dennisvang merged commit 61323f9 into master Feb 7, 2024
17 checks passed
@dennisvang dennisvang deleted the issue99 branch February 7, 2024 13:34
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.

add support for custom object in tuf targets metadata
1 participant