fix: generate pushToken on push monitor save
https://github.com/lucasheld/ansible-uptime-kuma/issues/5
This commit is contained in:
parent
9b0f0c1e7f
commit
12cd8067e4
2 changed files with 15 additions and 1 deletions
|
@ -62,6 +62,7 @@ class TestMonitor(UptimeKumaTestCase):
|
|||
|
||||
monitor = self.api.get_monitor(monitor_id)
|
||||
self.compare(monitor, expected_monitor)
|
||||
return monitor
|
||||
|
||||
def test_monitor_type_http(self):
|
||||
json_data = '{"key": "value"}'
|
||||
|
@ -115,7 +116,10 @@ class TestMonitor(UptimeKumaTestCase):
|
|||
"type": MonitorType.PUSH,
|
||||
"name": "monitor 1"
|
||||
}
|
||||
self.do_test_monitor_type(expected_monitor)
|
||||
monitor = self.do_test_monitor_type(expected_monitor)
|
||||
|
||||
# https://github.com/lucasheld/ansible-uptime-kuma/issues/5
|
||||
self.assertIsNotNone(monitor["pushToken"])
|
||||
|
||||
def test_monitor_type_steam(self):
|
||||
expected_monitor = {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import json
|
||||
import time
|
||||
import string
|
||||
import random
|
||||
|
||||
import requests
|
||||
import socketio
|
||||
|
@ -25,6 +27,11 @@ def int_to_bool(data, keys):
|
|||
data[key] = True if data[key] == 1 else False
|
||||
|
||||
|
||||
def gen_secret(length: int) -> str:
|
||||
chars = string.ascii_uppercase + string.ascii_lowercase + string.digits
|
||||
return ''.join(random.choice(chars) for _ in range(length))
|
||||
|
||||
|
||||
def _convert_monitor_data(kwargs):
|
||||
if not kwargs["accepted_statuscodes"]:
|
||||
kwargs["accepted_statuscodes"] = ["200-299"]
|
||||
|
@ -40,6 +47,9 @@ def _convert_monitor_data(kwargs):
|
|||
kwargs["databaseConnectionString"] = "Server=<hostname>,<port>;Database=<your database>;User Id=<your user id>;Password=<your password>;Encrypt=<true/false>;TrustServerCertificate=<Yes/No>;Connection Timeout=<int>"
|
||||
elif kwargs["type"] == MonitorType.POSTGRES:
|
||||
kwargs["databaseConnectionString"] = "postgres://username:password@host:port/database"
|
||||
|
||||
if kwargs["type"] == MonitorType.PUSH and not kwargs.get("pushToken"):
|
||||
kwargs["pushToken"] = gen_secret(10)
|
||||
return kwargs
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue