forked from mozilla-conduit/git-hg-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
58 lines (44 loc) · 1.42 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pathlib
import tomllib
from typing import Self
import pydantic
from git_hg_sync.mapping import Mapping
class PulseConfig(pydantic.BaseModel):
userid: str
host: str
port: int
exchange: str
routing_key: str
queue: str
password: str
ssl: bool
class TrackedRepository(pydantic.BaseModel):
name: str
url: str
class ClonesConfig(pydantic.BaseModel):
directory: pathlib.Path
class SentryConfig(pydantic.BaseModel):
sentry_url: str | None = None
class Config(pydantic.BaseModel):
pulse: PulseConfig
sentry: SentryConfig | None = None
clones: ClonesConfig
tracked_repositories: list[TrackedRepository]
mappings: list[Mapping]
@pydantic.model_validator(mode="after")
def verify_all_mappings_reference_tracked_repositories(
self,
) -> Self:
tracked_urls = [tracked_repo.url for tracked_repo in self.tracked_repositories]
for mapping in self.mappings:
if mapping.source.url not in tracked_urls:
raise ValueError(
f"Found mapping for untracked repository: {mapping.source.url}"
)
return self
@staticmethod
def from_file(file_path: pathlib.Path) -> "Config":
assert file_path.exists(), f"config file {file_path} doesn't exists"
with open(file_path, "rb") as config_file:
config = tomllib.load(config_file)
return Config(**config)