diff --git a/solstone/observe/export.py b/solstone/observe/export.py index 7e52541c9..830ea6ec6 100644 --- a/solstone/observe/export.py +++ b/solstone/observe/export.py @@ -4,7 +4,8 @@ """Export journal data to a remote solstone instance. Usage: - sol export --to HOST --key KEY [--only TYPE] [--dry-run] [--day YYYYMMDD] + sol export --to URL --key KEY [--only TYPE] [--dry-run] [--day YYYYMMDD] + sol export --to LABEL [--only TYPE] [--dry-run] [--day YYYYMMDD] """ from __future__ import annotations @@ -22,6 +23,9 @@ from typing import Any import requests +from solstone.observe.peer_lookup import PeerInfo, PeerLookupError, resolve_peer +from solstone.observe.peer_unpair import maybe_prompt_unpair +from solstone.observe.pl_http import PlHttpSession from solstone.observe.transfer import ( RETRY_BACKOFF, _build_segment_manifest, @@ -30,6 +34,9 @@ from solstone.observe.transfer import ( ) from solstone.think.entities.journal import load_all_journal_entities from solstone.think.importers.sync import SYNCABLE_REGISTRY +from solstone.think.link.bundle import load_client_identity +from solstone.think.link.dialer import TunnelClient +from solstone.think.link.paths import relay_url from solstone.think.utils import ( day_path, get_config, @@ -47,6 +54,8 @@ _DAY_JSONL_RE = re.compile(r"^\d{8}\.jsonl$") _DAY_MD_RE = re.compile(r"^\d{8}\.md$") _IMPORT_ID_RE = re.compile(r"^\d{8}_\d{6}$") _NEVER_TRANSFER_PATHS = frozenset({"convey.password_hash", "convey.secret"}) +EXPORT_AREAS = ("segments", "imports", "entities", "facets", "config") +FULL_EXPORT_SET = frozenset(EXPORT_AREAS) @dataclass @@ -62,6 +71,45 @@ class ExportResult: error: str | None = None +def _is_url_destination(to: str) -> bool: + return to.startswith(("http://", "https://")) + + +def _resolve_destination( + parser: argparse.ArgumentParser, + to: str, + key: str | None, +) -> tuple[str, str | None, PeerInfo | None]: + if _is_url_destination(to): + if key is None: + parser.error("'--to ' requires '--key '") + return ("dl", _normalize_url(to), None) + if key is not None: + parser.error( + "'--key' is only valid with '--to '; " + "use '--to