-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathacl.py
43 lines (38 loc) · 1.31 KB
/
acl.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
# -*- coding: utf-8 -*-
'''
The acl module handles client_acl operations
Additional information on client_acl can be
found by reading the salt documention:
http://docs.saltstack.com/en/latest/ref/clientacl.html
'''
# Import python libraries
from __future__ import absolute_import
import re
class ClientACL(object):
'''
Represents the client ACL and provides methods
to query the ACL for given operations
'''
def __init__(self, blacklist):
self.blacklist = blacklist
def user_is_blacklisted(self, user):
'''
Takes a username as a string and returns a boolean. True indicates that
the provided user has been blacklisted
'''
for blacklisted_user in self.blacklist.get('users', []):
if re.match(blacklisted_user, user):
return True
return False
def cmd_is_blacklisted(self, cmd):
for blacklisted_module in self.blacklist.get('modules', []):
# If this is a regular command, it is a single function
if isinstance(cmd, str):
funs_to_check = [cmd]
# If this is a compound function
else:
funs_to_check = cmd
for fun in funs_to_check:
if re.match(cmd, fun):
return True
return False