|
9 | 9 |
|
10 | 10 | import cadcutils |
11 | 11 | import dill |
| 12 | +import requests |
12 | 13 | from cadcdata import StorageInventoryClient |
13 | 14 | from cadctap import CadcTapClient |
14 | 15 | from cadcutils import net |
| 16 | +from requests.exceptions import HTTPError |
15 | 17 | from rich.traceback import install |
16 | 18 |
|
17 | 19 | from dtcli.config import procure |
@@ -364,3 +366,33 @@ def query( |
364 | 366 | content = buffer.getvalue() |
365 | 367 | sys.stdout = sys.__stdout__ |
366 | 368 | return [line.split(",") for line in content.split("\n")] |
| 369 | + |
| 370 | + |
| 371 | +def status( |
| 372 | + url: str = "https://ws-uv.canfar.net/minoc/capabilities", |
| 373 | + certfile: Optional[str] = None, |
| 374 | +) -> bool: |
| 375 | + """Check the status of Minoc. |
| 376 | +
|
| 377 | + Args: |
| 378 | + url: Minoc capabilities HEAD endpoint. |
| 379 | + certfile: Canfar certificate file. |
| 380 | +
|
| 381 | + Returns: |
| 382 | + bool: True if Minoc is up, False otherwise. |
| 383 | + """ |
| 384 | + if not certfile: |
| 385 | + certfile = procure(key="vospace_certfile") |
| 386 | + response = requests.get(url, cert=certfile, allow_redirects=True) |
| 387 | + try: |
| 388 | + response.raise_for_status() |
| 389 | + except HTTPError as error: |
| 390 | + logger.error(error) |
| 391 | + logger.error("Canfar is down.") |
| 392 | + return False |
| 393 | + authorised = response.headers.get("x-vo-authenticated") |
| 394 | + if isinstance(authorised, str): |
| 395 | + return True |
| 396 | + else: |
| 397 | + logger.error("Canfar certificate is not valid.") |
| 398 | + return False |
0 commit comments