Refactored input validation

This commit is contained in:
CasVT
2025-04-23 19:55:41 +02:00
parent b4057155e7
commit 3892b9754e
8 changed files with 1111 additions and 1038 deletions

View File

@@ -6,7 +6,7 @@
from os.path import dirname
from subprocess import run
from sys import path
from typing import Type
from typing import List, Type, Union
path.insert(0, dirname(dirname(__file__)))
@@ -16,13 +16,13 @@ from backend.base.custom_exceptions import (NotificationServiceNotFound,
from backend.base.definitions import MindException, StartType
from backend.base.helpers import folder_path
from backend.internals.server import Server
from frontend.input_validation import DataSource, api_docs
from frontend.input_validation import API_DOCS, DataSource, InputVariable
# autopep8: on
api_prefix = Server.api_prefix
admin_prefix = Server.admin_prefix
api_file = folder_path('docs', 'src', 'other_docs', 'api.md')
API_PREFIX = Server.api_prefix
ADMIN_PREFIX = Server.admin_prefix
API_FILE = folder_path('docs', 'src', 'other_docs', 'api.md')
url_var_map = {
'int:n_id': NotificationServiceNotFound,
@@ -31,29 +31,15 @@ url_var_map = {
'int:s_id': ReminderNotFound
}
def make_exception_instance(cls: Type[MindException]) -> MindException:
try:
return cls()
except TypeError:
try:
return cls('1')
except TypeError:
try:
return cls('1', '2')
except AttributeError:
return cls('1', StartType.STARTUP)
result = f"""# API
Below is the API documentation. Report an issue on [GitHub](https://github.com/Casvt/MIND/issues).
All endpoints have the `{api_prefix}` prefix. That means, for example, that `/auth/login` can be reached at `{api_prefix}/auth/login`.
All endpoints have the `{API_PREFIX}` prefix. That means, for example, that `/auth/login` can be reached at `{API_PREFIX}/auth/login`.
## Authentication
Authentication is done using an API key.
To log in, make a POST request to the [`{api_prefix}/auth/login`](#authlogin) endpoint.
To log in, make a POST request to the [`{API_PREFIX}/auth/login`](#authlogin) endpoint.
You'll receive an API key, which you can then use in your requests to authenticate.
Supply it via the url parameter `api_key`.
This API key is valid for one hour (though the admin can change this duration) after which the key expires, any further requests return 401 'APIKeyExpired' and you are required to log in again.
@@ -61,7 +47,7 @@ If no `api_key` is supplied or it is invalid, 401 `APIKeyInvalid` is returned.
For example:
```bash
curl -sSL 'http://192.168.2.15:8080{api_prefix}/reminders?api_key=ABCDEFG'
curl -sSL 'http://192.168.2.15:8080{API_PREFIX}/reminders?api_key=ABCDEFG'
```
## Supplying data
@@ -75,19 +61,19 @@ Often, data needs to be supplied with a request:
For example:
```bash
# URL parameter
curl -sSL 'http://192.168.2.15:8080{api_prefix}/reminders/search?api_key=ABCDEFG&query=Fountain&sort_by=time_reversed'
curl -sSL 'http://192.168.2.15:8080{API_PREFIX}/reminders/search?api_key=ABCDEFG&query=Fountain&sort_by=time_reversed'
# Body parameter
curl -sSLX POST \\
-H 'Content-Type: application/json' \\
-d '{{"title": "Test service", "url": "test://fake/url"}}' \\
'http://192.168.2.15:8080{api_prefix}/notificationservices?api_key=ABCDEFG'
'http://192.168.2.15:8080{API_PREFIX}/notificationservices?api_key=ABCDEFG'
# File parameter
curl -sSLX POST \\
-H 'Content-Type: multipart/form-data' \\
-F file=@/backups/MIND_backup.db \\
'http://192.168.2.15:8080{admin_prefix}/database?api_key=ABCDEFG'
'http://192.168.2.15:8080{ADMIN_PREFIX}/database?api_key=ABCDEFG'
```
@@ -95,97 +81,177 @@ curl -sSLX POST \\
The following is automatically generated. Please report any issues on [GitHub](https://github.com/Casvt/MIND/issues).
"""
for rule, data in api_docs.items():
result += f"""### `{rule}`
def make_exception_instance(cls: Type[MindException]) -> MindException:
for args in (
(),
('1'),
('1', '2'),
('1', StartType.STARTUP)
):
try:
inst = cls(*args)
except (TypeError, AttributeError):
continue
else:
return inst
raise RuntimeError("Unsupported exception parameter")
def extract_url_var(endpoint: str) -> Union[str, None]:
split = endpoint.replace('<', '>').split('>')
return None if len(split) == 1 else split[1]
def rule_header(endpoint: str, requires_auth: bool, description: str) -> str:
return f"""### `{endpoint}`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| {'Yes' if data.requires_auth else 'No'} | {data.description} |
| {'Yes' if requires_auth else 'No'} | {description} |
"""
url_var = rule.replace('<', '>').split('>')
url_var = None if len(url_var) == 1 else url_var[1]
if url_var:
result += f"""
Replace `<{url_var}>` with the ID of the entry. For example: `{rule.replace(f'<{url_var}>', '2')}`.
def url_var_note(endpoint: str, url_var: str) -> str:
return f"""
Replace `<{url_var}>` with the ID of the entry. For example: `{endpoint.replace(f'<{url_var}>', '2')}`.
"""
for m_name, method in ((m, data.methods[m])
for m in data.methods.used_methods()):
if method is None:
continue
result += f"\n??? {m_name}\n"
def method_body(name: str, description: str) -> str:
r = f"\n??? {name.upper()}\n"
if method.description:
result += f"\n {method.description}\n"
if description:
r += f"\n {description}\n"
var_types = {
'url': [
v for v in method.vars if v.source == DataSource.VALUES
],
'body': [
v for v in method.vars if v.source == DataSource.DATA
],
'file': [
v for v in method.vars if v.source == DataSource.FILES
]
}
return r
for var_type, entries in var_types.items():
if entries:
result += f"""
def method_parameters(
var_type: str,
variables: List[Type[InputVariable]]
) -> str:
r = f"""
**Parameters ({var_type})**
| Name | Required | Data type | Description | Allowed values |
| ---- | -------- | --------- | ----------- | -------------- |
"""
for entry in entries:
result += f" {super(entry, entry('', entry.name, entry.description)).__repr__()}\n"
result += f"""
for var in variables:
r += " | %s | %s | %s | %s | %s |\n" % (
var.name, 'Yes' if var.required else 'No',
','.join(v.value for v in var.data_type), var.description,
", ".join(str(v) for v in var.options) or "N/A"
)
return r
def return_codes(
method_name: str,
exceptions: List[MindException]
) -> str:
r = f"""
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| {201 if m_name == 'POST' else 200} | N/A | Success |
| {201 if method_name == 'post' else 200} | N/A | Success |
"""
url_exception = [url_var_map[url_var]] if url_var in url_var_map else []
variable_exceptions = [
e
for v in method.vars
for e in v('t', v.name, v.description).related_exceptions
]
related_exceptions = sorted(
(
make_exception_instance(e)
for e in set(variable_exceptions + url_exception)
),
key=lambda e: (
e.api_response["code"],
e.api_response["error"]
)
for exception in exceptions:
r += " | %d | %s | %s |\n" % (
exception.api_response['code'], exception.api_response['error'],
exception.__doc__
)
for related_exception in related_exceptions:
ar = related_exception.api_response
result += f" | {ar['code']} | {ar['error']} | {related_exception.__doc__} |\n"
result += '\n'
return r
with open(api_file, 'r') as f:
current_content = f.read()
if current_content == result:
print('Nothing changed')
else:
with open(api_file, 'w+') as f:
f.write(result)
def create_result(base_string: str) -> str:
for endpoint, data in API_DOCS.items():
# Add header
base_string += rule_header(
endpoint,
data.requires_auth,
data.description
)
run(["git", "config", "--global", "user.email", '"casvantijn@gmail.com"'])
run(["git", "config", "--global", "user.name", '"CasVT"'])
run(["git", "checkout", "Development"])
run(["git", "add", api_file])
run(["git", "commit", "-m", "Updated API docs"])
run(["git", "push"])
# Add note about url var
url_var = extract_url_var(endpoint)
if url_var:
base_string += url_var_note(endpoint, url_var)
# Add info for each method
for m_name, method in (
(m, data.methods[m])
for m in data.methods.used_methods()
):
if method is None:
continue
# Add basic method info
base_string += method_body(m_name, method.description)
# Add input variable info
var_types = {
'url': [
v for v in method.input_variables if v.source == DataSource.VALUES
],
'body': [
v for v in method.input_variables if v.source == DataSource.DATA
],
'file': [
v for v in method.input_variables if v.source == DataSource.FILES
]
}
for var_type, entries in var_types.items():
if entries:
base_string += method_parameters(var_type, entries)
url_exception = (
[url_var_map[url_var]]
if url_var in url_var_map else
[]
)
variable_exceptions = [
e
for v in method.input_variables
for e in v.related_exceptions
]
related_exceptions = sorted(
(
make_exception_instance(e)
for e in set(variable_exceptions + url_exception)
),
key=lambda e: (
e.api_response["code"],
e.api_response["error"]
)
)
base_string += return_codes(m_name, related_exceptions)
base_string += '\n'
return base_string.strip()
if __name__ == '__main__':
result = create_result(result)
with open(API_FILE, 'r') as f:
current_content = f.read()
if current_content == result:
print('Nothing changed')
else:
with open(API_FILE, 'w+') as f:
f.write(result)
# run(["git", "config", "--global", "user.email", '"casvantijn@gmail.com"'])
# run(["git", "config", "--global", "user.name", '"CasVT"'])
# run(["git", "checkout", "Development"])
# run(["git", "add", API_FILE])
# run(["git", "commit", "-m", "Updated API docs"])
# run(["git", "push"])

View File

@@ -19,9 +19,11 @@ curl -sSL 'http://192.168.2.15:8080/api/reminders?api_key=ABCDEFG'
## Supplying data
Often, data needs to be supplied with a request.
If the parameters need to be supplied via `url`, add them to the url as url parameters.
If the parameters need to be supplied via `body`, add them to the body as a json object and supply the `Content-Type: application/json` header.
Often, data needs to be supplied with a request:
- If the parameters need to be supplied via `url`, add them to the url as url parameters.
- If the parameters need to be supplied via `body`, add them to the body as a json object and supply the `Content-Type: application/json` header.
- If the parameters need to be supplied via `file`, send them as form data values and supply the `Content-Type: multipart/form-data` header.
For example:
```bash
@@ -33,6 +35,13 @@ curl -sSLX POST \
-H 'Content-Type: application/json' \
-d '{"title": "Test service", "url": "test://fake/url"}' \
'http://192.168.2.15:8080/api/notificationservices?api_key=ABCDEFG'
# File parameter
curl -sSLX POST \
-H 'Content-Type: multipart/form-data' \
-F file=@/backups/MIND_backup.db \
'http://192.168.2.15:8080/api/admin/database?api_key=ABCDEFG'
```
## Endpoints
@@ -41,7 +50,7 @@ The following is automatically generated. Please report any issues on [GitHub](h
| Requires being logged in | Description |
| ------------------------ | ----------- |
| No | Login to a user account |
| No | Login to a user account |
??? POST
@@ -53,24 +62,24 @@ The following is automatically generated. Please report any issues on [GitHub](h
| password | Yes | string | The password of the user account | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
| 400 | KeyNotFound | A key was not found in the input that is required to be given |
| 400 | UsernameInvalid | The username contains invalid characters or is not allowed |
| 401 | AccessUnauthorized | The password given is not correct |
| 404 | UserNotFound | The user requested can not be found |
### `/auth/logout`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Logout of a user account |
| Yes | Logout of a user account |
??? POST
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
@@ -79,12 +88,12 @@ The following is automatically generated. Please report any issues on [GitHub](h
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Get current status of login |
| Yes | Get current status of login |
??? GET
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -93,7 +102,7 @@ The following is automatically generated. Please report any issues on [GitHub](h
| Requires being logged in | Description |
| ------------------------ | ----------- |
| No | Create a new user account |
| No | Create a new user account |
??? POST
@@ -105,12 +114,12 @@ The following is automatically generated. Please report any issues on [GitHub](h
| password | Yes | string | The password of the user account | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
| 400 | KeyNotFound | A key was not found in the input that is required to be given |
| 400 | UsernameInvalid | The username contains invalid characters |
| 400 | UsernameInvalid | The username contains invalid characters or is not allowed |
| 400 | UsernameTaken | The username is already taken |
| 403 | NewAccountsNotAllowed | It's not allowed to create a new account except for the admin |
@@ -118,7 +127,7 @@ The following is automatically generated. Please report any issues on [GitHub](h
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage a user account |
| Yes | Manage a user account |
??? PUT
@@ -131,7 +140,7 @@ The following is automatically generated. Please report any issues on [GitHub](h
| new_password | Yes | string | The new password of the user account | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -142,7 +151,7 @@ The following is automatically generated. Please report any issues on [GitHub](h
Delete the user account
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -151,14 +160,14 @@ The following is automatically generated. Please report any issues on [GitHub](h
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage the notification services |
| Yes | Manage the notification services |
??? GET
Get a list of all notification services
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -175,7 +184,7 @@ The following is automatically generated. Please report any issues on [GitHub](h
| url | Yes | string | The Apprise URL of the notification service | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
@@ -186,12 +195,12 @@ The following is automatically generated. Please report any issues on [GitHub](h
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Get all available notification services and their url layout |
| Yes | Get all available notification services and their URL layout |
??? GET
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -200,7 +209,7 @@ The following is automatically generated. Please report any issues on [GitHub](h
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Send a test notification using the supplied Apprise URL |
| Yes | Send a test notification using the supplied Apprise URL |
??? POST
@@ -211,7 +220,7 @@ The following is automatically generated. Please report any issues on [GitHub](h
| url | Yes | string | The Apprise URL of the notification service | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
@@ -222,14 +231,16 @@ The following is automatically generated. Please report any issues on [GitHub](h
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage a specific notification service |
| Yes | Manage a specific notification service |
Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservices/2`.
??? GET
Get info of the notification service
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -247,7 +258,7 @@ Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservic
| url | No | string | The Apprise URL of the notification service | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -262,10 +273,10 @@ Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservic
| Name | Required | Data type | Description | Allowed values |
| ---- | -------- | --------- | ----------- | -------------- |
| delete_reminders_using | No | bool | Instead of throwing an error when there are still reminders using the service, delete the reminders. | N/A |
| delete_reminders_using | No | string | Instead of throwing an error when there are still reminders using the service, delete the reminders | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -276,20 +287,20 @@ Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservic
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage the reminders |
| Yes | Manage the reminders |
??? GET
Get a list of all reminders
Get a list of reminders
**Parameters (url)**
| Name | Required | Data type | Description | Allowed values |
| ---- | -------- | --------- | ----------- | -------------- |
| sort_by | No | string | How to sort the result | `time`, `time_reversed`, `title`, `title_reversed`, `date_added`, `date_added_reversed` |
| sort_by | No | string | How to sort the result | time, time_reversed, title, title_reversed, date_added, date_added_reversed |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -307,13 +318,13 @@ Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservic
| time | Yes | number,decimal number | The UTC epoch timestamp that the reminder should be sent at | N/A |
| notification_services | Yes | list of numbers | Array of the id's of the notification services to use to send the notification | N/A |
| text | No | string | The body of the entry | N/A |
| repeat_quantity | No | string | The quantity of the repeat_interval | `years`, `months`, `weeks`, `days`, `hours`, `minutes` |
| repeat_quantity | No | string | The quantity of the repeat_interval | years, months, weeks, days, hours, minutes |
| repeat_interval | No | number | The number of the interval | N/A |
| weekdays | No | list of numbers | On which days of the weeks to run the reminder | `0`, `1`, `2`, `3`, `4`, `5`, `6` |
| color | No | string | The hex code of the color of the entry, which is shown in the web-ui | N/A |
| weekdays | No | list of numbers | On which days of the week to run the reminder | 0, 1, 2, 3, 4, 5, 6 |
| color | No | string | The hex code of the color of the entry, which is shown in the web-UI | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
@@ -326,7 +337,7 @@ Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservic
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Search through the list of reminders |
| Yes | Search for reminders |
??? GET
@@ -334,11 +345,11 @@ Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservic
| Name | Required | Data type | Description | Allowed values |
| ---- | -------- | --------- | ----------- | -------------- |
| sort_by | No | string | How to sort the result | `time`, `time_reversed`, `title`, `title_reversed`, `date_added`, `date_added_reversed` |
| query | Yes | string | The search term | N/A |
| sort_by | No | string | How to sort the result | time, time_reversed, title, title_reversed, date_added, date_added_reversed |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -349,7 +360,7 @@ Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservic
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Test send a reminder draft |
| Yes | Test send a reminder draft |
??? POST
@@ -362,7 +373,7 @@ Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservic
| text | No | string | The body of the entry | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
@@ -374,18 +385,20 @@ Replace `<int:n_id>` with the ID of the entry. For example: `/notificationservic
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage a specific reminder |
| Yes | Manage a specific reminder |
Replace `<int:r_id>` with the ID of the entry. For example: `/reminders/2`.
??? GET
Get info of the reminder
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
| 404 | ReminderNotFound | The reminder with the id can not be found |
| 404 | ReminderNotFound | The reminder was not found |
??? PUT
@@ -399,37 +412,37 @@ Replace `<int:r_id>` with the ID of the entry. For example: `/reminders/2`.
| time | No | number,decimal number | The UTC epoch timestamp that the reminder should be sent at | N/A |
| notification_services | No | list of numbers | Array of the id's of the notification services to use to send the notification | N/A |
| text | No | string | The body of the entry | N/A |
| repeat_quantity | No | string | The quantity of the repeat_interval | `years`, `months`, `weeks`, `days`, `hours`, `minutes` |
| repeat_quantity | No | string | The quantity of the repeat_interval | years, months, weeks, days, hours, minutes |
| repeat_interval | No | number | The number of the interval | N/A |
| weekdays | No | list of numbers | On which days of the weeks to run the reminder | `0`, `1`, `2`, `3`, `4`, `5`, `6` |
| color | No | string | The hex code of the color of the entry, which is shown in the web-ui | N/A |
| weekdays | No | list of numbers | On which days of the week to run the reminder | 0, 1, 2, 3, 4, 5, 6 |
| color | No | string | The hex code of the color of the entry, which is shown in the web-UI | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
| 400 | InvalidKeyValue | The value of a key is invalid |
| 400 | InvalidTime | The time given is in the past |
| 404 | NotificationServiceNotFound | The notification service was not found |
| 404 | ReminderNotFound | The reminder with the id can not be found |
| 404 | ReminderNotFound | The reminder was not found |
??? DELETE
Delete the reminder
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
| 404 | ReminderNotFound | The reminder with the id can not be found |
| 404 | ReminderNotFound | The reminder was not found |
### `/templates`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage the templates |
| Yes | Manage the templates |
??? GET
@@ -439,10 +452,10 @@ Replace `<int:r_id>` with the ID of the entry. For example: `/reminders/2`.
| Name | Required | Data type | Description | Allowed values |
| ---- | -------- | --------- | ----------- | -------------- |
| sort_by | No | string | How to sort the result | `title`, `title_reversed`, `date_added`, `date_added_reversed` |
| sort_by | No | string | How to sort the result | title, title_reversed, date_added, date_added_reversed |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -459,10 +472,10 @@ Replace `<int:r_id>` with the ID of the entry. For example: `/reminders/2`.
| title | Yes | string | The title of the entry | N/A |
| notification_services | Yes | list of numbers | Array of the id's of the notification services to use to send the notification | N/A |
| text | No | string | The body of the entry | N/A |
| color | No | string | The hex code of the color of the entry, which is shown in the web-ui | N/A |
| color | No | string | The hex code of the color of the entry, which is shown in the web-UI | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
@@ -474,7 +487,7 @@ Replace `<int:r_id>` with the ID of the entry. For example: `/reminders/2`.
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Search through the list of templates |
| Yes | Search for templates |
??? GET
@@ -482,11 +495,11 @@ Replace `<int:r_id>` with the ID of the entry. For example: `/reminders/2`.
| Name | Required | Data type | Description | Allowed values |
| ---- | -------- | --------- | ----------- | -------------- |
| sort_by | No | string | How to sort the result | `title`, `title_reversed`, `date_added`, `date_added_reversed` |
| query | Yes | string | The search term | N/A |
| sort_by | No | string | How to sort the result | title, title_reversed, date_added, date_added_reversed |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -497,14 +510,16 @@ Replace `<int:r_id>` with the ID of the entry. For example: `/reminders/2`.
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage a specific template |
| Yes | Manage a specific template |
Replace `<int:t_id>` with the ID of the entry. For example: `/templates/2`.
??? GET
Get info of the template
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -521,10 +536,10 @@ Replace `<int:t_id>` with the ID of the entry. For example: `/templates/2`.
| title | No | string | The title of the entry | N/A |
| notification_services | No | list of numbers | Array of the id's of the notification services to use to send the notification | N/A |
| text | No | string | The body of the entry | N/A |
| color | No | string | The hex code of the color of the entry, which is shown in the web-ui | N/A |
| color | No | string | The hex code of the color of the entry, which is shown in the web-UI | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -537,7 +552,7 @@ Replace `<int:t_id>` with the ID of the entry. For example: `/templates/2`.
Delete the template
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -547,7 +562,7 @@ Replace `<int:t_id>` with the ID of the entry. For example: `/templates/2`.
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage the static reminders |
| Yes | Manage the static reminders |
??? GET
@@ -557,10 +572,10 @@ Replace `<int:t_id>` with the ID of the entry. For example: `/templates/2`.
| Name | Required | Data type | Description | Allowed values |
| ---- | -------- | --------- | ----------- | -------------- |
| sort_by | No | string | How to sort the result | `title`, `title_reversed`, `date_added`, `date_added_reversed` |
| sort_by | No | string | How to sort the result | title, title_reversed, date_added, date_added_reversed |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -577,10 +592,10 @@ Replace `<int:t_id>` with the ID of the entry. For example: `/templates/2`.
| title | Yes | string | The title of the entry | N/A |
| notification_services | Yes | list of numbers | Array of the id's of the notification services to use to send the notification | N/A |
| text | No | string | The body of the entry | N/A |
| color | No | string | The hex code of the color of the entry, which is shown in the web-ui | N/A |
| color | No | string | The hex code of the color of the entry, which is shown in the web-UI | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
@@ -592,7 +607,7 @@ Replace `<int:t_id>` with the ID of the entry. For example: `/templates/2`.
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Search through the list of staticreminders |
| Yes | Search for static reminders |
??? GET
@@ -600,44 +615,46 @@ Replace `<int:t_id>` with the ID of the entry. For example: `/templates/2`.
| Name | Required | Data type | Description | Allowed values |
| ---- | -------- | --------- | ----------- | -------------- |
| sort_by | No | string | How to sort the result | `title`, `title_reversed`, `date_added`, `date_added_reversed` |
| query | Yes | string | The search term | N/A |
| sort_by | No | string | How to sort the result | title, title_reversed, date_added, date_added_reversed |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
| 400 | InvalidKeyValue | The value of a key is invalid |
| 400 | KeyNotFound | A key was not found in the input that is required to be given |
### `/staticreminders/<int:s_id>`
### `staticreminders/<int:s_id>`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage a specific static reminder |
| Yes | Manage a specific static reminder |
Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`.
Replace `<int:s_id>` with the ID of the entry. For example: `staticreminders/2`.
??? GET
Get info of the static reminder
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
| 404 | ReminderNotFound | The reminder with the id can not be found |
| 404 | ReminderNotFound | The reminder was not found |
??? POST
Trigger the static reminder
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
| 404 | ReminderNotFound | The reminder with the id can not be found |
| 404 | ReminderNotFound | The reminder was not found |
??? PUT
@@ -650,38 +667,38 @@ Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`
| title | No | string | The title of the entry | N/A |
| notification_services | No | list of numbers | Array of the id's of the notification services to use to send the notification | N/A |
| text | No | string | The body of the entry | N/A |
| color | No | string | The hex code of the color of the entry, which is shown in the web-ui | N/A |
| color | No | string | The hex code of the color of the entry, which is shown in the web-UI | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
| 400 | InvalidKeyValue | The value of a key is invalid |
| 404 | NotificationServiceNotFound | The notification service was not found |
| 404 | ReminderNotFound | The reminder with the id can not be found |
| 404 | ReminderNotFound | The reminder was not found |
??? DELETE
Delete the static reminder
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
| 404 | ReminderNotFound | The reminder with the id can not be found |
| 404 | ReminderNotFound | The reminder was not found |
### `/admin/shutdown`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Shut down the application |
| Yes | Shut down the application |
??? POST
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
@@ -690,12 +707,12 @@ Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Restart the application |
| Yes | Restart the application |
??? POST
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
@@ -704,12 +721,26 @@ Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| No | Get the admin settings |
| No | Get the admin settings |
??? GET
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
### `/about`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| No | Get data about the application and it's environment |
??? GET
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -718,14 +749,14 @@ Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Interact with the admin settings |
| Yes | |
??? GET
Get the admin settings
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -738,16 +769,16 @@ Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`
| Name | Required | Data type | Description | Allowed values |
| ---- | -------- | --------- | ----------- | -------------- |
| allow_new_accounts | No | bool | Whether or not to allow users to register a new account. The admin can always add a new account. | N/A |
| login_time | No | number | How long a user stays logged in, in seconds. Between 1 min and 1 month (60 <= sec <= 2592000) | N/A |
| login_time_reset | No | bool | If the Login Time timer should reset with each API request. | N/A |
| host | No | string | The IP to bind to. Use 0.0.0.0 to bind to all addresses. | N/A |
| port | No | number | The port to listen on. | N/A |
| url_prefix | No | string | The base url to run on. Useful for reverse proxies. Empty string to disable. | N/A |
| log_level | No | number | The level to log on. | `20`, `10` |
| allow_new_accounts | No | bool | Whether to allow users to register a new account. The admin can always add a new account. | N/A |
| login_time | No | number | How long a user stays logged in, in seconds. Between 1 minute and 1 month (60 <= sec <= 2592000). | N/A |
| login_time_reset | No | bool | Whether the Login Time timer should reset with each API request | N/A |
| host | No | string | The IP to bind to. Use 0.0.0.0 to bind to all addresses | N/A |
| port | No | number | The port to listen on | N/A |
| url_prefix | No | string | The base URL to run on. Useful for reverse proxies. Empty string to disable. | N/A |
| log_level | No | number | The level to log on | 20, 10 |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -757,12 +788,12 @@ Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Get the debug logs |
| Yes | Get the logfile |
??? GET
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -771,21 +802,21 @@ Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Get all users or add one |
| Yes | Manage the users |
??? GET
Get all users
Get a list of all users
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
??? POST
Add a new user
Add a user
**Parameters (body)**
@@ -795,12 +826,12 @@ Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`
| password | Yes | string | The password of the user account | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |
| 400 | KeyNotFound | A key was not found in the input that is required to be given |
| 400 | UsernameInvalid | The username contains invalid characters |
| 400 | UsernameInvalid | The username contains invalid characters or is not allowed |
| 400 | UsernameTaken | The username is already taken |
| 403 | NewAccountsNotAllowed | It's not allowed to create a new account except for the admin |
@@ -808,7 +839,7 @@ Replace `<int:s_id>` with the ID of the entry. For example: `/staticreminders/2`
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Manage a specific user |
| Yes | Manage a specific user |
Replace `<int:u_id>` with the ID of the entry. For example: `/admin/users/2`.
@@ -823,7 +854,7 @@ Replace `<int:u_id>` with the ID of the entry. For example: `/admin/users/2`.
| new_password | Yes | string | The new password of the user account | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -834,7 +865,7 @@ Replace `<int:u_id>` with the ID of the entry. For example: `/admin/users/2`.
Delete the user account
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -843,14 +874,14 @@ Replace `<int:u_id>` with the ID of the entry. For example: `/admin/users/2`.
| Requires being logged in | Description |
| ------------------------ | ----------- |
| Yes | Download the database |
| Yes | Download and upload the database |
??? GET
Download the database file
Download the database
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 200 | N/A | Success |
@@ -872,7 +903,7 @@ Replace `<int:u_id>` with the ID of the entry. For example: `/admin/users/2`.
| file | Yes | N/A | The MIND database file | N/A |
**Returns**
| Code | Error | Description |
| ---- | ----- | ----------- |
| 201 | N/A | Success |