Repository navigation
Conversation
|
I am not sure how to resolve the mypy issue: https://github.com/theupdateframework/python-tuf/runs/5467473728?check_suite_focus=true |
Pull Request Test Coverage Report for Build 2023081596
💛 - Coveralls |
Directories do not become importable packages automatically. You need at least an empty |
799bd3e to
b87887e
Compare
|
@jku I fixed the mypy issues. The downside to this is that the metadata files won't be human-readable. |
That sounds highly undesirable... not to mention that it sounds like a bug somewhere. What is the inconsistency? |
There was a problem hiding this comment.
Hmm, turns out I have opinions about this. I think we can both
- reduce complexity and
- make this more prepared for future additions
Some suggestions:
- keys that are meant for use in multiple places should not be named for their role (this is the reason I don't want to use the legacy test keys). they should be named for the type of key they are (like "ed25519_1") so that individual tests, or in this case generating functions, can decide what they use the key for.
- The CLI complexity is unused: let's not have arguments unless we really need them. Currently neither argument is needed
- The generated data (files/roles) are now hard coded in four different functions: if I next want to add a single file, I would have to modify all four functions. This cannot be the optimal design. I think the object does not need attributes at all:
generate_repository()could just do everything it needs to (either write the files it wants to write or validate the same files, depending on the argument): once the function is finished, no-one else needs to know which files it touched. - generate_repository() calls the data it generates a repository and I get the aim of providing examples of python-tuf repositories... but I think it may be premature:
- Most importantly we don't actually check that it's a valid repository. It looks like one but I can only tell because it's the simplest possible, anything more complex is going to be hard to estimate. The filenames are at least incorrect for a consistent_snapshot repository
- what if I want to add e.g. a file that tests all keytypes we support? Do I have to create a complete repository to add that one file? Looking at the metadata types, timestamp probably only needs one test case but targets might need multiple different files...
- Would a better approach be to have one or more methods to generate just a bunch of independent metadata files that are not called a repository, and later we add repository support when we can reasonably test it?
adea8f5 to
45f20be
Compare
|
@jku I think I have simplified the test script a lot. |
| md_targets: Metadata[Targets] = Metadata(targets, {}) | ||
|
|
||
| for md in [md_root, md_timestamp, md_snapshot, md_targets]: | ||
| assert isinstance(md, Metadata) |
There was a problem hiding this comment.
This check is required from mypy otherwise there is a warning:
tests/generated_data/generate_md.py:142: error: Argument 1 to "verify_generation" of "MetadataGenerator" has incompatible type "object"; expected "Metadata[Any]" [arg-type]
lukpueh
left a comment
There was a problem hiding this comment.
I commented a couple of observations/questions, mostly about further simplifying the script.
But maybe I'm missing the big picture. In what direction should the script scale?
I'd probably make it just a collection of generate_*_metadata functions, plus helper functions to be re-used by those generation function, like your verification function.
| # Dump metadata files in a human readable format. | ||
| self.serializer = JSONSerializer() | ||
|
|
||
| def verify_generation(self, md: Metadata, path: str) -> None: |
There was a problem hiding this comment.
🎉 I like this function. It's a good example for factoring out functionality that could be in generate_all_files, so that it can also be used re-used by other metadata generating functions as well.
I did it that way before and @jku mentioned that there is no sense in having separate functions now when we generate only one variation per role. |
45f20be to
14d3f1a
Compare
Oh, I probably wasn't clear. I didn't mean that you should split |
62d15d3 to
e763b47
Compare
lukpueh
left a comment
There was a problem hiding this comment.
Cool! Thanks for the updates, Martin! I think it's easier to review and use now, without making it much harder to scale later. Here are two more comments about signing...
| os.mkdir(OUT_DIR) | ||
|
|
||
| SERIALIZER = JSONSerializer() | ||
| key_info = copy.deepcopy(keys["ed25519_0"].to_securesystemslib_key()) |
There was a problem hiding this comment.
Because at keys["ed25519_0"] we have the dictionary information of a dict containing a dictionary of a dictionary.
More precisely the keyval of a key is again a dictionary and a simple copy.copy() doesn't work here.
There was a problem hiding this comment.
What do you mean by "doesn't work here"? And why do you need to copy it at all?
|
|
||
| for md in [md_root, md_timestamp, md_snapshot, md_targets]: | ||
| assert isinstance(md, Metadata) | ||
| md.sign(SIGNER) |
There was a problem hiding this comment.
Why do you sign all metadata files with the root key? Why not sign timestamp with timestamp, snapshot with snapshot and targets with targets keys?
There was a problem hiding this comment.
Changed that.
Initially (while there was a class), it was to reuse the signer.
There was a problem hiding this comment.
I am not sure I understand. So initially you wanted to sign with one key on purpose?
There was a problem hiding this comment.
Yea, because the files are not supposed to be read as a stand-alone repository, but as separate independent files, and as such we can reuse the same key as many times as we want.
The only reason I defined 4 keys is because of the root roles.
A really specific bug occurred on CI runs on all Windows machines https://github.com/theupdateframework/python-tuf/runs/5467473050?check_suite_focus=true where we weren't able to verify that what was generated is the same as the stored on Git. After research with Jussi, we found out that the problem comes not from the content of the file that was generated, but because on Windows Git proactively replaced all line endings for text files with CRLF symbol ("\r") this made the locally stored JSON files different from the one generated. We want to make sure such bugs doesn't occur again and that's why we disable this behavior for all JSON files. Signed-off-by: Martin Vrachev <[email protected]>
I created a new script called "generate_md.py" which can be used to easily generate a repository. Additionally, I created a new test file making sure that the locally stored metadata files and the newly generated metadata roles are the same. This will allow us to test that we are not changing the metadata file structure when making changes. Signed-off-by: Martin Vrachev <[email protected]>
e763b47 to
545ff37
Compare
| targets = Targets(1, SPEC_VERSION, EXPIRY, {}) | ||
| md_targets: Metadata[Targets] = Metadata(targets, {}) | ||
|
|
||
| i = 0 |
There was a problem hiding this comment.
hint: enumerate() gives you a running index.
There was a problem hiding this comment.
I remembered it just when I sent it, thanks.
| for md in [md_root, md_timestamp, md_snapshot, md_targets]: | ||
| assert isinstance(md, Metadata) | ||
| key_info = copy.deepcopy((keys[f"ed25519_{i}"].to_securesystemslib_key())) | ||
| key_info["keyval"]["private"] = private_values[0] |
There was a problem hiding this comment.
| key_info["keyval"]["private"] = private_values[0] | |
| key_info["keyval"]["private"] = private_values[i] |
?
There was a problem hiding this comment.
I think you could avoid deepcopy, to_securesystemslib_key and the assignment of private_values[i] if you use the private key dictionary defined above (before passing it to from_securesystemslib_key).
|
Not sure why, but GitHub doesn't see my update which exists on the same branch on my fork... |
Related to: #1806
Description of the changes being introduced by the pull request:
I created a new script called "generate_md.py" which can be used
to easily generate a repository. Additionally, I created a new
test file making sure that the locally stored metadata files and
the newly generated metadata roles are the same.
This will allow us to test that we are not changing the metadata
file structure when making changes.
Signed-off-by: Martin Vrachev [email protected]
Please verify and check that the pull request fulfills the following
requirements: