Commit graph

38 commits

Author SHA1 Message Date
Martin Vrachev
a872eb5b6d Hash bin delegation example: save versioned files
If we have a goal of making metadata that can just be served to clients,
then these (and the parent metadata) should have versioned filenames.
Change the file names of the delegated files in the
hashed_bin_delegation.py to versioned.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-07-21 22:39:31 +03:00
Martin Vrachev
b8ea2fb9b9 Add an example script about succinct roles usage
Add a basic example script showing all features of the succinct hash bin
delegations and the available API calls of SuccinctRoles.

The explanations are used to promote the usage of succinct hash bin
delegations by explaining it well enough so our users can understand
the API limitations and how to use them and at the same time I tried not
going into too many details of the SuccinctRoles math as its
implementation is inside tuf/api/metadata.py and there there are
explanations about that.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-07-21 22:39:31 +03:00
Martin Vrachev
bfcd3a54a2 Simplifications on hashed_bin_delegatio example
We no longer need or use SPEC_VERSION variable defined in the
begging of the script.

Additionally, I decided to add a small addition to the "roles"
type annotation as that gives better context to the syntax highlighter
of VS code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-07-21 22:33:46 +03:00
Martin Vrachev
28b6917739 Root and Targets key API changes
Here is the list of all breaking API changes:
1) The "role" and "key" arguments in "Root.add_key()" are in reverse
order - "key" becomes first and "role" second.
2) "Root.remove_key()" has been renamed to "Root.revoke_key()".
3) The "role" and "keyid" arguments in "Root.revoke_key()" are in
reverse order - "keyid" becomes first and "role" second.
4) The "role" and "key" arguments in "Targets.add_key()" are in reverse
order - "key" becomes first and "role" second.
5) "Targets.remove_key()" has been renamed to "Targets.revoke_key()".
6) The "role" and "keyid" arguments in "Targets.revoke_key()" are in
reverse order - "keyid" becomes first and "role" second.
7) In both methods "Targets.add_key()" and "Targets.revoke_key()" the
"role" argument becomes an optional with a default value of None.

Those changes are made in an effort to make those methods logical
for both cases when standard roles and succinct_roles are used.
The "Root" API change was done in order to preserve naming and argument
order consistency with "Targets" API.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-17 13:33:01 +03:00
Martin Vrachev
15cd42c0d6 Delegations: add support for succinct_roles
This commit contains 2 API changes in "Delegations" class from
tuf/api/metadata.py:
1. roles argment is made optional
2. unrecognized_fields argument becomes the 4-th rather than the 3-rd
as it used to be

In this commit, I add support for succinct_roles roles inside
Delegations class. This change is related to TAP 15 proposal.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-06-17 13:33:01 +03:00
Jussi Kukkonen
8071806e04 examples: Use the constructor default arguments
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-03-24 10:37:30 +02:00
Martin Vrachev
06118843ca Use spec version from tuf/api/metadata in examples
Replace the hardcoded specification version with the one defined inside
tuf/api/metadata.py

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-03-17 15:41:05 +02:00
lukpueh
31fd8d4f03
Merge pull request #1790 from lukpueh/rm-all
Rm all legacy
2022-02-04 14:01:53 +01:00
Jussi Kukkonen
4efd9496dc ngclient: Make DownloadErrors consistent
Fetcher interface should only raise DownloadErrors,
regardless of the implementation.
 * Make sure fetch() wraps non-DownloadError errors in a DownloadError
 * Make the abstract function private _fetch()
 * Try to be more consistent in doscstrings

This now makes the example client more sensible (when server does not
respond):
    $ ./client_example.py download qwerty
    ...
    Failed to download target qwerty: Failed to download url http://127.0.0.1:8000/metadata/2.root.json

(here the latter part of the error string comes from DownloadError
raised by FetcherInterface.fetch())

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2022-02-04 11:03:12 +02:00
Lukas Puehringer
9816c40d77 doc: update deprecation info in repo_example docs
Rephrase deprecation info in repo_example modules doc headers
to reflect that the deprecation has happened.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2022-02-03 10:00:22 +01:00
Martin Vrachev
a2f7b4588f Fix new space warning by black
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-02-01 12:29:50 +02:00
lukpueh
b2704a56a8
Merge pull request #1783 from MVrachev/drop-python3.6
Drop python3.6 and remove the usage of OrderedDict
2022-01-20 14:46:52 +01:00
Martin Vrachev
e3b267e2e0 Remove OrderedDict in favor of python3.7+ dict
After we drop support for python3.6 we can relly that dictionaries
preserve the insertion order:
https://docs.python.org/3.7/whatsnew/3.7.html

This means we can replace the usage of OrderedDict with a standard
dictionaries.

Something we have to keep in mind is that even thought the insertion
order is preserved the equality comparison for normal dicts is
insensitive for normal dicts compared to OrderedDict

For example:
>>> OrderedDict([(1,1), (2,2)]) == OrderedDict([(2,2), (1,1)])
False
>>> dict([(1,1), (2,2)]) == dict([(2,2), (1,1)])
True

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-01-19 18:19:56 +02:00
Martin Vrachev
4b61be9cf7 Add tuf/api/exceptions.py
Add tuf/api/exceptions.py for exceptions in the new code.
I copied the exceptions from tuf/exceptions.py with a few important
decisions:
1. I only added the exceptions that are used in the new code
2. I removed the general "Error" class as we can directly inherit
Exceptions
3. I tried grouping the exceptions by relevance
4. I removed the second argument "UnsignedMetadataError" as it's only
kept for backward compatibility and is not used
5. I tried following the new code style guidelines and linted the file
with our linters.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-01-19 16:52:19 +02:00
Kairo de Araujo
23534790cd docs: add examples to the RTD
This commit adds to the RTD the links references to source code
examples.
The examples are added to TUF ngclient Updater, Metadata and API
reference.
includes a seed for examples/README.md

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2022-01-18 13:14:02 +01:00
Jussi Kukkonen
2a6e773323 ngclient: Rename constructor arg
metadata_dir matches metadata_base_url better.

This is an API break for anyone using named arguments.

Fixes #1638

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-12-15 13:22:24 +02:00
lukpueh
8209189a44
Merge pull request #1700 from lukpueh/repo-examples-hbd
doc:  basic hash bin delegation repo example + test
2021-12-10 10:33:04 +01:00
Lukas Puehringer
ef388daa3a doc: clarify math in hash bin delegation example
Tries to clarify the introductory text in the hash bin delegation
example.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-12-10 10:13:42 +01:00
Kairo de Araujo
134441019c This commit fixes the verbosity (-v) levels.
without -v is ERROR logging, -v  WARNINGS logging, -vv INFO logging
and -vvv (+) DEBUG logging.

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-03 19:59:04 +01:00
Kairo de Araujo
183223e59c Simplify README, fix some flows and output
- Simplify README and better keywords
- Fix the verbosity
- Better docstrings
- Client flow for init and main are clear

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-03 19:59:01 +01:00
Kairo de Araujo
ca13d059b6 Single error handling for updater
To simple exemplify, the updater calls are added to a single block
that handles the exceptions

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-03 19:58:42 +01:00
Kairo de Araujo
4c37f1bc35 Removes the Python Client Example as WIP
This commit adds many comments from the WIP stage

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-03 19:58:42 +01:00
Kairo de Araujo
4c5581a800 Add a simple example handling TUF exceptions.
To highlight TUF ngclient exceptions.

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-03 19:58:42 +01:00
Kairo de Araujo
46629c4547 Implement a combination of print and logging
Using ``print`` for high-level client output
Option to see ``tuf.ngclient`` logging output

Update the README.

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-03 19:58:42 +01:00
Kairo de Araujo
9b4fcdb564 Added lint, rst to md, output
- Added the lint to examples
- README format moved from Restructuredtext to Markdown
- Removed the [INFO] and [ERROR] from output, to avoid confundint with
  logging structure

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-03 19:58:33 +01:00
Kairo de Araujo
ffe2c11fcf WIP: TUF Python Client Example/Tutorial
It is a simple example of TUF ngclient implementation.

This example contains a README.rst that is a tutorial/how-to-use
this simple client using static test data from TUF repository.

The code aims to be straightforward implementation, using basic
concepts from Python and Command Line Interface.

This is part of theupdateframework#1518

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-03 19:57:53 +01:00
Lukas Puehringer
b8cf1c0e37 doc: annotate types in hash bin delegation example
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-12-03 10:49:57 +01:00
Lukas Puehringer
e90acfe123 doc: basic hash bin delegation repo example + test
As 'repository_tool' and 'repository_lib' are being deprecated,
hash bin delegation interfaces are no longer available in this
implementation. The example code in this file demonstrates how to
easily implement those interfaces, and how to use them together
with the TUF metadata API, to perform hash bin delegation.

Note, the hash bin delegation logic in this example is largely
copied from repository_{lib, tool}, and modernized and simplified
for this purpose.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-12-03 10:33:24 +01:00
Lukas Puehringer
caffc415d1 doc: use sentence case in all repo example titles
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-12-03 10:33:24 +01:00
Martin Vrachev
1ae6a22b8e Start linting the examples folder
The examples folder currently contains a repository example and it's
good if we start linting its content and as a result add type
annotations.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-02 13:40:14 +02:00
Lukas Puehringer
190c21b65b doc: add repository example based on metadata API
As 'repository_tool' and 'repository_lib' are being deprecated,
repository metadata must to be created and maintained manually
using the low-level Metadata API. The added example code shall
serve as temporary replacement until a new repository tool is
available.

The sample code contains the following repo workflows:
 - creation of top-level metadata
 - target file handling
 - consistent snapshots
 - key management
 - top-level delegation and signing thresholds
 - target delegation
 - in-band and out-of-band metadata signing
 - writing and reading metadata files
 - root key rotation

Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Jussi Kukkonen <jku@goto.fi>

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-11-29 13:25:10 +01:00
Vladimir Diaz
709ada1e65
Remove example metadata
Instead of having duplicate metadata in examples/ and tests/repository_data, retain only the metadata in tests/repository_data and link to them from METADATA.md
2017-10-11 10:38:08 -04:00
Artiom Baloian
b793c81739 Added simple_settings, now it is a requirement of TuF.
Rename conf.py into the settings.py an changed import call.
2016-11-01 15:38:40 -04:00
Artiom Baloian
8247a02737 Moved TuF exceptions and schem into the ssl_commons 2016-10-31 11:58:05 -04:00
Vladimir Diaz
1f4f7d4b63 Add a README to the "examples" directory.
Also warn users that the examples might not be fully up-to-date, and
to please consult the examples used by the unit tests.
2015-11-17 15:28:18 -05:00
Vladimir Diaz
ab95a4b3aa [WIP] Python 2+3 support.
Python 2+3 unicode.
libraries.
The following modules (and their tests) work in PY2.7+3.3:
keydb, hash, formats, mirrors
2014-04-29 14:27:34 -04:00
vladdd
7b4c3218e1 Remove extraneous example files. 2014-04-19 14:39:47 -04:00
vladdd
5f94d5be0d Support ISO 8601, vendor iso8601, clean codebase. 2014-04-19 14:27:53 -04:00