-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabaseAuthInformation.py
53 lines (42 loc) · 1.57 KB
/
DatabaseAuthInformation.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class DatabaseAuthInformation:
def __init__(self):
self.host = None
self.port = None
self.database_name = None
self.username = None
self.password = None
def parse_auth_info(self, auth_filepath):
try:
with open(auth_filepath, 'r') as file:
for line in file:
if not line.strip() or line.strip()[0] == '#':
continue
key, value = line.strip().split('=', 1)
if key == 'host':
self.host = value.strip()
elif key == 'port':
self.port = value.strip()
elif key == 'database':
self.database_name = value.strip()
elif key == 'username':
self.username = value.strip()
elif key == 'password':
self.password = value.strip()
except Exception as e:
print(e)
return False
if None in (self.host, self.port, self.database_name, self.username, self.password):
return False
return True
def get_host(self):
return self.host
def get_port(self):
return self.port
def get_database_name(self):
return self.database_name
def get_username(self):
return self.username
def get_password(self):
return self.password
def debug_print(self):
print(f"Host: {self.host}:{self.port}/{self.database_name}@{self.username}:{self.password}")