forked from GithubBackups/healthchecks
API call for deleting checks.
This commit is contained in:
parent
acbc1f0b23
commit
23b237ed96
23
hc/api/tests/test_delete_check.py
Normal file
23
hc/api/tests/test_delete_check.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from hc.api.models import Check
|
||||||
|
from hc.test import BaseTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteCheckTestCase(BaseTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(DeleteCheckTestCase, self).setUp()
|
||||||
|
self.check = Check(user=self.alice)
|
||||||
|
self.check.save()
|
||||||
|
|
||||||
|
def test_it_works(self):
|
||||||
|
r = self.client.delete("/api/v1/checks/%s" % self.check.code,
|
||||||
|
HTTP_X_API_KEY="abc")
|
||||||
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
|
# It should be gone--
|
||||||
|
self.assertFalse(Check.objects.filter(code=self.check.code).exists())
|
||||||
|
|
||||||
|
def test_it_handles_missing_check(self):
|
||||||
|
url = "/api/v1/checks/07c2f548-9850-4b27-af5d-6c9dc157ec02"
|
||||||
|
r = self.client.delete(url, HTTP_X_API_KEY="abc")
|
||||||
|
self.assertEqual(r.status_code, 404)
|
@ -139,7 +139,6 @@ def checks(request):
|
|||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@require_POST
|
|
||||||
@uuid_or_400
|
@uuid_or_400
|
||||||
@check_api_key
|
@check_api_key
|
||||||
@validate_json(schemas.check)
|
@validate_json(schemas.check)
|
||||||
@ -148,8 +147,17 @@ def update(request, code):
|
|||||||
if check.user != request.user:
|
if check.user != request.user:
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
_update(check, request.json)
|
if request.method == "POST":
|
||||||
return JsonResponse(check.to_dict())
|
_update(check, request.json)
|
||||||
|
return JsonResponse(check.to_dict())
|
||||||
|
|
||||||
|
elif request.method == "DELETE":
|
||||||
|
response = check.to_dict()
|
||||||
|
check.delete()
|
||||||
|
return JsonResponse(response)
|
||||||
|
|
||||||
|
# Otherwise, method not allowed
|
||||||
|
return HttpResponse(status=405)
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -48,3 +48,4 @@ class Command(BaseCommand):
|
|||||||
_process("create_check_response", lexers.JsonLexer())
|
_process("create_check_response", lexers.JsonLexer())
|
||||||
_process("pause_check_request", lexers.BashLexer())
|
_process("pause_check_request", lexers.BashLexer())
|
||||||
_process("pause_check_response", lexers.JsonLexer())
|
_process("pause_check_response", lexers.JsonLexer())
|
||||||
|
_process("delete_check_request", lexers.BashLexer())
|
||||||
|
@ -27,8 +27,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
h2.rule {
|
h2.rule {
|
||||||
border-top: 1px solid #ddd;
|
border-top: 3px solid #eee;
|
||||||
padding-top: 20px;
|
margin-top: 30px;
|
||||||
|
padding-top: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h3.api-section {
|
h3.api-section {
|
||||||
@ -41,6 +42,11 @@ h3.api-section {
|
|||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
|
background: #f5f5f5;
|
||||||
|
color: #333;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 2px 4px;
|
||||||
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
a.section {
|
a.section {
|
||||||
|
@ -6,18 +6,46 @@
|
|||||||
{% block docs_content %}
|
{% block docs_content %}
|
||||||
|
|
||||||
<h2>REST API</h2>
|
<h2>REST API</h2>
|
||||||
<p>
|
<p>{% site_name %} REST API supports listing, creating,
|
||||||
This is early days for healtchecks.io REST API. For now, there's API calls to:
|
updating, pausing and deleting checks in user's account.
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
|
||||||
<li><a href="#list-checks">List existing checks</a></li>
|
|
||||||
<li><a href="#create-check">Create a new check</a></li>
|
|
||||||
<li><a href="#update-check">Update an existing check</a></li>
|
|
||||||
<li><a href="#pause-check">Pause monitoring of a check</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h2 class="rule">Authentication</h2>
|
<h2>API Endpoints</h2>
|
||||||
<p>Your requests to healtchecks.io REST API must authenticate using an
|
<table class="table table-bordered">
|
||||||
|
<tr>
|
||||||
|
<td><a href="#list-checks">Get list of existing checks</a></td>
|
||||||
|
<td>
|
||||||
|
<code>GET {{ SITE_ROOT }}/api/v1/checks/</code>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><a href="#create-check">Create a new check</a></td>
|
||||||
|
<td>
|
||||||
|
<code>POST {{ SITE_ROOT }}/api/v1/checks/</code>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><a href="#update-check">Update an existing check</a></td>
|
||||||
|
<td>
|
||||||
|
<code>POST {{ SITE_ROOT }}/api/v1/checks/<code></code>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><a href="#pause-check">Pause monitoring of a check</a></td>
|
||||||
|
<td>
|
||||||
|
<code>POST {{ SITE_ROOT }}/api/v1/checks/<code>/pause</code>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><a href="#delete-check">Delete check</a></td>
|
||||||
|
<td>
|
||||||
|
<code>DELETE {{ SITE_ROOT }}/api/v1/checks/<code></code>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>Authentication</h2>
|
||||||
|
<p>Your requests to {% site_name %} REST API must authenticate using an
|
||||||
API key. By default, an user account on {% site_name %} doesn't have
|
API key. By default, an user account on {% site_name %} doesn't have
|
||||||
an API key. You can create one in the <a href="{% url 'hc-profile' %}">Settings</a> page.
|
an API key. You can create one in the <a href="{% url 'hc-profile' %}">Settings</a> page.
|
||||||
</p>
|
</p>
|
||||||
@ -55,7 +83,7 @@ The response may contain a JSON document with additional data.
|
|||||||
<!-- ********************************************************************** /-->
|
<!-- ********************************************************************** /-->
|
||||||
|
|
||||||
<a class="section" name="list-checks">
|
<a class="section" name="list-checks">
|
||||||
<h2 class="rule">List checks</h2>
|
<h2 class="rule">Get List of Existing Checks</h2>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="api-path">GET {{ SITE_ROOT }}/api/v1/checks/</div>
|
<div class="api-path">GET {{ SITE_ROOT }}/api/v1/checks/</div>
|
||||||
@ -90,7 +118,7 @@ one or more tags.</p>
|
|||||||
<!-- ********************************************************************** /-->
|
<!-- ********************************************************************** /-->
|
||||||
|
|
||||||
<a class="section" name="create-check">
|
<a class="section" name="create-check">
|
||||||
<h2 class="rule">Create a check</h2>
|
<h2 class="rule">Create a Check</h2>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/</div>
|
<div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/</div>
|
||||||
@ -228,7 +256,7 @@ To create a "cron" check, specify the "schedule" and "tz" parameters.
|
|||||||
<!-- ********************************************************************** /-->
|
<!-- ********************************************************************** /-->
|
||||||
|
|
||||||
<a class="section" name="update-check">
|
<a class="section" name="update-check">
|
||||||
<h2 class="rule">Update an existing check</h2>
|
<h2 class="rule">Update an Existing Check</h2>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/<code></div>
|
<div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/<code></div>
|
||||||
@ -338,8 +366,6 @@ To create a "cron" check, specify the "schedule" and "tz" parameters.
|
|||||||
|
|
||||||
<div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/<uuid>/pause</div>
|
<div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/<uuid>/pause</div>
|
||||||
|
|
||||||
<strong></strong>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Disables monitoring for a check, without removing it. The check goes
|
Disables monitoring for a check, without removing it. The check goes
|
||||||
into a "paused" state. You can resume monitoring of the check by pinging
|
into a "paused" state. You can resume monitoring of the check by pinging
|
||||||
@ -362,6 +388,28 @@ is sometimes required by some network proxies and web servers.
|
|||||||
<h3 class="api-section">Example Response</h3>
|
<h3 class="api-section">Example Response</h3>
|
||||||
{% include "front/snippets/pause_check_response.html" %}
|
{% include "front/snippets/pause_check_response.html" %}
|
||||||
|
|
||||||
|
<!-- ********************************************************************** /-->
|
||||||
|
|
||||||
|
<a class="section" name="delete-check">
|
||||||
|
<h2 class="rule">Delete Check</h2>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="api-path">DELETE {{ SITE_ROOT }}/api/v1/checks/<uuid></div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Permanently deletes the check from user's account. Returns JSON
|
||||||
|
representation of the check that was just deleted.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
This API call has no request parameters.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3 class="api-section">Example Request</h3>
|
||||||
|
|
||||||
|
{% include "front/snippets/delete_check_request.html" %}
|
||||||
|
|
||||||
|
<h3 class="api-section">Example Response</h3>
|
||||||
|
{% include "front/snippets/create_check_response.html" %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
3
templates/front/snippets/delete_check_request.html
Normal file
3
templates/front/snippets/delete_check_request.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<div class="highlight"><pre><span></span>curl {{ SITE_ROOT }}/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc <span class="se">\</span>
|
||||||
|
--request DELETE --header <span class="s2">"X-Api-Key: your-api-key"</span>
|
||||||
|
</pre></div>
|
2
templates/front/snippets/delete_check_request.txt
Normal file
2
templates/front/snippets/delete_check_request.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc \
|
||||||
|
--request DELETE --header "X-Api-Key: your-api-key"
|
Loading…
x
Reference in New Issue
Block a user