Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
repos:
- repo: https://github.com/psf/black
rev: "22.12.0"
rev: "26.3.1"
hooks:
- id: black
exclude: ^taf/tools/
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: "5.0.4"
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

ci_require = [
"bandit>=1.6.0",
"black==22.12.0",
"black==26.3.1",
"coverage==4.5.3",
"pre-commit>=1.18.3",
"pytest-cov==2.7.1",
Expand All @@ -24,7 +24,7 @@

executable_require = ["lxml"]

dev_require = ["bandit>=1.6.0", "black==22.12.0", "pre-commit>=1.18.3"]
dev_require = ["bandit>=1.6.0", "black==26.3.1", "pre-commit>=1.18.3"]

tests_require = [
"pytest==8.*",
Expand Down
3 changes: 1 addition & 2 deletions taf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Add platform-dependent libraries to the path.
"""
"""Add platform-dependent libraries to the path."""

import sys

Expand Down
1 change: 0 additions & 1 deletion taf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import datetime
from typing import List, Optional


TARGETS_DIRECTORY_NAME = "targets"
METADATA_DIRECTORY_NAME = "metadata"

Expand Down
1 change: 0 additions & 1 deletion taf/repositoriesdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from taf.log import taf_logger
from taf.models.types import Commitish


# Target repositories db

# {
Expand Down
1 change: 0 additions & 1 deletion taf/tests/test_api/metadata/api/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from tuf.api.metadata import Root, Snapshot, Timestamp, Targets
from taf.yubikey.yubikey_manager import PinManager


AUTH_REPO_NAME = "auth"


Expand Down
1 change: 0 additions & 1 deletion taf/tests/test_api/targets/api/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)
from taf.yubikey.yubikey_manager import PinManager


AUTH_REPO_NAME = "auth"


Expand Down
1 change: 0 additions & 1 deletion taf/tests/test_git/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from taf.utils import on_rm_error
from taf.tests.conftest import TEST_DATA_REPOS_PATH


TEST_DIR = Path(TEST_DATA_REPOS_PATH, "test-git")
REPO_NAME = "repository"
CLONE_REPO_NAME = "repository2"
Expand Down
6 changes: 5 additions & 1 deletion taf/tests/test_repository/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ def _check_values(repo, json_data):
else:
assert repo_value == attr_value

for (repo_library_dir, repo_name, repo_path,) in (
for (
repo_library_dir,
repo_name,
repo_path,
) in (
(library_dir, name, None),
(None, None, Path(library_dir, name)),
):
Expand Down
1 change: 0 additions & 1 deletion taf/tests/test_updater/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

from tuf.api.metadata import Timestamp


KEYS_DESCRIPTION = str(TEST_INIT_DATA_PATH / "keys.json")


Expand Down
1 change: 0 additions & 1 deletion taf/tests/test_updater/test_handlers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from tuf.ngclient._internal import trusted_metadata_set
from pytest import fixture


HANDLERS_DATA_INPUT_DIR = TEST_DATA_PATH / "handler_inputs"
TYPES_DIR = TEST_DATA_PATH / "types"
UPDATE_TYPES_DIR = TYPES_DIR / "update"
Expand Down
1 change: 0 additions & 1 deletion taf/tests/test_updater/test_handlers/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
update_update_schema,
)


schema_store = {
repo_update_schema["$id"]: repo_update_schema,
update_update_schema["$id"]: update_update_schema,
Expand Down
1 change: 0 additions & 1 deletion taf/tests/test_updater/test_update_library/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from tuf.ngclient._internal import trusted_metadata_set
from pytest import fixture


original_tuf_trusted_metadata_set = trusted_metadata_set.TrustedMetadataSet

NAMESPACE1 = "namespace1"
Expand Down
1 change: 0 additions & 1 deletion taf/tests/tuf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path


# TODO: de-duplicate with conftest.py constants
TEST_DATA_PATH = Path(__file__).parent.parent / "data"
1 change: 0 additions & 1 deletion taf/tests/tuf/test_keys/test_yk.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from securesystemslib.exceptions import UnverifiedSignatureError


# Test data to sign
_DATA = b"DATA"
_NOT_DATA = b"NOT DATA"
Expand Down
6 changes: 2 additions & 4 deletions taf/tools/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def add(


def remove_dependency_command():
@click.command(
help="""Remove a dependency from dependencies.json.
@click.command(help="""Remove a dependency from dependencies.json.
Update and sign targets metadata, snapshot and timestamp using yubikeys or keys loaded from the specified keystore location.

`taf dependencies remove --path auth-path dependency-name --keystore keystore-path`
Expand All @@ -117,8 +116,7 @@ def remove_dependency_command():

`taf dependencies remove dependency-name --keystore keystore-path`

if inside an authentication repository"""
)
if inside an authentication repository""")
@find_repository
@catch_cli_exception(handle=TAFError)
@click.argument("dependency-name")
Expand Down
30 changes: 10 additions & 20 deletions taf/tools/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def exit_profiler():


def create_repo_command():
@click.command(
help="""
@click.command(help="""
\b
Create a new authentication repository at the specified location by registering
signing keys and generating initial metadata files. Information about the roles
Expand Down Expand Up @@ -154,8 +153,7 @@ def create_repo_command():

If the test flag is set, a special target file will be created. This means that when
calling the updater, it'll be necessary to use the --authenticate-test-repo flag.
"""
)
""")
@catch_cli_exception(handle=TAFError, remove_dir_on_error=True)
@click.argument(
"path",
Expand Down Expand Up @@ -195,8 +193,7 @@ def create(path, keys_description, keystore, no_commit, test, pin_manager):


def clone_repo_command():
@click.command(
help="""
@click.command(help="""
Validate and clone authentication repositories and target repositories. URL of the
remote authentication repository must be specified when calling this command. If the remote repository's URL is a file system path, the --from-fs flag must be used.

Expand Down Expand Up @@ -228,8 +225,7 @@ def clone_repo_command():
The update can be performed in strict or non-strict mode. Strict mode is enabled by specifying
--strict, which will raise errors during the update if any warnings are found. By default, --strict
is disabled.
"""
)
""")
@catch_cli_exception(handle=UpdateFailedError, skip_cleanup=True)
@click.argument("url")
@common_update_options
Expand Down Expand Up @@ -326,8 +322,7 @@ def clone(


def update_repo_command():
@click.command(
help="""
@click.command(help="""
Update and validate local authentication repositories and target repositories.

If the authentication repository and the target repositories are in the same root directory,
Expand Down Expand Up @@ -357,8 +352,7 @@ def update_repo_command():
The update can be performed in strict or non-strict mode. Strict mode is enabled by specifying
--strict, which will raise errors during the update if any warnings are found. By default, --strict
is disabled.
"""
)
""")
@find_repository
@catch_cli_exception(handle=UpdateFailedError, skip_cleanup=True)
@common_update_options
Expand Down Expand Up @@ -448,16 +442,14 @@ def update(


def validate_repo_command():
@click.command(
help="""
@click.command(help="""
Validates an authentication repository which is already on the file system
and its target repositories (which are also expected to be on the file system).
Does not clone repositories, fetch changes or merge commits.

Validation can be in strict or no-strict mode. Strict mode is set by specifying --strict, which will raise errors
during validate if any/all warnings are found. By default, --strict is disabled.
"""
)
""")
@find_repository
@catch_cli_exception(handle=UpdateFailedError)
@click.option(
Expand Down Expand Up @@ -558,8 +550,7 @@ def validate(


def reset_repo_command():
@click.command(
help="""
@click.command(help="""
Resets an authentication repository which is already on the file system
and its target repositories (which are also expected to be on the file system)
to a specified snapshot in the past.
Expand All @@ -570,8 +561,7 @@ def reset_repo_command():
in --comit flag if reset is successful.
If --force flag is set, any uncommited changes or unstaged files will be removed,
else an error will be raised if there are any those.
"""
)
""")
@find_repository
@catch_cli_exception(handle=UpdateFailedError)
@click.option(
Expand Down
36 changes: 12 additions & 24 deletions taf/tools/roles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@


def add_roles_command():
@click.command(
help="""
@click.command(help="""
Add new delegated target roles. Allows optional specification of each role's properties through a JSON configuration file.

Configuration file (JSON) can specify:
Expand Down Expand Up @@ -68,8 +67,7 @@ def add_roles_command():
}
}
}
"""
)
""")
@find_repository
@catch_cli_exception(handle=TAFError)
@common_repo_edit_options
Expand Down Expand Up @@ -116,11 +114,9 @@ def add_roles(


def export_roles_description_command():
@click.command(
help="""
@click.command(help="""
Export roles-description.json file based on the
"""
)
""")
@find_repository
@catch_cli_exception(handle=TAFError)
@click.option(
Expand Down Expand Up @@ -308,17 +304,15 @@ def remove_delegated_paths(


def add_signing_key_command():
@click.command(
help="""
@click.command(help="""
Add a new signing key. This will make it possible to a sign metadata files
corresponding to the specified roles with another key. Although private keys are
used for signing, key identifiers are calculated based on the public keys. This
means that it's necessary to enter the public key in order to register
a new signing key. Public key can be loaded from a file, in which case it is
necessary to specify its path as the pub_key parameter's value. If this option
is not used when calling this command, the key can be directly entered later.
"""
)
""")
@find_repository
@catch_cli_exception(handle=TAFError)
@common_repo_edit_options
Expand Down Expand Up @@ -379,11 +373,9 @@ def adding_signing_key(


def revoke_signing_key_command():
@click.command(
help="""
@click.command(help="""
Revoke a signing key.
"""
)
""")
@find_repository
@catch_cli_exception(handle=TAFError)
@common_repo_edit_options
Expand Down Expand Up @@ -437,11 +429,9 @@ def revoke_key(


def rotate_signing_key_command():
@click.command(
help="""
@click.command(help="""
Rotate a signing key.
"""
)
""")
@find_repository
@catch_cli_exception(handle=TAFError)
@click.argument("keyid")
Expand Down Expand Up @@ -506,12 +496,10 @@ def rotate_key(


def list_keys_command():
@click.command(
help="""
@click.command(help="""
List all keys of the specified role. If certs directory exists and contains certificates exported from YubiKeys,
include additional information read from these certificates, like name or organization.
"""
)
""")
@find_repository
@catch_cli_exception(handle=TAFError)
@click.argument("role")
Expand Down
6 changes: 2 additions & 4 deletions taf/tools/yubikey/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ def setup_signing_key(certs_dir, pin_manager):


def setup_test_key_command():
@click.command(
help="""Copies the specified key onto the inserted YubiKey
WARNING - this will reset the inserted key."""
)
@click.command(help="""Copies the specified key onto the inserted YubiKey
WARNING - this will reset the inserted key.""")
@click.argument("key-path")
@catch_cli_exception(handle=YubikeyError)
@pin_managed
Expand Down
4 changes: 1 addition & 3 deletions taf/tuf/keys.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""TUF metadata key functions.

"""
"""TUF metadata key functions."""

from typing import Optional, Tuple, Union

Expand Down
7 changes: 3 additions & 4 deletions taf/tuf/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

from securesystemslib.signer import CryptoSigner


logger = logging.getLogger(__name__)

# TODO remove this, use from constants or remove from constants
Expand Down Expand Up @@ -721,9 +720,9 @@ def create_delegated_roles(
key_id = _get_legacy_keyid(public_key)
keys_data[key_id] = public_key
if key_id in self.keys_name_mappings:
public_key.unrecognized_fields[
"name"
] = self.keys_name_mappings[key_id]
public_key.unrecognized_fields["name"] = (
self.keys_name_mappings[key_id]
)

for signer in signers[role_data.name]:
public_key = signer.public_key
Expand Down
Loading
Loading