refactored + testing added

pull/186/head
Chris Caron 2019-12-09 22:53:13 -05:00
parent 88564d4d67
commit 5949e757fa
5 changed files with 96 additions and 23 deletions

View File

@ -50,6 +50,7 @@ The table below identifies the services this tool supports and some example serv
| [Matrix](https://github.com/caronc/apprise/wiki/Notify_matrix) | matrix:// or matrixs:// | (TCP) 80 or 443 | matrix://hostname<br />matrix://user@hostname<br />matrixs://user:pass@hostname:port/#room_alias<br />matrixs://user:pass@hostname:port/!room_id<br />matrixs://user:pass@hostname:port/#room_alias/!room_id/#room2<br />matrixs://token@hostname:port/?webhook=matrix<br />matrix://user:token@hostname/?webhook=slack&format=markdown
| [Mattermost](https://github.com/caronc/apprise/wiki/Notify_mattermost) | mmost:// | (TCP) 8065 | mmost://hostname/authkey<br />mmost://hostname:80/authkey<br />mmost://user@hostname:80/authkey<br />mmost://hostname/authkey?channel=channel<br />mmosts://hostname/authkey<br />mmosts://user@hostname/authkey<br />
| [Microsoft Teams](https://github.com/caronc/apprise/wiki/Notify_msteams) | msteams:// | (TCP) 443 | msteams://TokenA/TokenB/TokenC/
| [NextCloud](https://github.com/caronc/apprise/wiki/Notify_nextcloud) | ncloud:// or nclouds:// | (TCP) 80 or 443 | ncloud://adminuser:pass@host/User<br/>nclouds://adminuser:pass@host/User1/User2/UserN
| [Notica](https://github.com/caronc/apprise/wiki/Notify_notica) | notica:// | (TCP) 443 | notica://Token/
| [Notifico](https://github.com/caronc/apprise/wiki/Notify_notifico) | notifico:// | (TCP) 443 | notifico://ProjectID/MessageHook/
| [Prowl](https://github.com/caronc/apprise/wiki/Notify_prowl) | prowl:// | (TCP) 443 | prowl://apikey<br />prowl://apikey/providerkey

View File

@ -43,10 +43,10 @@ class NotifyNextCloud(NotifyBase):
service_url = 'https://github.com/nextcloud/notifications'
# Insecure protocol (for those self hosted requests)
protocol = 'nextcloud'
protocol = 'ncloud'
# The default protocol (this is secure for notica)
secure_protocol = 'nextclouds'
secure_protocol = 'nclouds'
# A URL that takes you to the setup/help of the specific protocol
setup_url = 'https://github.com/caronc/apprise/wiki/Notify_nextcloud'
@ -89,13 +89,11 @@ class NotifyNextCloud(NotifyBase):
'user': {
'name': _('Username'),
'type': 'string',
'required': True,
},
'password': {
'name': _('Password'),
'type': 'string',
'private': True,
'required': True,
},
'target_user': {
'name': _('Target User'),
@ -162,8 +160,9 @@ class NotifyNextCloud(NotifyBase):
else:
payload['shortMessage'] = body
# Auth is used for SELFHOSTED queries
auth = (self.user, self.password)
auth = None
if self.user:
auth = (self.user, self.password)
notify_url = self.notify_url.format(
schema='https' if self.secure else 'http',
@ -182,7 +181,7 @@ class NotifyNextCloud(NotifyBase):
try:
r = requests.post(
notify_url.format(token=self.token),
notify_url,
data=payload,
headers=headers,
auth=auth,
@ -238,11 +237,18 @@ class NotifyNextCloud(NotifyBase):
# Append our headers into our args
args.update({'+{}'.format(k): v for k, v in self.headers.items()})
auth = '{user}:{password}@'.format(
user=NotifyNextCloud.quote(self.user, safe=''),
password=self.pprint(
self.password, privacy, mode=PrivacyMode.Secret, safe=''),
)
# Determine Authentication
auth = ''
if self.user and self.password:
auth = '{user}:{password}@'.format(
user=NotifyNextCloud.quote(self.user, safe=''),
password=self.pprint(
self.password, privacy, mode=PrivacyMode.Secret, safe=''),
)
elif self.user:
auth = '{user}@'.format(
user=NotifyNextCloud.quote(self.user, safe=''),
)
default_port = 443 if self.secure else 80
@ -254,8 +260,6 @@ class NotifyNextCloud(NotifyBase):
hostname=NotifyNextCloud.quote(self.host, safe=''),
port='' if self.port is None or self.port == default_port
else ':{}'.format(self.port),
fullpath=NotifyNextCloud.quote(
self.fullpath, safe='/'),
targets='/'.join([NotifyNextCloud.quote(x)
for x in self.targets]),
args=NotifyNextCloud.urlencode(args),
@ -268,7 +272,8 @@ class NotifyNextCloud(NotifyBase):
us to substantiate this object.
"""
results = NotifyBase.parse_url(url, verify_host=False)
results = NotifyBase.parse_url(url)
if not results:
# We're done early as we couldn't load the results
return results

View File

@ -49,10 +49,11 @@ it easy to access:
Boxcar, ClickSend, Discord, E-Mail, Emby, Faast, Flock, Gitter, Gotify, Growl,
IFTTT, Join, KODI, Kumulos, Mailgun, MatterMost, Matrix, Microsoft Windows
Notifications, Microsoft Teams, MessageBird, MSG91, Nexmo, Notica, Notifico,
Notify MyAndroid, Prowl, Pushalot, PushBullet, Pushjet, Pushover, PushSafer,
Rocket.Chat, SendGrid, SimplePush, Slack, Super Toasty, Stride, Syslog,
Techulus Push, Telegram, Twilio, Twitter, Twist, XBMC, XMPP, Webex Teams}
Notifications, Microsoft Teams, MessageBird, MSG91, Nexmo, NextCloud, Notica,
Notifico, Notify MyAndroid, Prowl, Pushalot, PushBullet, Pushjet, Pushover,
PushSafer, Rocket.Chat, SendGrid, SimplePush, Slack, Super Toasty, Stride,
Syslog, Techulus Push, Telegram, Twilio, Twitter, Twist, XBMC, XMPP,
Webex Teams}
Name: python-%{pypi_name}
Version: 0.8.2

View File

@ -72,10 +72,10 @@ setup(
keywords='Push Notifications Alerts Email AWS SNS Boxcar ClickSend '
'Discord Dbus Emby Faast Flock Gitter Gnome Gotify Growl IFTTT Join '
'KODI Kumulos Mailgun Matrix Mattermost MessageBird MSG91 Nexmo '
'Notica, Notifico Prowl PushBullet Pushjet Pushed Pushover PushSafer '
'Rocket.Chat Ryver SendGrid SimplePush Slack Stride Syslog Techulus '
'Push Telegram Twilio Twist Twitter XBMC Microsoft MSTeams Windows '
'Webex CLI API',
'NextCloud Notica, Notifico Prowl PushBullet Pushjet Pushed Pushover '
'PushSafer Rocket.Chat Ryver SendGrid SimplePush Slack Stride Syslog '
'Techulus Push Telegram Twilio Twist Twitter XBMC Microsoft MSTeams '
'Windows Webex CLI API',
author='Chris Caron',
author_email='lead2gold@gmail.com',
packages=find_packages(),

View File

@ -1737,6 +1737,72 @@ TEST_URLS = (
'test_requests_exceptions': True,
}),
##################################
# NotifyNextCloud
##################################
('ncloud://:@/', {
'instance': None,
}),
('ncloud://', {
'instance': None,
}),
('nclouds://', {
# No hostname
'instance': None,
}),
('ncloud://localhost', {
# No user specified
'instance': TypeError,
}),
('ncloud://localhost/admin', {
'instance': plugins.NotifyNextCloud,
}),
('ncloud://user@localhost/admin', {
'instance': plugins.NotifyNextCloud,
}),
('ncloud://user@localhost?to=user1,user2', {
'instance': plugins.NotifyNextCloud,
}),
('ncloud://user:pass@localhost/user1/user2', {
'instance': plugins.NotifyNextCloud,
# Our expected url(privacy=True) startswith() response:
'privacy_url': 'ncloud://user:****@localhost/user1/user2',
}),
('ncloud://user:pass@localhost:8080/admin', {
'instance': plugins.NotifyNextCloud,
}),
('nclouds://user:pass@localhost/admin', {
'instance': plugins.NotifyNextCloud,
# Our expected url(privacy=True) startswith() response:
'privacy_url': 'nclouds://user:****@localhost/admin',
}),
('nclouds://user:pass@localhost:8080/admin/', {
'instance': plugins.NotifyNextCloud,
}),
('ncloud://localhost:8080/admin?-HeaderKey=HeaderValue', {
'instance': plugins.NotifyNextCloud,
}),
('ncloud://user:pass@localhost:8081/admin', {
'instance': plugins.NotifyNextCloud,
# force a failure
'response': False,
'requests_response_code': requests.codes.internal_server_error,
}),
('ncloud://user:pass@localhost:8082/admin', {
'instance': plugins.NotifyNextCloud,
# throw a bizzare code forcing us to fail to look it up
'response': False,
'requests_response_code': 999,
}),
('ncloud://user:pass@localhost:8083/user1/user2/user3', {
'instance': plugins.NotifyNextCloud,
# Throws a series of connection and transfer exceptions when this flag
# is set and tests that we gracfully handle them
'test_requests_exceptions': True,
}),
##################################
# NotifyProwl
##################################