in lemur/notifications/service.py [0:0]
def create_default_expiration_notifications(name, recipients, intervals=None):
"""
Will create standard 30, 10 and 2 day notifications for a given owner unless an alternate set of
intervals is supplied. If standard notifications already exist these will be returned instead of
new notifications.
:param name:
:param recipients:
:return:
"""
if not recipients:
return []
options = [
{
"name": "unit",
"type": "select",
"required": True,
"validation": "",
"available": ["days", "weeks", "months"],
"helpMessage": "Interval unit",
"value": "days",
},
{
"name": "recipients",
"type": "str",
"required": True,
"validation": r"^([\w+-.%]+@[\w-.]+\.[A-Za-z]{2,4},?)+$",
"helpMessage": "Comma delimited list of email addresses",
"value": ",".join(recipients),
},
]
if intervals is None:
intervals = current_app.config.get(
"LEMUR_DEFAULT_EXPIRATION_NOTIFICATION_INTERVALS", [30, 15, 2]
)
notifications = []
for i in intervals:
n = get_by_label("{name}_{interval}_DAY".format(name=name, interval=i))
if not n:
inter = [
{
"name": "interval",
"type": "int",
"required": True,
"validation": r"^\d+$",
"helpMessage": "Number of days to be alert before expiration.",
"value": i,
}
]
inter.extend(options)
n = create(
label="{name}_{interval}_DAY".format(name=name, interval=i),
plugin_name=current_app.config.get(
"LEMUR_DEFAULT_NOTIFICATION_PLUGIN", "email-notification"
),
options=list(inter),
description="Default {interval} day expiration notification".format(
interval=i
),
certificates=[],
)
notifications.append(n)
return notifications