Debian Codegraph @

src/globus_sdk/local_endpoint/server/endpoint.py

raw
1 from __future__ import annotations
2
3 import json
4 import pathlib
5 import typing as t
6
7
8 class LocalGlobusConnectServer:
9 r"""
10 A LocalGlobusConnectServer object represents the available SDK methods
11 for inspecting and controlling a running Globus Connect Server
12 installation.
13
14 These objects do *not* inherit from BaseClient and do not provide methods
15 for interacting with any Globus Service APIs.
16
17 :param info_path: The path to the info file used to inspect the local system
18 """
19
20 def __init__(
21 self,
22 *,
23 info_path: str | pathlib.Path = "/var/lib/globus-connect-server/info.json",
24 ) -> None:
25 self.info_path = pathlib.Path(info_path)
26 self._loaded_info: dict[str, t.Any] | None = None
27
28 @property
29 def info_dict(self) -> dict[str, t.Any] | None:
30 """
31 The info.json data for the local Globus Connect Server, as a dict.
32
33 If the info.json file is not present or cannot be parsed, the data is None.
34 This indicates that there is no local Globus Connect Server node, or if there is
35 one, it cannot be used or examined by the SDK. For example, containerized
36 applications using the SDK may not be able to interact with Globus Connect
37 Server on the container host.
38 """
39 if self._loaded_info is None:
40 if self.info_path.is_file():
41 with open(self.info_path, encoding="utf-8") as fp:
42 try:
43 parsed_data = json.load(fp)
44 except (UnicodeDecodeError, json.JSONDecodeError):
45 pass
46 else:
47 if isinstance(parsed_data, dict):
48 self._loaded_info = t.cast(t.Dict[str, t.Any], parsed_data)
49 return self._loaded_info
50
51 @info_dict.deleter
52 def info_dict(self) -> None:
53 self._loaded_info = None
54
55 @property
56 def endpoint_id(self) -> str | None:
57 """
58 The endpoint ID of the local Globus Connect Server endpoint.
59 None if the data cannot be loaded or is malformed.
60 """
61 if self.info_dict is not None:
62 epid = self.info_dict.get("endpoint_id")
63 if isinstance(epid, str):
64 return epid
65 return None
66
67 @property
68 def domain_name(self) -> str | None:
69 """
70 The domain name of the local Globus Connect Server endpoint.
71 None if the data cannot be loaded or is malformed.
72 """
73 if self.info_dict is not None:
74 domain = self.info_dict.get("domain_name")
75 if isinstance(domain, str):
76 return domain
77 return None