This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
config.py
109 lines (89 loc) · 3.82 KB
/
config.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
import re
import sys
sys.path.append('plugins/sdm')
from enabled_commands_util import get_commands_enabled, get_commands_aliases
def is_admins_channel_elevate_enabled():
return str(os.getenv("SDM_ADMINS_CHANNEL_ELEVATE", "")).lower() == 'true' and os.getenv("SDM_ADMINS_CHANNEL") is not None
def get_access_controls():
commands_enabled = [re.sub(r':[\w-]+', '', cmd) for cmd in get_commands_enabled()]
allow_all = { 'allowusers': ('*') }
deny_all = { 'denyusers': ('*') }
return { # The order in this dict matters!
'AccessBot:access_resource': allow_all if 'access_resource' in commands_enabled else deny_all,
'AccessBot:approve': allow_all if 'approve' in commands_enabled else deny_all,
'AccessBot:assign_role': allow_all if 'assign_role' in commands_enabled else deny_all,
'AccessBot:deny': allow_all if 'deny' in commands_enabled else deny_all,
'AccessBot:show_resources': allow_all if 'show_resources' in commands_enabled else deny_all,
'AccessBot:show_roles': allow_all if 'show_roles' in commands_enabled else deny_all,
'AccessBot:match_alias': allow_all,
'AccessBot:accessbot-whoami': {
'allowusers': ('*'),
'allowprivate': True,
'allowmuc': False,
},
'help': { 'allowusers': ('*') },
'whoami': deny_all,
'*': {
'allowusers': BOT_ADMINS,
'allowrooms': [os.getenv('SDM_ADMINS_CHANNEL')],
'allowprivate': not is_admins_channel_elevate_enabled(),
'allowmuc': is_admins_channel_elevate_enabled(),
},
}
def get_bot_identity():
platform = os.getenv('SDM_BOT_PLATFORM')
if platform == 'ms-teams':
return {
"app_id": os.getenv("AZURE_APP_ID", None),
"app_password": os.getenv("AZURE_APP_PASSWORD", None),
"ad_tenant_id": os.getenv("AZURE_AD_TENANT_ID", None),
"ad_app_id": os.getenv("AZURE_AD_APP_ID", None),
"ad_app_secret": os.getenv("AZURE_AD_APP_SECRET", None),
}
elif platform == 'slack-classic':
return {
'token': os.getenv("SLACK_TOKEN")
}
return {
"app_token": os.getenv("SLACK_APP_TOKEN"),
"bot_token": os.getenv("SLACK_BOT_TOKEN"),
}
def get_backend():
platform = os.getenv('SDM_BOT_PLATFORM')
if platform == 'ms-teams':
return 'BotFramework'
elif platform == 'slack-classic':
return 'Slack'
return 'SlackBolt'
def get_bot_extra_backend_dir():
platform = os.getenv('SDM_BOT_PLATFORM').lower()
if platform == 'ms-teams':
return 'errbot-backend-botframework'
elif platform == 'slack-classic':
return None
return 'errbot-slack-bolt-backend/errbot_slack_bolt_backend'
def get_bot_admins():
return os.getenv("SDM_ADMINS").lower().split(" ")
CORE_PLUGINS = ('ACLs', 'Backup', 'ChatRoom', 'CommandNotFoundFilter', 'Flows', 'Health', 'Help', 'Plugins', 'TextCmds',
'Utils', 'VersionChecker', 'Webserver')
BACKEND = get_backend()
BOT_EXTRA_BACKEND_DIR = get_bot_extra_backend_dir()
BOT_DATA_DIR = 'data'
BOT_EXTRA_PLUGIN_DIR = 'plugins'
BOT_PLATFORM = os.getenv("SDM_BOT_PLATFORM").lower()
BOT_LOG_FILE = '' if str(os.getenv("SDM_DOCKERIZED", "")).lower() == 'true' else 'errbot.log'
BOT_LOG_LEVEL = os.getenv("LOG_LEVEL", 'INFO')
BOT_ADMINS = get_bot_admins()
CHATROOM_PRESENCE = ()
BOT_IDENTITY = get_bot_identity()
ACCESS_CONTROLS = get_access_controls()
BOT_PREFIX = ''
HIDE_RESTRICTED_COMMANDS = True
HIDE_RESTRICTED_ACCESS = True
BOT_COMMANDS_ALIASES = get_commands_aliases()
ACCESS_FORM_BOT_INFO = {
"bot_id": None, # will be initialized in SlackBoltBackend.resolve_access_form_bot_id method
"nickname": os.getenv("SDM_ACCESS_FORM_BOT_NICKNAME")
}
EXPOSE_METRICS = os.getenv("SDM_EXPOSE_METRICS", "false").lower() == "true"