|
11 | 11 | from uuid import uuid4 |
12 | 12 | from warnings import warn |
13 | 13 |
|
| 14 | +import requests |
| 15 | +from pydantic.v1 import validator |
14 | 16 | from typing_extensions import ( |
15 | 17 | IO, |
16 | 18 | Any, |
@@ -64,6 +66,12 @@ class OswExpress(OSW): |
64 | 66 | class Config: |
65 | 67 | arbitrary_types_allowed = True |
66 | 68 |
|
| 69 | + @validator("domain") |
| 70 | + def validate_domain(cls, v): |
| 71 | + pattern = r"^(?!-)[A-Za-z0-9.-]{1,63}(?<!-)\.[A-Za-z]{2,}$" |
| 72 | + assert re.match(pattern, v), "The domain is not valid." |
| 73 | + return v |
| 74 | + |
67 | 75 | @overload |
68 | 76 | def __init__( |
69 | 77 | self, |
@@ -122,7 +130,19 @@ def __init__( |
122 | 130 | # that filepath will be used |
123 | 131 | else: |
124 | 132 | cred_mngr.save_credentials_to_file() |
125 | | - |
| 133 | + # Test if domain is reachable |
| 134 | + try: |
| 135 | + url = f"https://{domain}/wiki/Main_Page" |
| 136 | + response = requests.get(url) |
| 137 | + if response.status_code == 200: |
| 138 | + pass # Domain is reachable |
| 139 | + else: |
| 140 | + raise ConnectionError( |
| 141 | + f"Could not connect to '{domain}'. " |
| 142 | + f"Response: {response.status_code}" |
| 143 | + ) |
| 144 | + except Exception as e: |
| 145 | + raise ConnectionError(f"Could not connect to '{domain}'. Error: {e}") |
126 | 146 | site = WtSite(WtSite.WtSiteConfig(iri=domain, cred_mngr=cred_mngr)) |
127 | 147 | super().__init__(**{"site": site, "domain": domain}) |
128 | 148 | self.cred_mngr = cred_mngr |
|
0 commit comments