-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared.py
66 lines (56 loc) · 1.25 KB
/
shared.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
54
55
56
57
58
59
60
61
62
63
64
65
66
from schema import Schema, Or, Optional
"""
import threading
from queue import Queue
def printer(queue):
while True:
print(queue.get())
def printqueue() -> Queue:
printqueue = Queue()
thread = threading.Thread(target=printer, args=(printqueue,), daemon=True)
thread.start()
return printqueue
"""
initial_schema = Schema(Or({
"mode": "background",
"hostname": str,
}, {
"mode": "admin",
"hostname": str,
"password": str
}))
command_client_schema = Schema({
"command": str,
Optional("args"): [str]
})
command_server_schema = Schema({
Optional("targets"): [str],
"command": command_client_schema
})
client_response_schema = Schema(Or({
"error": None,
"result": dict # TODO
}, {
"error": str
}, only_one=True))
server_response_schema = Schema([{
"hostname": str,
"response": client_response_schema
}])
"""
authorised_schema = Schema({
"response": lambda m: m in ("authorised", "unauthorised")
}
)
command_schema = Schema({
"command": And(str, Use(str.lower),
lambda m: m in ("logoff" , "listclient")),
Optional("targets"): [str]
}
)
action_schema = Schema({
"action": And(str, Use(str.lower),
lambda m: m in ("logoff")),
}
)
"""