From 67642b130c9d5a543331f480fc660064948ed411 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Thu, 2 Sep 2021 23:03:12 -0400 Subject: [PATCH] Remove deprecated endpoints --- controller/badge.go | 8 +------- controller/controller.go | 4 ---- controller/controller_test.go | 10 +++++----- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/controller/badge.go b/controller/badge.go index f21860fa..e2e91e55 100644 --- a/controller/badge.go +++ b/controller/badge.go @@ -40,13 +40,7 @@ func uptimeBadgeHandler(writer http.ResponseWriter, request *http.Request) { _, _ = writer.Write([]byte("Durations supported: 7d, 24h, 1h")) return } - var key string - if identifier := variables["identifier"]; len(identifier) > 0 { - // XXX: Remove this conditional statement in v3.0.0 and rely on variables["key"] instead - key = strings.TrimSuffix(identifier, ".svg") - } else { - key = variables["key"] - } + key := variables["key"] uptime, err := storage.Get().GetUptimeByKey(key, from, time.Now()) if err != nil { if err == common.ErrServiceNotFound { diff --git a/controller/controller.go b/controller/controller.go index fb735d12..d9c88dfb 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -75,10 +75,6 @@ func CreateRouter(securityConfig *security.Config, enabledMetrics bool) *mux.Rou } router.Handle("/health", health.Handler().WithJSON(true)).Methods("GET") router.HandleFunc("/favicon.ico", favIconHandler).Methods("GET") - // Deprecated endpoints - router.HandleFunc("/api/v1/statuses", secureIfNecessary(securityConfig, serviceStatusesHandler)).Methods("GET") // No GzipHandler for this one, because we cache the content as Gzipped already - router.HandleFunc("/api/v1/statuses/{key}", secureIfNecessary(securityConfig, GzipHandlerFunc(serviceStatusHandler))).Methods("GET") - router.HandleFunc("/api/v1/badges/uptime/{duration}/{identifier}", uptimeBadgeHandler).Methods("GET") // New endpoints router.HandleFunc("/api/v1/services/statuses", secureIfNecessary(securityConfig, serviceStatusesHandler)).Methods("GET") // No GzipHandler for this one, because we cache the content as Gzipped already router.HandleFunc("/api/v1/services/{key}/statuses", secureIfNecessary(securityConfig, GzipHandlerFunc(serviceStatusHandler))).Methods("GET") diff --git a/controller/controller_test.go b/controller/controller_test.go index d18a871f..42b0d9ed 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -390,31 +390,31 @@ func TestServiceStatusesHandler(t *testing.T) { Name: "no-pagination", Path: "/api/v1/services/statuses", ExpectedCode: http.StatusOK, - ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"},{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}]}]`, + ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"},{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}],"events":[]}]`, }, { Name: "pagination-first-result", Path: "/api/v1/services/statuses?page=1&pageSize=1", ExpectedCode: http.StatusOK, - ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}]}]`, + ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}],"events":[]}]`, }, { Name: "pagination-second-result", Path: "/api/v1/services/statuses?page=2&pageSize=1", ExpectedCode: http.StatusOK, - ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"}]}]`, + ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"}],"events":[]}]`, }, { Name: "pagination-no-results", Path: "/api/v1/services/statuses?page=5&pageSize=20", ExpectedCode: http.StatusOK, - ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[]}]`, + ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[],"events":[]}]`, }, { Name: "invalid-pagination-should-fall-back-to-default", Path: "/api/v1/services/statuses?page=INVALID&pageSize=INVALID", ExpectedCode: http.StatusOK, - ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"},{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}]}]`, + ExpectedBody: `[{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"},{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}],"events":[]}]`, }, }