2021-08-27 23:45:24 +02:00
|
|
|
from typing import Iterator
|
|
|
|
|
2021-05-09 17:22:14 +02:00
|
|
|
from dynaconf import Validator
|
|
|
|
|
2021-07-05 21:44:11 +02:00
|
|
|
telegram_validators = [
|
|
|
|
Validator("notifier.telegram.chat_id", must_exist=True),
|
|
|
|
Validator("notifier.telegram.token", must_exist=True),
|
|
|
|
Validator("notifier.telegram.username", must_exist=True),
|
|
|
|
]
|
2021-09-26 20:12:06 +02:00
|
|
|
zulip_validators = [
|
2021-10-20 00:08:58 +02:00
|
|
|
Validator("notifier.zulip.chat_id", must_exist=True),
|
|
|
|
Validator("notifier.zulip.subject", must_exist=True),
|
|
|
|
Validator("notifier.zulip.bot_token", must_exist=True),
|
|
|
|
Validator("notifier.zulip.bot_email", must_exist=True),
|
|
|
|
]
|
|
|
|
mastodon_validators = [
|
2021-11-11 16:25:09 +01:00
|
|
|
Validator("publisher.zulip.instance", must_exist=True),
|
2021-10-20 00:08:58 +02:00
|
|
|
Validator("notifier.mastodon.instance", must_exist=True),
|
|
|
|
Validator("notifier.mastodon.token", must_exist=True),
|
|
|
|
Validator("notifier.mastodon.name", must_exist=True),
|
2021-09-26 20:12:06 +02:00
|
|
|
]
|
2021-10-17 14:05:16 +02:00
|
|
|
twitter_validators = [
|
|
|
|
Validator("publisher.twitter.api_key", must_exist=True),
|
|
|
|
Validator("publisher.twitter.api_key_secret", must_exist=True),
|
|
|
|
Validator("publisher.twitter.access_token", must_exist=True),
|
|
|
|
Validator("publisher.twitter.access_secret", must_exist=True),
|
|
|
|
]
|
2021-05-09 17:22:14 +02:00
|
|
|
|
|
|
|
notifier_name_to_validators = {
|
|
|
|
"telegram": telegram_validators,
|
|
|
|
"twitter": twitter_validators,
|
|
|
|
"mastodon": mastodon_validators,
|
|
|
|
"zulip": zulip_validators,
|
|
|
|
}
|
|
|
|
notifier_names = notifier_name_to_validators.keys()
|
|
|
|
|
|
|
|
|
2021-08-27 23:45:24 +02:00
|
|
|
def get_active_notifiers(settings) -> Iterator[str]:
|
2021-05-09 17:22:14 +02:00
|
|
|
return filter(
|
|
|
|
lambda notifier_name: settings["notifier"][notifier_name]["active"],
|
|
|
|
notifier_names,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def get_validators(settings):
|
|
|
|
active_notifiers = get_active_notifiers(settings)
|
|
|
|
validators = []
|
|
|
|
for notifier in active_notifiers:
|
|
|
|
validators += notifier_name_to_validators[notifier]
|
|
|
|
return validators
|