Commit graph

4292 commits

Author SHA1 Message Date
Teodora Sechkova
e54ed249f5 Add docstrings in Updater
Add some missing docstrings in updater.py

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-05-21 13:07:27 +03:00
Jussi Kukkonen
b49d841673
Merge pull request #1405 from jku/ngclient-readme
ngclient: Update README
2021-05-21 11:57:33 +03:00
Jussi Kukkonen
e41a2de1e8
Merge pull request #1406 from jku/remove-pylint-disable
ngclient: Remove pylint disable
2021-05-21 11:56:34 +03:00
Jussi Kukkonen
000a184616 ngclient: Update README
Fixes #1404

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-21 11:54:56 +03:00
Jussi Kukkonen
534021bdf1 ngclient: Fix logging to remove pylint disable
Remove pylint disable logging-no-lazy, fix remaining non-lazy logging
(ngclient/updater.py still contains some but pylint does not notice
them: These will be fixed in issue #1400)

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-21 11:28:46 +03:00
Jussi Kukkonen
5f37eb36e6
Merge pull request #1401 from sechkova/dirs-and-names
Experimental client: renaming
2021-05-21 10:45:00 +03:00
Teodora Sechkova
18c527241c Omit ngclient from coverage check
Restore coverage back to 97% but omit ngclient
form the overall score until tests are implemented.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-05-21 10:00:00 +03:00
Teodora Sechkova
d57d36f4bb Combine paths in tox.ini
Use the same call of black, isort, pylint to cover
multiple directories.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-05-21 10:00:00 +03:00
Teodora Sechkova
3f1aa10dbd Expose client public classes from __init__.py
Only "Updater" and "FetcherInterface" are considered
public classes of the client. Exposing them in __init__.py
makes usage and access simpler.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-05-21 10:00:00 +03:00
Teodora Sechkova
c29051cc4b Move non-public modules to nglient/_internal
Separate public/private API. Keep modules
containing the piblic classes in the main client
directory and move the rest to _internal.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-05-21 10:00:00 +03:00
Teodora Sechkova
c64a6f92c1 Rename client_rework to ngclient
The current client and the next-gen client should
coexist in the same repository during the ongoing
development of the latter.

Looking for a name which is client-related,
short, meeting PEP8 package names requirements.
Currently "ngclient" seems to fit in until a
better proposal comes.

Rename updater_rework.py to updater.py

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-05-21 10:00:00 +03:00
Jussi Kukkonen
34b5e5294f
Merge pull request #1403 from sechkova/merge-develop-into-exp-client
Merge develop into experimental-client
2021-05-21 08:48:44 +03:00
Teodora Sechkova
38ce083149
Add fixes after merging develop
Fixes incorrct access to MetaFile and TargetFile
after the merge of develop into experimetnal-client
branch.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-05-20 18:26:49 +03:00
Teodora Sechkova
3bee15e2e0 Merge branch 'develop' into merge-develop-into-exp-client 2021-05-20 18:00:54 +03:00
Jussi Kukkonen
db02fa6c59
Merge pull request #1396 from jku/experimental-client-use-bundle
Experimental client: use bundle
2021-05-20 15:45:26 +03:00
Jussi Kukkonen
d35fc27b0a New updater: Update comments
Mostly remove comments that provide little value after all the changes.
Also remove a unused variable from a test.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-20 15:41:24 +03:00
Jussi Kukkonen
f935ea33da
Merge pull request #1329 from MVrachev/new-api-classes
New metadata API: add MetaFile and TargetFile classes
2021-05-19 14:23:52 +03:00
Martin Vrachev
15bf88231d Remove testing "update()" with "version" only
We have tests which make sure we can use `Timestamp.update()` and
`Snapshot.update()` with MetaFile instance storing only version
(because length and hashes are optional).
Those tests were created to make sure that we are actually supporting
optional hashes and length when we call `update` for those classes, but
after we changed the `update()` signature to accept `MetaFile` instance
the tests are obsolete.
The reason is that length and hashes can be optional because of the
MetaFile implementation, no the update function itself and we have
other tests validating creating a MetaFie instance without hashes and
length.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-19 13:21:32 +03:00
Martin Vrachev
37de69050a Change "update()" argument types
Currently, when we call Targets/Snapshot/Timestamp.update() we are
passing all of the necessary values to create MetaFile/Targets File
respectively.
This is not needed, given that one of the reasons we have created
MetaFile and TargetFile is to make the API easier to use.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-19 13:21:32 +03:00
Martin Vrachev
aaa5bb4fc0 Disable "C0302" for tuf/api/metadata.py
Disable the "C0302: Too many lines in module" warning which warns for modules
with more 1000 lines, because all of the code here is logically connected
and currently, we are above 1000 lines by a small margin.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-19 13:21:32 +03:00
Martin Vrachev
408732f4ff Add MetaFile/TargetFile specific tests
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-19 13:21:32 +03:00
Martin Vrachev
60bbb165a8 New API: Add TargetFile class
In the top-level metadata classes, there are complex attributes such as
"meta" in Targets and Snapshot, "key" and "roles" in Root etc.
We want to represent those complex attributes with a class to allow
easier verification and support for metadata with unrecognized fields.
For more context read ADR 0004 and ADR 0008 in the docs/adr folder.

As written in the spec "targets" in "targets.json" has defined the
"custom" field serving the same purpose as "unrecognized_fields" in the
implementation.
That's why to conform against the spec and support "custom" and allow
"unrecognized_fields" everywhere where it's not sensitive we can define
custom as property which actually access data stored in
unrecognized_fields.
For context read ADR 8 in tuf/docs/adr.

Additionally, after adding the TargetFile class, when we create a
Targets an object we are now calling from dict twice - one for the main
Targets class and one for each of the complex attributes
TargetFile.from_dict() and Delegations.from_dict().
Given that the "from_dict" methods have the side effect of destroying
the given dictionary, we would need to start using deepcopy()
for our tests.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-19 13:21:31 +03:00
Martin Vrachev
3771a77ffe New API: Add MetaFile class
In the top-level metadata classes, there are complex attributes such as
"meta" in Targets and Snapshot, "key" and "roles" in Root etc.
We want to represent those complex attributes with a class to allow
easier verification and support for metadata with unrecognized fields.
For more context read ADR 0004 and ADR 0008 in the docs/adr folder.

Additionally, after adding the MetaFile class, when we create an object
we are now calling from dict twice - one for the main class (Timestamp,
Snapshot) and one for the pacticular complex attribute -
MetaFile.from_dict(). Given that the "from_dict" methods have the
side effect of destroying the given dictionary, we would need to
start using deepcopy() for our tests.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-19 13:04:24 +03:00
Jussi Kukkonen
8348523b77
Merge pull request #1394 from MVrachev/optional-consistent-snapshot
Metadata API: Make consistent_snapshot optional
2021-05-18 21:11:57 +03:00
Jussi Kukkonen
2bbf5bc178 tests: Cleanup in new Updater tests
Add test for a refresh with just a local root.json.

Remove unused code. Add docstrings for raised exceptions, add TODOs for
the missing exception handling.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-18 20:56:10 +03:00
Jussi Kukkonen
1d45c2aa2c New Updater: use the MetadataBundle
Use the MetadataBundle to verify metadata validity.
* Updater now handles reading metadata files (from filesystem as
  well as network
* Updater feeds bytes to MetadataBundle for verification
* Updater persists data on disk after it had been verified

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-18 20:56:02 +03:00
Jussi Kukkonen
d002dcdb8f
Merge pull request #1390 from jku/no-falsy-tests-for-none
Avoid using falsy tests for None
2021-05-18 20:32:59 +03:00
Jussi Kukkonen
8bb704b166
Merge pull request #1355 from jku/experimental-metadata-bundle
experimental client: Add MetadataBundle
2021-05-18 20:30:25 +03:00
Jussi Kukkonen
377eac18f6 MetadataBundle: Improve docstrings
Document arguments and exceptions, improve prose in general. Remove
mention of local file deletion now that file IO is not done here.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-18 20:09:53 +03:00
Martin Vrachev
de2644f3d0 Breaking: new API: consistent_snapshot optional
NOTE: making consistent_snapshot optional requires using a default value
for the argument in __init__ in Root and thus consistent_snapshot should
be rearranged in the end.
Read more: https://github.com/theupdateframework/tuf/pull/1394#issuecomment-842134961

From chapter 7 in the spec (version 1.0.17)
"Finally, the root metadata should write the Boolean
"consistent_snapshot" attribute at the root level of its keys of
attributes.
If consistent snapshots are not written by the repository,
then the attribute may either be left unspecified or be set to the
False value. Otherwise, it must be set to the True value."

We want to make sure we support repositories
without consistent_snapshot set.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-05-17 11:41:52 +03:00
Jussi Kukkonen
f2cff951a6 MetadataBundle: Don't do any file IO
Remove file IO from MetadataBundle:
* This make the bundle API very clear and easy to understand
* This means caller must now read from and persist data to disk
  but initial prototypes suggest this won't make Updater too
  complex

This change is something we can still back out from if it turns out to
be the wrong decision: the file-persisting MetadataBundle has been tested
and works fine.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 12:30:06 +03:00
Jussi Kukkonen
6b53ac78d0 Make BadHashError derive from RepositoryError
This is backwards-compatible and means that most (all?) errors resulting
from suspicious or broken metadata are now RepositoryErrors.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 12:28:50 +03:00
Jussi Kukkonen
a371258be8 MetadataBundle: Use builtin errors when possible
There's on value in using custom errors when builtins work.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
b86d1f733f MetadataBundle: Raise instead of returning bool
The bundle should now raise
* derivatives of RepositoryError on failures that are likely a result
  of server error or a malicious server
* RuntimeErrors if calls were made when they are not possible
* ValueErrors if arguments are invalid

last two are callers errors and avoidable.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
112f3b6a03 MetadataBundle: Handle Deserialization errors
because we are deserializing, not serializing.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
876fda1bb2 MetadataBundle: Add comments about the process
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
8d0245ab30 MetadataBundle: Use type, not _type
Signed now has "type" attribute, use that.

Also remove another pylint disable that is no longer needed (logging is
now old style).

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
3b30d085ee MetadataBundle: Store reference time earlier
Spec says reference time should be the beginning of the process: do
that.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
eb648d19bc MetadataBundle: Save original files on disk
Don't use the serialized format as that won't match any hashes in
"meta".

Add basic tests for updating metadata.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
2d155faae6 MetadataBundle: Change ValueErrors to RuntimeErrors
As the metadata type is no longer an argument, these are not
ValueErrors.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
f8b714d167 Metadata API: Don't do equality comparisons on containers
Use either "if X is not None:" or a try-except instead of a "if X:".

I believe Targets.from_dict() was not really broken with previous code
but it looks suspicious and did fail the added test with a strange
exception: I expect the from_dict() methods to mainly fail with
KeyErrors, ValueErrors or AttributeErrors if file format structure
is incorrect.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
112b333bba Metadata API: Fix DelegatedRole serialization issue
A DelegatedRole with paths=[] fails to serialize correctly (paths is not
included in the output json).

Fix the issue, modify tests to notice a regression.

Fixes #1389

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
0bbfe038cf tests: Add minimal test case for Bundle
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
66fa37b259 MetadataBundle: Update to API changes
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
b6817886cc Improve documentation
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-16 10:48:59 +03:00
Jussi Kukkonen
14f5957eee Metadata API: Don't do equality comparisons on containers
Use either "if X is not None:" or a try-except instead of a "if X:".

I believe Targets.from_dict() was not really broken with previous code
but it looks suspicious and did fail the added test with a strange
exception: I expect the from_dict() methods to mainly fail with
KeyErrors, ValueErrors or AttributeErrors if file format structure
is incorrect.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-14 16:12:50 +03:00
Jussi Kukkonen
aa480b1280 Metadata API: Fix DelegatedRole serialization issue
A DelegatedRole with paths=[] fails to serialize correctly (paths is not
included in the output json).

Fix the issue, modify tests to notice a regression.

Fixes #1389

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-14 14:02:29 +03:00
Jussi Kukkonen
800b088212 MetadataBundle: Fix loads of linting issues
Lots of fixes, mostly obvious ones. The trickier ones and pylint
disables have comments added to explain them.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-14 10:06:01 +03:00
Jussi Kukkonen
e26772cc6d Remove unnecessary directory check at startup
* Loading root.json will fail just as descriptively
* As long as Bundle doesn't implement bootstrapping
  the local repo, there's also no need to create
  missing directories

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-14 10:06:01 +03:00
Jussi Kukkonen
1d22d5aedc MetadataBundle: Improve hints and docs
Complete the type hints for MetadataBundle.
Slightly improve documentation.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-05-14 10:06:01 +03:00