Skip to content

Commit

Permalink
Logging improvements and code tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Apr 20, 2024
1 parent 9be5a8d commit ef30289
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 90 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ curl -X POST -d '{"tag":"leaders teamA, leaders teamB", "body":"meeting now"}' \
| 400 | bad request | Your API call did not conform to what was documented here
| 405 | method not accepted | Your API call identified an action that has been disabled due to the Server configuration (such as a `apprise://` `APPRISE_RECURSION_MAX` being exceeded).
| 424 | failed dependency | At least one notification could not be sent. This can be due to<br/> - Not all notifications intended to be actioned could follow through (due to upstrem failures).<br/>You didn't idenify a tag associated with what was defined in your configuration.<br/>The tag(s) you specified do not match with those defined in your configuration.
| 431 | fields too large | This can happen if you're payload is larger then 3MB (default value). See `APPRISE_UPLOAD_MAX_MEMORY_SIZE` to adjust this.
| 500 | internal server error | This can occur if there was an issue saving your configuration to disk (usually the cause of permission issues).


Expand All @@ -358,6 +359,7 @@ The use of environment variables allow you to provide over-rides to default sett
| `APPRISE_CONFIG_DIR` | Defines an (optional) persistent store location of all configuration files saved. By default:<br/> - Configuration is written to the `apprise_api/var/config` directory when just using the _Django_ `manage runserver` script. However for the path for the container is `/config`.
| `APPRISE_ATTACH_DIR` | The directory the uploaded attachments are placed in. By default:<br/> - Attachments are written to the `apprise_api/var/attach` directory when just using the _Django_ `manage runserver` script. However for the path for the container is `/attach`.
| `APPRISE_ATTACH_SIZE` | Over-ride the attachment size (defined in MB). By default it is set to `200` (Megabytes). You can set this up to a maximum value of `500` which is the restriction in place for NginX (internal hosting ervice) at this time. If you set this to zero (`0`) then attachments will not be passed along even if provided.
| `APPRISE_UPLOAD_MAX_MEMORY_SIZE` | Over-ride the in-memory accepted payload size (defined in MB). By default it is set to `3` (Megabytes). There is no reason the HTTP payload (excluding attachments) should exceed this limit. This value is only configurable for those who have edge cases where there are exceptions to this rule.
| `APPRISE_STATELESS_URLS` | For a non-persistent solution, you can take advantage of this global variable. Use this to define a default set of Apprise URLs to notify when using API calls to `/notify`. If no `{KEY}` is defined when calling `/notify` then the URLs defined here are used instead. By default, nothing is defined for this variable.
| `APPRISE_STATEFUL_MODE` | This can be set to the following possible modes:<br/>📌 **hash**: This is also the default. It stores the server configuration in a hash formatted that can be easily indexed and compressed.<br/>📌 **simple**: Configuration is written straight to disk using the `{KEY}.cfg` (if `TEXT` based) and `{KEY}.yml` (if `YAML` based).<br/>📌 **disabled**: Straight up deny any read/write queries to the servers stateful store. Effectively turn off the Apprise Stateful feature completely.
| `APPRISE_CONFIG_LOCK` | Locks down your API hosting so that you can no longer delete/update/access stateful information. Your configuration is still referenced when stateful calls are made to `/notify`. The idea of this switch is to allow someone to set their (Apprise) configuration up and then as an added security tactic, they may choose to lock their configuration down (in a read-only state). Those who use the Apprise CLI tool may still do it, however the `--config` (`-c`) switch will not successfully reference this access point anymore. You can however use the `apprise://` plugin without any problem ([see here for more details](https://github.com/caronc/apprise/wiki/Notify_apprise_api)). This defaults to `no` and can however be set to `yes` by simply defining the global variable as such.
Expand Down
40 changes: 34 additions & 6 deletions apprise_api/api/tests/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def test_notify_by_loaded_urls_with_json(self, mock_notify):

# Preare our JSON data
json_data = {
'body': 'test notifiction',
'body': 'test notification',
'type': apprise.NotifyType.WARNING,
}

Expand Down Expand Up @@ -1059,6 +1059,7 @@ def test_notify_by_loaded_urls_with_json(self, mock_notify):

headers = {
'HTTP_X_APPRISE_LOG_LEVEL': 'debug',
# Accept is over-ridden to be that of the content type
'HTTP_ACCEPT': 'text/plain',
}

Expand All @@ -1072,15 +1073,28 @@ def test_notify_by_loaded_urls_with_json(self, mock_notify):

assert response.status_code == 200
assert mock_notify.call_count == 1
assert response['content-type'] == 'text/plain'
assert response['content-type'] == 'application/json'

mock_notify.reset_mock()

# Test referencing a key that doesn't exist
response = self.client.post(
'/notify/{}'.format(key),
data={'body': 'test'},
**headers,
)

assert response.status_code == 200
assert mock_notify.call_count == 1
assert response['content-type'].startswith('text/html')

mock_notify.reset_mock()

headers = {
'HTTP_X_APPRISE_LOG_LEVEL': 'debug',
'HTTP_ACCEPT': 'text/html',
}

mock_notify.reset_mock()

# Test referencing a key that doesn't exist
response = self.client.post(
'/notify/{}'.format(key),
Expand All @@ -1091,7 +1105,7 @@ def test_notify_by_loaded_urls_with_json(self, mock_notify):

assert response.status_code == 200
assert mock_notify.call_count == 1
assert response['content-type'] == 'text/html'
assert response['content-type'] == 'application/json'

headers = {
'HTTP_X_APPRISE_LOG_LEVEL': 'invalid',
Expand All @@ -1110,7 +1124,21 @@ def test_notify_by_loaded_urls_with_json(self, mock_notify):

assert response.status_code == 200
assert mock_notify.call_count == 1
assert response['content-type'] == 'text/html'
assert response['content-type'] == 'application/json'

mock_notify.reset_mock()

# Test referencing a key that doesn't exist
response = self.client.post(
'/notify/{}'.format(key),
data=json_data,
**headers,
)

assert response.status_code == 200
assert mock_notify.call_count == 1
assert response['content-type'].startswith('text/html')


@mock.patch('apprise.plugins.NotifyEmail.NotifyEmail.send')
def test_notify_with_filters(self, mock_send):
Expand Down
Loading

0 comments on commit ef30289

Please sign in to comment.