Skip to content

Commit

Permalink
move multiple-preserves check to config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrudenell committed Sep 12, 2024
1 parent 15d791f commit b220340
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
10 changes: 0 additions & 10 deletions src/btrfs2s3/_internal/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,6 @@ def command(*, console: Console, args: argparse.Namespace) -> int:
s3_endpoint = s3_remote.get("endpoint", {})

sources = config["sources"]
assert ( # noqa: S101
len(
{
upload["preserve"]
for source in sources
for upload in source["upload_to_remotes"]
}
)
== 1
)
assert ( # noqa: S101
len(
{
Expand Down
10 changes: 9 additions & 1 deletion src/btrfs2s3/_internal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,17 @@ def load_from_path(path: str | PathLike[str]) -> Config:
msg = "multiple remotes not supported in this release"
raise InvalidConfigError(msg)

all_sources = config["sources"]

# https://github.com/sbrudenell/btrfs2s3/issues/81
if len({source["snapshots"] for source in config["sources"]}) > 1:
if len({source["snapshots"] for source in all_sources}) > 1:
msg = "multiple snapshot locations not supported in this release"
raise InvalidConfigError(msg)

all_uploads = [up for src in all_sources for up in src["upload_to_remotes"]]

if len({upload["preserve"] for upload in all_uploads}) > 1:
msg = "multiple preserve configurations not supported in this release"
raise InvalidConfigError(msg)

return config
23 changes: 23 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,26 @@ def test_no_multiple_snapshot_locations(path: Path) -> None:
""")
with pytest.raises(InvalidConfigError):
load_from_path(path)


def test_no_multiple_preserves(path: Path) -> None:
path.write_text("""
timezone: a
sources:
- path: b
snapshots: c
upload_to_remotes:
- id: aws
preserve: 1y 1m
- path: x
snapshots: c
upload_to_remotes:
- id: aws
preserve: 1y
remotes:
- id: aws
s3:
bucket: d
""")
with pytest.raises(InvalidConfigError):
load_from_path(path)

0 comments on commit b220340

Please sign in to comment.