diff --git a/src/_zkapauthorizer/recover.py b/src/_zkapauthorizer/recover.py index 082077f8cbac7a9e99e3777575937f1e66bcb786..d5bfd046a944faf4098d11f8741addf23f9cedc3 100644 --- a/src/_zkapauthorizer/recover.py +++ b/src/_zkapauthorizer/recover.py @@ -19,13 +19,9 @@ from io import BytesIO from sqlite3 import Cursor from typing import BinaryIO, Callable, Dict, Iterator, Optional -from allmydata.node import _Config from attrs import define -from treq.client import HTTPClient -from twisted.python.filepath import FilePath -from .config import read_node_url -from .tahoe import download +from .tahoe import Tahoe class SnapshotMissing(Exception): @@ -204,8 +200,7 @@ def recover(statements: Iterator[str], cursor) -> None: async def tahoe_lafs_downloader( - treq: HTTPClient, - node_config: _Config, + client: Tahoe, recovery_cap: str, set_state: SetState, ) -> Awaitable: # Awaitable[FilePath] @@ -213,17 +208,14 @@ async def tahoe_lafs_downloader( Download replica data from the given replica directory capability into the node's private directory. """ - api_root = read_node_url(node_config) - snapshot_path = FilePath(node_config.get_private_path("snapshot.sql")) + snapshot_path = client.get_private_path("snapshot.sql") set_state(RecoveryState(stage=RecoveryStages.downloading)) - await download(treq, snapshot_path, api_root, recovery_cap, ["snapshot.sql"]) + await client.download(snapshot_path, recovery_cap, ["snapshot.sql"]) return snapshot_path -def get_tahoe_lafs_downloader( - httpclient: HTTPClient, node_config: _Config -) -> Callable[[str], Downloader]: +def get_tahoe_lafs_downloader(client: Tahoe) -> Callable[[str], Downloader]: """ Bind some parameters to ``tahoe_lafs_downloader`` in a convenient way. @@ -233,7 +225,7 @@ def get_tahoe_lafs_downloader( def get_downloader(cap_str): def downloader(set_state): - return tahoe_lafs_downloader(httpclient, node_config, cap_str, set_state) + return tahoe_lafs_downloader(client, cap_str, set_state) return downloader diff --git a/src/_zkapauthorizer/tahoe.py b/src/_zkapauthorizer/tahoe.py index 9738995562fe221cb5a292bea4f9e7ba4aa74d3b..1b185ac636d5fac307a777a2cf831623f140f860 100644 --- a/src/_zkapauthorizer/tahoe.py +++ b/src/_zkapauthorizer/tahoe.py @@ -10,6 +10,7 @@ from typing import Callable, Dict, Iterable, List, Optional import treq from allmydata.node import _Config +from allmydata.uri import from_string as capability_from_string from allmydata.util.base32 import b2a as b32encode from attrs import Factory, define, field from hyperlink import DecodedURL diff --git a/src/_zkapauthorizer/tests/test_recover.py b/src/_zkapauthorizer/tests/test_recover.py index e71d69363e9665a7417666f77d5c19c467bf7c16..799551f2ed6d5ae0d8f5652ffde92a83e542efbc 100644 --- a/src/_zkapauthorizer/tests/test_recover.py +++ b/src/_zkapauthorizer/tests/test_recover.py @@ -39,7 +39,7 @@ from ..recover import ( noop_downloader, recover, ) -from ..tahoe import link, make_directory, upload +from ..tahoe import Tahoe, link, make_directory, upload from .fixtures import Treq from .resources import client_manager from .sql import Table, create_table @@ -316,7 +316,8 @@ class TahoeLAFSDownloaderTests(TestCase): ) ) - get_downloader = get_tahoe_lafs_downloader(httpclient, config) + tahoeclient = Tahoe(httpclient, config) + get_downloader = get_tahoe_lafs_downloader(tahoeclient) download = get_downloader(replica_dir_cap_str) downloaded_snapshot_path = yield Deferred.fromCoroutine(