From 77fd0d00e0462c49e6d9044b0db844481ad6e380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 4 Jul 2019 19:33:26 +0300 Subject: [PATCH] Add "desc" back in the readonly API responses, and add "unique_key" field, derived from code. --- hc/api/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hc/api/models.py b/hc/api/models.py index 62b80f2d..ca92fdd8 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -178,6 +178,7 @@ class Check(models.Model): result = { "name": self.name, "tags": self.tags, + "desc": self.desc, "grace": int(self.grace.total_seconds()), "n_pings": self.n_pings, "status": self.get_status(), @@ -185,7 +186,10 @@ class Check(models.Model): "next_ping": isostring(self.get_grace_start()), } - if not readonly: + if readonly: + code_half = self.code.hex[:16] + result["unique_key"] = hashlib.sha1(code_half.encode()).hexdigest() + else: update_rel_url = reverse("hc-api-update", args=[self.code]) pause_rel_url = reverse("hc-api-pause", args=[self.code]) @@ -193,7 +197,6 @@ class Check(models.Model): result["update_url"] = settings.SITE_ROOT + update_rel_url result["pause_url"] = settings.SITE_ROOT + pause_rel_url result["channels"] = self.channels_str() - result["desc"] = self.desc if self.kind == "simple": result["timeout"] = int(self.timeout.total_seconds())