diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-03-20 15:56:33 +0100 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2023-09-25 09:43:37 +0200 |
| commit | 2388b826cc8c0507bc840a728d005450d91adf4b (patch) | |
| tree | 01efd5c44d9ce9cee30f291d8d5ae5db726a5732 /wrappers/python/eduvpn_common/main.py | |
| parent | 19882f158fec139622ffe5b52bc9e834a9d3246e (diff) | |
Exports + Python: Use an enum for server type
Diffstat (limited to 'wrappers/python/eduvpn_common/main.py')
| -rw-r--r-- | wrappers/python/eduvpn_common/main.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/wrappers/python/eduvpn_common/main.py b/wrappers/python/eduvpn_common/main.py index f22e4d3..87de430 100644 --- a/wrappers/python/eduvpn_common/main.py +++ b/wrappers/python/eduvpn_common/main.py @@ -1,3 +1,4 @@ +from enum import IntEnum from typing import Any, Callable, Iterator, Optional from eduvpn_common.loader import initialize_functions, load_lib @@ -16,6 +17,13 @@ def forwardError(error: bytes | str): raise WrappedError(error.decode("utf-8")) +class ServerType(IntEnum): + UNKNOWN = 0 + INSTITUTE_ACCESS = 1 + SECURE_INTERNET = 2 + CUSTOM = 3 + + class EduVPN(object): """The main class used to communicate with the Go library. It registers the client with the library and then calls the needed appropriate functions @@ -93,15 +101,15 @@ class EduVPN(object): if register_err: forwardError(register_err) - def add_server(self, _type: str, _id: str) -> None: + def add_server(self, _type: ServerType, _id: str) -> None: """Add a server - :param _type: str: The type of server: "institute_access", "secure_internet" or "custom_server" + :param _type: ServerType: The type of server e.g. SERVER.INSTITUTE_ACCESS :param _id: str: The identifier of the server, e.g. "https://vpn.example.com/" :raises WrappedError: An error by the Go library """ - add_err = self.go_function(self.lib.AddServer, _type, _id) + add_err = self.go_function(self.lib.AddServer, int(_type), _id) if add_err: forwardError(add_err) @@ -140,25 +148,25 @@ class EduVPN(object): forwardError(servers_err) return servers - def remove_server(self, _type: str, _id: str) -> None: + def remove_server(self, _type: ServerType, _id: str) -> None: """Remove a server - :param _type: str: The type of server: "institute_access", "secure_internet" or "custom_server" + :param _type: ServerType: The type of server e.g. SERVER.INSTITUTE_ACCESS :param _id: str: The identifier of the server, e.g. "https://vpn.example.com/" :raises WrappedError: An error by the Go library """ - remove_err = self.go_function(self.lib.RemoveServer, _type, _id) + remove_err = self.go_function(self.lib.RemoveServer, int(_type), _id) if remove_err: forwardError(remove_err) def get_config( - self, _type: str, identifier: str, prefer_tcp: bool = False, tokens: str = "{}" + self, _type: ServerType, identifier: str, prefer_tcp: bool = False, tokens: str = "{}" ) -> Optional[str]: """Get an OpenVPN/WireGuard configuration from the server - :param _type: str: The type of server: "institute_access", "secure_internet" or "custom_server" + :param _type: ServerType: The type of server e.g. SERVER.INSTITUTE_ACCESS :param identifier: str: The identifier of the server, e.g. URL or ORG ID :param prefer_tcp: bool: (Default value = False): Whether or not to prefer TCP :param tokens: str (Defualt value = ""): The OAuth tokens if available |
