ix-notifiers 0.5.2__tar.gz → 0.5.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/PKG-INFO +2 -1
- ix_notifiers-0.5.3/ix_notifiers/__init__.py +5 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/ix_notifiers/constants.py +1 -1
- ix_notifiers-0.5.3/ix_notifiers/core.py +74 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/ix_notifiers/gotify_notifier.py +4 -10
- ix_notifiers-0.5.3/ix_notifiers/notifier.py +64 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/ix_notifiers/null_notifier.py +3 -10
- ix_notifiers-0.5.3/ix_notifiers/py.typed +0 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/ix_notifiers.egg-info/PKG-INFO +2 -1
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/ix_notifiers.egg-info/SOURCES.txt +2 -0
- ix_notifiers-0.5.3/ix_notifiers.egg-info/requires.txt +2 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/pyproject.toml +2 -1
- ix_notifiers-0.5.3/requirements.txt +2 -0
- ix_notifiers-0.5.2/ix_notifiers/__init__.py +0 -2
- ix_notifiers-0.5.2/ix_notifiers/core.py +0 -90
- ix_notifiers-0.5.2/ix_notifiers.egg-info/requires.txt +0 -1
- ix_notifiers-0.5.2/requirements.txt +0 -1
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/LICENSE +0 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/README.md +0 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/ix_notifiers.egg-info/dependency_links.txt +0 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/ix_notifiers.egg-info/top_level.txt +0 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/setup.cfg +0 -0
- {ix_notifiers-0.5.2 → ix_notifiers-0.5.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: ix-notifiers
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.3
|
4
4
|
Summary: A python library for notifiers
|
5
5
|
Author-email: Alex Thomae <notifiers@egos.tech>
|
6
6
|
License: MIT License
|
@@ -33,6 +33,7 @@ Requires-Python: >=3.6
|
|
33
33
|
Description-Content-Type: text/markdown
|
34
34
|
License-File: LICENSE
|
35
35
|
Requires-Dist: requests==2.32.3
|
36
|
+
Requires-Dist: egos-helpers==0.5.0
|
36
37
|
|
37
38
|
# ix-notifiers
|
38
39
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
""" notification core """
|
4
|
+
|
5
|
+
import logging
|
6
|
+
import importlib
|
7
|
+
from os import listdir
|
8
|
+
from os.path import dirname, realpath
|
9
|
+
from typing import Dict, List, Any
|
10
|
+
from .constants import NAME
|
11
|
+
|
12
|
+
log = logging.getLogger(NAME)
|
13
|
+
|
14
|
+
class IxNotifiers:
|
15
|
+
""" the IxNotifiers class """
|
16
|
+
|
17
|
+
notifiers: List[str] = []
|
18
|
+
registered: Dict[str, Any] = {}
|
19
|
+
|
20
|
+
def __init__(self):
|
21
|
+
"""
|
22
|
+
Records the existing notifiers
|
23
|
+
|
24
|
+
It looks in the current library directory for all files called `*_notifier.py`
|
25
|
+
"""
|
26
|
+
for notifier in listdir(dirname(realpath(__file__))):
|
27
|
+
|
28
|
+
if notifier.endswith('_notifier.py'):
|
29
|
+
self.notifiers.append(notifier.replace('_notifier.py', ''))
|
30
|
+
log.debug(f"Notifier available: {notifier}")
|
31
|
+
|
32
|
+
def register(self, notifier: str, **kwargs) -> None:
|
33
|
+
""" registers the notifiers
|
34
|
+
|
35
|
+
Each notifier will expect `notifier_key: value`. The `notifier_` part will
|
36
|
+
be stripped and the notifier will get `key` set as part of `kwargs`.
|
37
|
+
|
38
|
+
For example, if the `register` `kwargs` is set to:
|
39
|
+
|
40
|
+
kwargs = {
|
41
|
+
'gotify_port': 1234,
|
42
|
+
'gotify_token': 'abc'
|
43
|
+
}
|
44
|
+
|
45
|
+
Then the Gotify notifier will be called with:
|
46
|
+
|
47
|
+
`gotify_notifier.start(port=1234, token='abc')`
|
48
|
+
"""
|
49
|
+
log.debug(f'Registering {notifier}')
|
50
|
+
for n in self.notifiers:
|
51
|
+
if n == notifier:
|
52
|
+
instance = importlib.import_module(f'ix_notifiers.{notifier}_notifier')
|
53
|
+
# Strips the prefix from kwargs, if set
|
54
|
+
settings = {}
|
55
|
+
for k, v in kwargs.items():
|
56
|
+
settings.update({k.replace(f'{notifier}_', ''): v})
|
57
|
+
self.registered.update({notifier: instance.start(**settings)})
|
58
|
+
log.debug(f'Registered {notifier}')
|
59
|
+
|
60
|
+
def notify(self, **kwargs) -> bool:
|
61
|
+
"""
|
62
|
+
dispatches a notification to all the registered notifiers
|
63
|
+
|
64
|
+
param: kwargs get passed to the `send()` method of the notifier
|
65
|
+
return: True if at least one notification channel was successful, False otherwise
|
66
|
+
"""
|
67
|
+
success = False
|
68
|
+
for notifier in self.registered.items():
|
69
|
+
log.debug(f'Sending notification to {notifier}')
|
70
|
+
if self.registered[notifier].send(**kwargs) is True:
|
71
|
+
success = True
|
72
|
+
return success
|
73
|
+
|
74
|
+
register = IxNotifiers.register
|
@@ -2,17 +2,9 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
""" Gotify """
|
4
4
|
|
5
|
-
import logging
|
6
5
|
from urllib.parse import urljoin
|
7
6
|
import requests
|
8
|
-
from .
|
9
|
-
from .constants import NAME, BUILD, VERSION
|
10
|
-
|
11
|
-
log = logging.getLogger(NAME)
|
12
|
-
|
13
|
-
def start(**kwargs):
|
14
|
-
""" Returns an instance of the GotifyNotifier """
|
15
|
-
return GotifyNotifier(**kwargs)
|
7
|
+
from .notifier import Notifier, log
|
16
8
|
|
17
9
|
class GotifyNotifier(Notifier):
|
18
10
|
""" The GotifyNotifier class """
|
@@ -52,7 +44,7 @@ class GotifyNotifier(Notifier):
|
|
52
44
|
success = True
|
53
45
|
headers = {
|
54
46
|
'X-Gotify-Key': self.settings['token'],
|
55
|
-
'user-agent': f'{
|
47
|
+
'user-agent': f'{self.user_agent}',
|
56
48
|
}
|
57
49
|
# Allow per message override of content_type
|
58
50
|
extras = {
|
@@ -106,3 +98,5 @@ class GotifyNotifier(Notifier):
|
|
106
98
|
log.info("Sent message to gotify")
|
107
99
|
|
108
100
|
return success
|
101
|
+
|
102
|
+
start = GotifyNotifier.start
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
""" The Notifier Class """
|
4
|
+
|
5
|
+
from typing import Dict
|
6
|
+
from egos_helpers import redact
|
7
|
+
from .constants import NAME, BUILD, VERSION
|
8
|
+
from .core import log
|
9
|
+
|
10
|
+
class Notifier:
|
11
|
+
"""
|
12
|
+
The base class, extended by notifiers
|
13
|
+
|
14
|
+
This class not meant to be used directly!
|
15
|
+
"""
|
16
|
+
|
17
|
+
settings: Dict = {}
|
18
|
+
params: Dict = {}
|
19
|
+
|
20
|
+
version: str
|
21
|
+
user_agent: str
|
22
|
+
|
23
|
+
def __init__(self, **kwargs):
|
24
|
+
|
25
|
+
self.version = VERSION
|
26
|
+
if BUILD:
|
27
|
+
self.version += f'.{BUILD}'
|
28
|
+
|
29
|
+
self.user_agent = f'{NAME} {self.version}'
|
30
|
+
|
31
|
+
# go through self.params and check against kwargs
|
32
|
+
for param, setting in self.params.items():
|
33
|
+
if setting.get('mandatory') and not kwargs.get(f'{param}'):
|
34
|
+
raise ValueError(f'{param} is mandatory')
|
35
|
+
self.settings[param] = kwargs.get(f'{param}', self.params[param].get('default'))
|
36
|
+
|
37
|
+
if (setting['type'] == 'boolean') and not isinstance(self.settings[param], bool):
|
38
|
+
raise ValueError(f'`{param}` is not bool but {type(self.settings[param])}')
|
39
|
+
if (setting['type'] == 'integer') and not isinstance(self.settings[param], int):
|
40
|
+
raise ValueError(f'`{param}` is not int but {type(self.settings[param])}')
|
41
|
+
if (setting['type'] == 'string') and not isinstance(self.settings[param], str):
|
42
|
+
raise ValueError(f'`{param}` is not str but {type(self.settings[param])}')
|
43
|
+
|
44
|
+
@classmethod
|
45
|
+
def start(cls, **kwargs):
|
46
|
+
""" Returns an instance of the Notifier """
|
47
|
+
return cls(**kwargs)
|
48
|
+
|
49
|
+
def send(self, **kwargs) -> bool:
|
50
|
+
"""
|
51
|
+
logs the notification to info
|
52
|
+
|
53
|
+
This method must be overwritten by the notifiers
|
54
|
+
|
55
|
+
return: True
|
56
|
+
"""
|
57
|
+
log.info(f"{self.redact(str(kwargs))}")
|
58
|
+
return True
|
59
|
+
|
60
|
+
def redact(self, message: str) -> str:
|
61
|
+
""" based on self.params, it replaces sensitive information in message with a redacted string """
|
62
|
+
for param, setting in self.params.items():
|
63
|
+
message = redact(message, self.settings[param], setting.get('redact', False))
|
64
|
+
return message
|
@@ -2,16 +2,7 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
""" Null """
|
4
4
|
|
5
|
-
import
|
6
|
-
from .core import Notifier
|
7
|
-
from .constants import NAME
|
8
|
-
|
9
|
-
log = logging.getLogger(NAME)
|
10
|
-
|
11
|
-
def start(**kwargs):
|
12
|
-
""" Returns an instance of NullNotifier """
|
13
|
-
return NullNotifier(**kwargs)
|
14
|
-
|
5
|
+
from .notifier import Notifier, log
|
15
6
|
|
16
7
|
class NullNotifier(Notifier):
|
17
8
|
""" The NullNotifier class """
|
@@ -20,3 +11,5 @@ class NullNotifier(Notifier):
|
|
20
11
|
self.settings = {}
|
21
12
|
super().__init__(**kwargs)
|
22
13
|
log.debug("Initialized")
|
14
|
+
|
15
|
+
start = NullNotifier.start
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: ix-notifiers
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.3
|
4
4
|
Summary: A python library for notifiers
|
5
5
|
Author-email: Alex Thomae <notifiers@egos.tech>
|
6
6
|
License: MIT License
|
@@ -33,6 +33,7 @@ Requires-Python: >=3.6
|
|
33
33
|
Description-Content-Type: text/markdown
|
34
34
|
License-File: LICENSE
|
35
35
|
Requires-Dist: requests==2.32.3
|
36
|
+
Requires-Dist: egos-helpers==0.5.0
|
36
37
|
|
37
38
|
# ix-notifiers
|
38
39
|
|
@@ -7,7 +7,9 @@ ix_notifiers/__init__.py
|
|
7
7
|
ix_notifiers/constants.py
|
8
8
|
ix_notifiers/core.py
|
9
9
|
ix_notifiers/gotify_notifier.py
|
10
|
+
ix_notifiers/notifier.py
|
10
11
|
ix_notifiers/null_notifier.py
|
12
|
+
ix_notifiers/py.typed
|
11
13
|
ix_notifiers.egg-info/PKG-INFO
|
12
14
|
ix_notifiers.egg-info/SOURCES.txt
|
13
15
|
ix_notifiers.egg-info/dependency_links.txt
|
@@ -1,90 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
""" notification core """
|
4
|
-
|
5
|
-
import logging
|
6
|
-
import importlib
|
7
|
-
from .constants import NAME
|
8
|
-
|
9
|
-
log = logging.getLogger(NAME)
|
10
|
-
|
11
|
-
class IxNotifiers():
|
12
|
-
""" the IxNotifiers class """
|
13
|
-
|
14
|
-
notifiers = [
|
15
|
-
'gotify',
|
16
|
-
'null',
|
17
|
-
]
|
18
|
-
|
19
|
-
registered = {}
|
20
|
-
|
21
|
-
def register(self, notifier, **kwargs):
|
22
|
-
""" registers a notifier """
|
23
|
-
log.debug(f'Registering {notifier}')
|
24
|
-
for n in self.notifiers:
|
25
|
-
if n == notifier:
|
26
|
-
instance = importlib.import_module(f'ix_notifiers.{notifier}_notifier')
|
27
|
-
# Strips the prefix from kwargs, if set
|
28
|
-
settings = {}
|
29
|
-
for k, v in kwargs.items():
|
30
|
-
settings.update({k.replace(f'{notifier}_', ''): v})
|
31
|
-
self.registered.update({notifier: instance.start(**settings)})
|
32
|
-
log.debug(f'Registered {notifier}')
|
33
|
-
|
34
|
-
def notify(self, **kwargs) -> bool:
|
35
|
-
"""
|
36
|
-
dispatches a notification to all the registered notifiers
|
37
|
-
|
38
|
-
param: kwargs get passed to the `send()` method of the notifier
|
39
|
-
return: True if at least one notification channel was successful, False otherwise
|
40
|
-
"""
|
41
|
-
success = False
|
42
|
-
for notifier in self.registered.items():
|
43
|
-
log.debug(f'Sending notification to {notifier}')
|
44
|
-
if self.registered[notifier].send(**kwargs) is True:
|
45
|
-
success = True
|
46
|
-
return success
|
47
|
-
|
48
|
-
class Notifier():
|
49
|
-
""" The base class, extended by notifiers """
|
50
|
-
|
51
|
-
settings = {}
|
52
|
-
params = {}
|
53
|
-
|
54
|
-
def __init__(self, **kwargs):
|
55
|
-
# go through self.params and check against kwargs
|
56
|
-
for param, setting in self.params.items():
|
57
|
-
if setting.get('mandatory') and not kwargs.get(f'{param}'):
|
58
|
-
raise ValueError(f'{param} is mandatory')
|
59
|
-
self.settings[param] = kwargs.get(f'{param}', self.params[param].get('default'))
|
60
|
-
|
61
|
-
if (setting['type'] == 'boolean') and not isinstance(self.settings[param], bool):
|
62
|
-
raise ValueError(f'`{param}` is not bool but {type(self.settings[param])}')
|
63
|
-
if (setting['type'] == 'integer') and not isinstance(self.settings[param], int):
|
64
|
-
raise ValueError(f'`{param}` is not int but {type(self.settings[param])}')
|
65
|
-
if (setting['type'] == 'string') and not isinstance(self.settings[param], str):
|
66
|
-
raise ValueError(f'`{param}` is not str but {type(self.settings[param])}')
|
67
|
-
|
68
|
-
def key_to_title(self, key: str) -> str:
|
69
|
-
""" converts a configuration key in form 'a_is_b' to a title in form 'A Is B ' """
|
70
|
-
parsed = ""
|
71
|
-
keys = key.split('_')
|
72
|
-
for k in keys:
|
73
|
-
parsed += f'{k.capitalize()} '
|
74
|
-
return parsed[:-1]
|
75
|
-
|
76
|
-
def send(self, **kwargs):
|
77
|
-
"""
|
78
|
-
logs the notification to info
|
79
|
-
|
80
|
-
return: True
|
81
|
-
"""
|
82
|
-
log.info(f"{self.redact(str(kwargs))}")
|
83
|
-
return True
|
84
|
-
|
85
|
-
def redact(self, message: str) -> str:
|
86
|
-
""" based on self.params, it replaces sensitive information in message with a redacted string """
|
87
|
-
for param, setting in self.params.items():
|
88
|
-
if setting.get('redact') and self.settings.get(param):
|
89
|
-
message = message.replace(self.settings.get(param), 'xxxREDACTEDxxx')
|
90
|
-
return message
|
@@ -1 +0,0 @@
|
|
1
|
-
requests==2.32.3
|
@@ -1 +0,0 @@
|
|
1
|
-
requests==2.32.3
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|