Mobilizon-Reshare-condividi.../mobilizon_reshare/config/notifiers.py

51 lines
1.7 KiB
Python
Raw Normal View History

from typing import Iterator
2021-05-09 17:22:14 +02:00
from dynaconf import Validator
telegram_validators = [
Validator("notifier.telegram.chat_id", must_exist=True),
Validator("notifier.telegram.token", must_exist=True),
Validator("notifier.telegram.username", must_exist=True),
]
zulip_validators = [
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 = [
Validator("publisher.zulip.instance", must_exist=True),
Validator("notifier.mastodon.instance", must_exist=True),
Validator("notifier.mastodon.token", must_exist=True),
Validator("notifier.mastodon.name", must_exist=True),
]
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()
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