forked from borgmatic-collective/borgmatic
add support for basic auth on self-hosted instances
This commit is contained in:
parent
673ed1a2d3
commit
7a9c17928a
|
@ -916,6 +916,18 @@ properties:
|
||||||
description: |
|
description: |
|
||||||
The address of your self-hosted ntfy.sh instance.
|
The address of your self-hosted ntfy.sh instance.
|
||||||
example: https://ntfy.your-domain.com
|
example: https://ntfy.your-domain.com
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
description: |
|
||||||
|
The username for your self-hosted ntfy.sh instance
|
||||||
|
(ignored for the upstream-hosted instance)
|
||||||
|
example: borgmatic
|
||||||
|
password:
|
||||||
|
type: string
|
||||||
|
description: |
|
||||||
|
The password for your self-hosted ntfy.sh instance.
|
||||||
|
(ignored for the upstream-hosted instance)
|
||||||
|
example: superSecretP@ssw0rd
|
||||||
start:
|
start:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -56,6 +56,15 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_
|
||||||
'X-Tags': state_config.get('tags'),
|
'X-Tags': state_config.get('tags'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
base_url != 'https://ntfy.sh'
|
||||||
|
and hook_config.get('username') is not None
|
||||||
|
and hook_config.get('password') is not None
|
||||||
|
):
|
||||||
|
headers.update(
|
||||||
|
{'Authorization': f'{hook_config.get("username")}:{hook_config.get("password")}'}
|
||||||
|
)
|
||||||
|
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
logging.getLogger('urllib3').setLevel(logging.ERROR)
|
logging.getLogger('urllib3').setLevel(logging.ERROR)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -286,6 +286,10 @@ so the default messages are intentionally generic. These can be overridden, depe
|
||||||
on your risk assessment. Each `state` can have its own custom messages, priorities and tags
|
on your risk assessment. Each `state` can have its own custom messages, priorities and tags
|
||||||
or, if none are provided, will use the default.
|
or, if none are provided, will use the default.
|
||||||
|
|
||||||
|
A [self-hosted ntfy instance](https://ntfy.sh/docs/install/) can be used if desired,
|
||||||
|
including support for Basic Authentication using the `username` and `password` fields
|
||||||
|
with a custom `server` value
|
||||||
|
|
||||||
An example configuration is shown here, with all the available options, including
|
An example configuration is shown here, with all the available options, including
|
||||||
[priorities](https://ntfy.sh/docs/publish/#message-priority) and
|
[priorities](https://ntfy.sh/docs/publish/#message-priority) and
|
||||||
[tags](https://ntfy.sh/docs/publish/#tags-emojis):
|
[tags](https://ntfy.sh/docs/publish/#tags-emojis):
|
||||||
|
@ -295,6 +299,8 @@ hooks:
|
||||||
ntfy:
|
ntfy:
|
||||||
topic: my-unique-topic
|
topic: my-unique-topic
|
||||||
server: https://ntfy.my-domain.com
|
server: https://ntfy.my-domain.com
|
||||||
|
username: borgmatic
|
||||||
|
password: superSecretP@ssw0rd
|
||||||
start:
|
start:
|
||||||
title: A Borgmatic backup started
|
title: A Borgmatic backup started
|
||||||
message: Watch this space...
|
message: Watch this space...
|
||||||
|
|
|
@ -155,3 +155,23 @@ def test_ping_monitor_with_other_error_logs_warning():
|
||||||
monitoring_log_level=1,
|
monitoring_log_level=1,
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ping_monitor_minimal_config_hits_selfhosted_with_custom_auth():
|
||||||
|
hook_config = {
|
||||||
|
'topic': topic,
|
||||||
|
'server': custom_base_url,
|
||||||
|
'username': 'unittesting',
|
||||||
|
'password': 'dummypassword',
|
||||||
|
}
|
||||||
|
expected_headers = {
|
||||||
|
**return_default_message_headers(module.monitor.State.FAIL),
|
||||||
|
'Authorization': 'unittesting:dummypassword',
|
||||||
|
}
|
||||||
|
flexmock(module.requests).should_receive('post').with_args(
|
||||||
|
f'{custom_base_url}/{topic}', headers=expected_headers,
|
||||||
|
).and_return(flexmock(ok=True)).once()
|
||||||
|
|
||||||
|
module.ping_monitor(
|
||||||
|
hook_config, 'config.yaml', module.monitor.State.FAIL, monitoring_log_level=1, dry_run=False
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue