From da4cf5241ee060efba4236b52fb6a4099adfbd44 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C4=93teris=20Caune?=
Date: Mon, 23 Mar 2020 11:54:41 +0200
Subject: [PATCH] Minor cleanup, update CHANGELOG
---
CHANGELOG.md | 1 +
hc/api/tests/test_get_check.py | 3 +--
hc/api/views.py | 10 +---------
templates/docs/api.html | 10 +++++++---
templates/docs/api.md | 13 ++++++++++---
templates/docs/cloning_checks.html | 2 +-
6 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aa4fb5ea..2cd8edc6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- Zulip integration (#202)
- OpsGenie integration returns more detailed error messages
- Telegram integration returns more detailed error messages
+- Added the "Get a single check" API call (#337)
### Bug Fixes
- The "render_docs" command checks if markdown and pygments is installed (#329)
diff --git a/hc/api/tests/test_get_check.py b/hc/api/tests/test_get_check.py
index 3b0c30a8..b3f916ec 100644
--- a/hc/api/tests/test_get_check.py
+++ b/hc/api/tests/test_get_check.py
@@ -1,5 +1,4 @@
from datetime import timedelta as td
-import uuid
from django.utils.timezone import now
from hc.api.models import Channel, Check
@@ -52,4 +51,4 @@ class GetCheckTestCase(BaseTestCase):
def test_it_handles_missing_check(self):
made_up_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
r = self.get(made_up_code)
- self.assertEqual(r.status_code, 404)
\ No newline at end of file
+ self.assertEqual(r.status_code, 404)
diff --git a/hc/api/views.py b/hc/api/views.py
index a8ec08f1..f0225702 100644
--- a/hc/api/views.py
+++ b/hc/api/views.py
@@ -191,7 +191,7 @@ def single(request, code):
try:
validate(request.json, schemas.check)
_update(check, request.json)
- except (BadChannelException,ValidationError) as e:
+ except (BadChannelException, ValidationError) as e:
return JsonResponse({"error": str(e)}, status=400)
return JsonResponse(check.to_dict())
@@ -208,14 +208,6 @@ def single(request, code):
return HttpResponse(status=405)
-@csrf_exempt
-@cors("POST", "DELETE")
-@validate_json(schemas.check)
-@authorize
-def update(request, code):
- single(request, code)
-
-
@cors("POST")
@csrf_exempt
@validate_json()
diff --git a/templates/docs/api.html b/templates/docs/api.html
index c896f2f3..1ce17fe5 100644
--- a/templates/docs/api.html
+++ b/templates/docs/api.html
@@ -15,7 +15,7 @@ checks in user's account.
GET SITE_ROOT/api/v1/checks/ |
-Create a single check |
+Get a single check |
GET SITE_ROOT/api/v1/checks/<uuid> |
@@ -178,15 +178,19 @@ is added. This identifier is stable across API calls. Example:
-Get a single Check
+Get a Single Check
GET SITE_ROOT/api/v1/checks/<uuid>
-Returns a JSON object containing information information from a single check.
+Returns a JSON representation of a single check.
Response Codes
- 200 OK
- The request succeeded.
- 401 Unauthorized
- The API key is either missing or invalid.
+- 403 Forbidden
+- Access denied, wrong API key.
+- 404 Not Found
+- The specified check does not exist.
Example Request
curl --header "X-Api-Key: your-api-key" SITE_ROOT/api/v1/checks/<uuid>
diff --git a/templates/docs/api.md b/templates/docs/api.md
index d04bac9e..8c3a1e47 100644
--- a/templates/docs/api.md
+++ b/templates/docs/api.md
@@ -8,7 +8,7 @@ checks in user's account.
Endpoint Name | Endpoint Address
------------------------------------------------------|-------
[Get a list of existing checks](#list-checks) | `GET SITE_ROOT/api/v1/checks/`
-[Create a single check](#get-check) | `GET SITE_ROOT/api/v1/checks/`
+[Get a single check](#get-check) | `GET SITE_ROOT/api/v1/checks/`
[Create a new check](#create-check) | `POST SITE_ROOT/api/v1/checks/`
[Update an existing check](#update-check) | `POST SITE_ROOT/api/v1/checks/`
[Pause monitoring of a check](#pause-check) | `POST SITE_ROOT/api/v1/checks//pause`
@@ -158,10 +158,10 @@ is added. This identifier is stable across API calls. Example:
}
```
-## Get a single Check {: #get-check .rule }
+## Get a Single Check {: #get-check .rule }
`GET SITE_ROOT/api/v1/checks/`
-Returns a JSON object containing information information from a single check.
+Returns a JSON representation of a single check.
### Response Codes
@@ -171,6 +171,13 @@ Returns a JSON object containing information information from a single check.
401 Unauthorized
: The API key is either missing or invalid.
+403 Forbidden
+: Access denied, wrong API key.
+
+404 Not Found
+: The specified check does not exist.
+
+
### Example Request
```bash
diff --git a/templates/docs/cloning_checks.html b/templates/docs/cloning_checks.html
index d972fe6b..8206e999 100644
--- a/templates/docs/cloning_checks.html
+++ b/templates/docs/cloning_checks.html
@@ -1,5 +1,5 @@
Cloning Checks
-You can individually clone individual checks SITE_NAME from the "Check Details"
+
You can clone individual checks from the "Check Details"
page:
The "Create a Copy..." function creates a new check in the same project, and copies