Skip to content

Commit 09da22b

Browse files
authored
Upgrade tuf dependency (#1017)
1 parent bc3d200 commit 09da22b

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies = [
3838
"sigstore-protobuf-specs ~= 0.3.2",
3939
# NOTE(ww): Under active development, so strictly pinned.
4040
"sigstore-rekor-types == 0.0.13",
41-
"tuf ~= 4.0",
41+
"tuf ~= 5.0",
4242
"platformdirs ~= 4.2",
4343
]
4444
requires-python = ">=3.8"

sigstore/_internal/tuf.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525

2626
import platformdirs
2727
from tuf.api import exceptions as TUFExceptions
28-
from tuf.ngclient import RequestsFetcher, Updater
28+
from tuf.ngclient import Updater, UpdaterConfig
2929

30+
from sigstore import __version__
3031
from sigstore._utils import read_embedded
3132
from sigstore.errors import RootError, TUFError
3233

@@ -36,18 +37,6 @@
3637
STAGING_TUF_URL = "https://tuf-repo-cdn.sigstage.dev"
3738

3839

39-
@lru_cache()
40-
def _get_fetcher() -> RequestsFetcher:
41-
# NOTE: We poke into the underlying fetcher here to set a more reasonable timeout.
42-
# The default timeout is 4 seconds, which can cause spurious timeout errors on
43-
# CI systems like GitHub Actions (where traffic may be delayed/deprioritized due
44-
# to network load).
45-
fetcher = RequestsFetcher()
46-
fetcher.socket_timeout = 30
47-
48-
return fetcher
49-
50-
5140
def _get_dirs(url: str) -> tuple[Path, Path]:
5241
"""
5342
Given a TUF repository URL, return suitable local metadata and cache directories.
@@ -133,7 +122,7 @@ def __init__(self, url: str, offline: bool = False) -> None:
133122
metadata_base_url=self._repo_url,
134123
target_base_url=parse.urljoin(f"{self._repo_url}/", "targets/"),
135124
target_dir=str(self._targets_dir),
136-
fetcher=_get_fetcher(),
125+
config=UpdaterConfig(app_user_agent=f"sigstore-python/{__version__}"),
137126
)
138127
try:
139128
self._updater.refresh()

test/unit/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434
from tuf.api.exceptions import DownloadHTTPError
3535
from tuf.ngclient import FetcherInterface
36+
from tuf.ngclient.updater import requests_fetcher
3637

3738
from sigstore._internal import tuf
3839
from sigstore._internal.rekor import _hashedrekord_from_parts
@@ -225,7 +226,7 @@ def verify(self, cert):
225226

226227
@pytest.fixture
227228
def mock_staging_tuf(monkeypatch, tuf_dirs):
228-
"""Mock that prevents tuf module from making requests: it returns staging
229+
"""Mock that prevents python-tuf from making requests: it returns staging
229230
assets from a local directory instead
230231
231232
Return a tuple of dicts with the requested files and counts"""
@@ -244,7 +245,9 @@ def _fetch(self, url: str) -> Iterator[bytes]:
244245
failure[filename] += 1
245246
raise DownloadHTTPError("File not found", 404)
246247

247-
monkeypatch.setattr(tuf, "_get_fetcher", lambda: MockFetcher())
248+
monkeypatch.setattr(
249+
requests_fetcher, "RequestsFetcher", lambda app_user_agent: MockFetcher()
250+
)
248251

249252
return success, failure
250253

0 commit comments

Comments
 (0)