-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathvalidate.py
More file actions
32 lines (29 loc) · 1 KB
/
validate.py
File metadata and controls
32 lines (29 loc) · 1 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
from jsonschema import validate
EMAIL_CONFIG_SCHEMA = {
"type" : "object",
"required": ['mail_from', 'smtp_host', 'smtp_port', 'smtp_user', 'smtp_password'],
"properties" : {
"mail_from" : {"type" : "string"},
"smtp_host" : {"type" : "string"},
"smtp_port" : {"type" : "number"},
"smtp_user" : {"type" : "string"},
"smtp_password" : {"type" : "string"},
"use_ssl": {"type" : "boolean"},
"use_tls": {"type" : "boolean"},
},
}
SLACK_CONFIG_SCHEMA = {
"type" : "object",
"required": ['webhook_url'],
"properties" : {
"webhook_url" : {"type" : "string"},
}
}
def validate_config_section(config, section):
notifications = config.get('notifications') or {}
if section == 'email':
email_config = notifications.get('email') or {}
validate(email_config, EMAIL_CONFIG_SCHEMA)
elif section == 'slack':
slack_config = notifications.get('slack') or {}
validate(slack_config, SLACK_CONFIG_SCHEMA)