-
Notifications
You must be signed in to change notification settings - Fork 33
/
testauth.py
70 lines (54 loc) · 1.97 KB
/
testauth.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
67
68
69
70
import mosquitto_auth
def plugin_init(opts):
mosquitto_auth.log(
mosquitto_auth.LOG_DEBUG,
'plugin_init (opts: %r)' % (opts,)
)
def plugin_cleanup():
mosquitto_auth.log(mosquitto_auth.LOG_DEBUG, 'plugin_cleanup')
def unpwd_check(username, password):
mosquitto_auth.log(
mosquitto_auth.LOG_DEBUG,
'unpwd_check (username: %s password: %s)' % (username, password)
)
return True
def acl_check(client_id, username, topic, access, payload):
mosquitto_auth.log(
mosquitto_auth.LOG_DEBUG,
'acl_check %r' % (mosquitto_auth.topic_matches_sub('/#', topic))
)
if access == mosquitto_auth.MOSQ_ACL_READ:
mosquitto_auth.log(
mosquitto_auth.LOG_DEBUG,
'acl_check READ (client_id: {} username: {} topic: {} access: {}, payload: {!r})'
.format(client_id, username, topic, access, payload)
)
elif access == mosquitto_auth.MOSQ_ACL_SUBSCRIBE:
mosquitto_auth.log(
mosquitto_auth.LOG_DEBUG,
'acl_check SUBSCRIBE (client_id: {} username: {} topic: {} access: {}, payload: {!r})'
.format(client_id, username, topic, access, payload)
)
elif access == mosquitto_auth.MOSQ_ACL_WRITE:
mosquitto_auth.log(
mosquitto_auth.LOG_DEBUG,
'acl_check WRITE (client_id: {} username: {} topic: {} access: {}, payload: {!r})'
.format(client_id, username, topic, access, payload)
)
return True
def psk_key_get(identity, hint):
mosquitto_auth.log(
mosquitto_auth.LOG_DEBUG,
'psk_key_get (identity: %s hint: %s)' % (identity, hint)
)
return '0123456789'
def security_init(opts, reload):
mosquitto_auth.log(
mosquitto_auth.LOG_DEBUG,
'security_init (reload: %s, opts: %s)' % (reload, opts)
)
def security_cleanup(reload):
mosquitto_auth.log(
mosquitto_auth.LOG_DEBUG,
'security_cleanup (reload: %s)' % (reload)
)