-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_functions.py
More file actions
executable file
·79 lines (74 loc) · 3.02 KB
/
api_functions.py
File metadata and controls
executable file
·79 lines (74 loc) · 3.02 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import requests
class Config:
url = ""
headers = {}
session = None
def configure(url,headers=None,session=None):
Config.url = url
Config.headers = headers
Config.session = session
endpoint_list = {
"add_user": {
"method": "POST",
"path": "/api/v1/auths/add",
"payload": lambda **kw: {
"name": kw.get("name", "string"),
"email": kw.get("email", "string"),
"password": kw.get("password", "string"),
"profile_image_url": kw.get("profile_image", ""),
"role": kw.get("role", "admin")
}
},
"admin_config_get": {
"method": "GET",
"path": "/api/v1/auths/admin/config",
"payload": None
},
"admin_config_set": {
"method": "POST",
"path": "/api/v1/auths/admin/config",
"payload": lambda **kw: {
"SHOW_ADMIN_DETAILS": kw.get("details", True),
"WEBUI_URL": kw.get("uiurl", ""),
"ENABLE_SIGNUP": kw.get("signup", False),
"ENABLE_API_KEY": kw.get("enableapi", True),
"ENABLE_API_KEY_ENDPOINT_RESTRICTIONS": kw.get("enablerestrictions", False),
"API_KEY_ALLOWED_ENDPOINTS": kw.get("allowedendpoints", ""),
"DEFAULT_USER_ROLE": kw.get("defaultrole", "user"),
"JWT_EXPIRES_IN": kw.get("jwtexpiretime", "30d"),
"ENABLE_COMMUNITY_SHARING": kw.get("communitysharing", True),
"ENABLE_MESSAGE_RATING": kw.get("messagerating", True),
"ENABLE_CHANNELS": kw.get("enablechannels", True),
"ENABLE_USER_WEBHOOKS": kw.get("enablewebhooks", True)
}
},
"ldap_config": {
"method": "GET",
"path": "/api/v1/auths/admin/config/ldap/server",
"payload": None
},
"api_key_get": {
"method": "GET",
"path": "/api/v1/auths/api_key",
"payload": None
},
"api_key_set": {
"method": "POST",
"path": "/api/v1/auths/api_key",
"payload": None
},
"user_chats": {
"method": "GET",
"path": "/api/v1/chats/all",
"payload": None
}
}
def call_endpoints(endpoint_name, **kwargs):
endpoint = endpoint_list[endpoint_name]
full_url = f"{Config.url}{endpoint['path']}"
payload = endpoint['payload'](**kwargs) if endpoint['payload'] else None
return Config.session.request(
endpoint['method'],
full_url,
json=payload,
headers=Config.headers)