Skip to content

Take fileinfo kwarg in add_target and add_target_to_bin methods #1003

@lukpueh

Description

@lukpueh

Description of issue or feature request:

The repository tool add_target and add_target_to_bin methods can be used to add target paths to the targets metadata in memory. The corresponding target file hashes are produced later e.g. on write or writeall.

It should be possible to add target paths using those functions, along with target file hashes that are generated out of band (this is required for PEP 458).

Current behavior:
add_target and add_target_to_bin don't take a fileinfo argument.

Implementation hint: roledb currently has a paths dictionary, where target paths are listed as dict keys and the optionally passed custom dict as value:

{"paths" : {"<TARGET PATH>": "custom": <CUSTOM DICT>}, ...}}

Expected behavior:

add_target and add_target_to_bin take an optional fileinfo argument that adheres to tuf.formats.FILEINFO_SCHEMA.

Implementation hint: probably requires a change to roledb to store all fileinfo properties, e.g.:

{
"paths" : {
  "<TARGET PATH>": {
    "length": <LENGTH>,
    "hashes": <HASHES>,
    "version": <VERSION>,
    "custom": <CUSTOM DICT>
    }, ... 
  }
}

Discussion:

  • fileinfo as returned by tuf.formats.make_fileinfo optionally includes the custom field (see above). It feels redundant to have add_target accept both custom and fileinfo. If we are fine with an interface change, I suggest to replace the former with the latter. Otherwise, we can have both, and fail if someone passes both custom and fileinfo

  • Functions that take multiple target paths as list of string, i.e. add_targets, delegate, delegate_hashed_bins, IMO don't need to provide this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions