Skip to content

Commit 7b15519

Browse files
committed
feat: provide func to fetch server info
1 parent af36aa0 commit 7b15519

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

dandi/cli/base.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,47 @@
22
import os
33

44
import click
5+
import requests
6+
from yarl import URL
7+
8+
from dandi.consts import known_instances
9+
from dandi.utils import ServerInfo
510

611
from .. import get_logger
712

813
lgr = get_logger()
914

15+
16+
def get_server_info(dandi_id: str) -> ServerInfo:
17+
"""
18+
Get server info from a particular DANDI instance
19+
20+
Parameters
21+
----------
22+
dandi_id : str
23+
The ID specifying the particular known DANDI instance to query for server info.
24+
This is a key in the `dandi.consts.known_instances` dictionary.
25+
26+
Returns
27+
-------
28+
ServerInfo
29+
An object representing the server information responded by the DANDI instance.
30+
31+
Raises
32+
------
33+
valueError
34+
If the provided `dandi_id` is not a valid key in the
35+
`dandi.consts.known_instances` dictionary.
36+
"""
37+
if dandi_id not in known_instances:
38+
raise ValueError(f"Unknown DANDI instance: {dandi_id}")
39+
40+
info_url = str(URL(known_instances[dandi_id].api) / "info/")
41+
resp = requests.get(info_url)
42+
resp.raise_for_status()
43+
return ServerInfo.model_validate(resp.json())
44+
45+
1046
# Aux common functionality
1147

1248

0 commit comments

Comments
 (0)