forked from GithubBackups/healthchecks
adds a unique parameter to the check creation API
It only checks for name uniqueness.
This commit is contained in:
parent
252fa1f884
commit
bcde5fe9d2
@ -55,8 +55,20 @@ def checks(request):
|
||||
return JsonResponse(doc)
|
||||
|
||||
elif request.method == "POST":
|
||||
|
||||
unique = bool(request.json.get("unique", False))
|
||||
name = str(request.json.get("name", ""))
|
||||
|
||||
if unique:
|
||||
existing_checks = Check.objects.filter(user=request.user, name=name)
|
||||
|
||||
if existing_checks.count() > 0:
|
||||
# There might be more than one check with the same name since name
|
||||
# uniqueness isn't enforced in the model
|
||||
return JsonResponse(existing_checks.first().to_dict(), status=200)
|
||||
|
||||
check = Check(user=request.user)
|
||||
check.name = str(request.json.get("name", ""))
|
||||
check.name = name
|
||||
check.tags = str(request.json.get("tags", ""))
|
||||
if "timeout" in request.json:
|
||||
check.timeout = td(seconds=request.json["timeout"])
|
||||
|
@ -127,6 +127,14 @@ The response may contain a JSON document with additional data.
|
||||
to automatically assign all existing notification channels.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>unique</th>
|
||||
<td>
|
||||
<p>bool, optional, default value: False.</p>
|
||||
<p>When true a check won't be created if there exists a check with the
|
||||
same name. If any existing checks match then the first one will be returned.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3 class="api-section">Example Request</h3>
|
||||
|
Loading…
x
Reference in New Issue
Block a user