Gotify supports extended URL paths beyond just the hostname (#259)

pull/261/head
Chris Caron 2020-07-27 11:10:54 -04:00 committed by GitHub
parent 74759031fc
commit 84feb163aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 4 deletions

View File

@ -89,6 +89,8 @@ class NotifyGotify(NotifyBase):
templates = (
'{schema}://{host}/{token}',
'{schema}://{host}:{port}/{token}',
'{schema}://{host}{path}{token}',
'{schema}://{host}:{port}{path}{token}',
)
# Define our template tokens
@ -104,6 +106,13 @@ class NotifyGotify(NotifyBase):
'type': 'string',
'required': True,
},
'path': {
'name': _('Path'),
'type': 'string',
'map_to': 'fullpath',
'default': '/',
'required': True,
},
'port': {
'name': _('Port'),
'type': 'int',
@ -137,6 +146,9 @@ class NotifyGotify(NotifyBase):
self.logger.warning(msg)
raise TypeError(msg)
# prepare our fullpath
self.fullpath = kwargs.get('fullpath', '/')
if priority not in GOTIFY_PRIORITIES:
self.priority = GotifyPriority.NORMAL
@ -161,7 +173,7 @@ class NotifyGotify(NotifyBase):
url += ':%d' % self.port
# Append our remaining path
url += '/message'
url += '{fullpath}message'.format(fullpath=self.fullpath)
# Define our parameteers
params = {
@ -245,11 +257,12 @@ class NotifyGotify(NotifyBase):
default_port = 443 if self.secure else 80
return '{schema}://{hostname}{port}/{token}/?{args}'.format(
return '{schema}://{hostname}{port}{fullpath}{token}/?{args}'.format(
schema=self.secure_protocol if self.secure else self.protocol,
hostname=NotifyGotify.quote(self.host, safe=''),
port='' if self.port is None or self.port == default_port
else ':{}'.format(self.port),
fullpath=NotifyGotify.quote(self.fullpath, safe='/'),
token=self.pprint(self.token, privacy, safe=''),
args=NotifyGotify.urlencode(args),
)
@ -271,13 +284,17 @@ class NotifyGotify(NotifyBase):
# optionally find the provider key
try:
# The first entry is our token
results['token'] = entries.pop(0)
# The last entry is our token
results['token'] = entries.pop()
except IndexError:
# No token was set
results['token'] = None
# Re-assemble our full path
results['fullpath'] = \
'/' if not entries else '/{}/'.format('/'.join(entries))
if 'priority' in results['qsd'] and len(results['qsd']['priority']):
_map = {
'l': GotifyPriority.LOW,

View File

@ -103,6 +103,14 @@ class NotifyNotica(NotifyBase):
'{schema}://{user}@{host}:{port}/{token}',
'{schema}://{user}:{password}@{host}/{token}',
'{schema}://{user}:{password}@{host}:{port}/{token}',
# Self-hosted notica servers (with custom path)
'{schema}://{host}{path}{token}',
'{schema}://{host}:{port}{path}{token}',
'{schema}://{user}@{host}{path}{token}',
'{schema}://{user}@{host}:{port}{path}{token}',
'{schema}://{user}:{password}@{host}{path}{token}',
'{schema}://{user}:{password}@{host}:{port}{path}{token}',
)
# Define our template tokens
@ -133,6 +141,12 @@ class NotifyNotica(NotifyBase):
'type': 'string',
'private': True,
},
'path': {
'name': _('Path'),
'type': 'string',
'map_to': 'fullpath',
'default': '/',
},
})
# Define any kwargs we're using

View File

@ -803,6 +803,20 @@ TEST_URLS = (
# Our expected url(privacy=True) startswith() response:
'privacy_url': 'gotify://hostname/t...t',
}),
# Provide a hostname, path, and token
('gotify://hostname/a/path/ending/in/a/slash/%s' % ('u' * 16), {
'instance': plugins.NotifyGotify,
# Our expected url(privacy=True) startswith() response:
'privacy_url': 'gotify://hostname/a/path/ending/in/a/slash/u...u/',
}),
# Provide a hostname, path, and token
('gotify://hostname/a/path/not/ending/in/a/slash/%s' % ('v' * 16), {
'instance': plugins.NotifyGotify,
# Our expected url(privacy=True) startswith() response:
'privacy_url': 'gotify://hostname/a/path/not/ending/in/a/slash/v...v/',
}),
# Provide a priority
('gotify://hostname/%s?priority=high' % ('i' * 16), {
'instance': plugins.NotifyGotify,