-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
31 lines (25 loc) · 1.03 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import xmlrpc.client
class OpenSPPClient:
COMMON_ENDPOINT = "/xmlrpc/2/common"
def __init__(self, server_root: str, username: str, password: str, db_name: str):
"""Initialize a PDS SPP client.
:param server_root: PDS SPP root url. E.g: https://dev.newlogic-demo.com/
:param username: User's username with access to the server
:param password: User's password or API key with access to the server
:param db_name: Name of database that contains the data for query
:return: a PDSSPPClient instance.
"""
self.server_root = server_root
self.username = username
self.password = password
self.db_name = db_name
@staticmethod
def get_server_proxy(url):
return xmlrpc.client.ServerProxy(url)
def login(self):
common_endpoint = self.get_server_proxy(
f"{self.server_root}{self.COMMON_ENDPOINT}"
)
return common_endpoint.authenticate(
self.db_name, self.username, self.password, {}
)