Skip to content

Open-source status page, incident response and uptime monitoring

🔑 bypass unkey (#635)

Thibault Le Ouay3e5450510aba
diff --git a/apps/checker/cmd/main.go b/apps/checker/cmd/main.go
index 306d02cb3..3e3ea12c8 100644
--- a/apps/checker/cmd/main.go
+++ b/apps/checker/cmd/main.go
@@ -101,11 +101,11 @@ func main() {
if !statusCode.IsSuccessful() && req.Status == "active" {
// Q: Why here we do not check if the status was previously active?
checker.UpdateStatus(ctx, checker.UpdateData{
- MonitorId: req.MonitorID,
- Status: "error",
- StatusCode: res.StatusCode,
- Region: flyRegion,
- Message: res.Message,
+ MonitorId: req.MonitorID,
+ Status: "error",
+ StatusCode: res.StatusCode,
+ Region: flyRegion,
+ Message: res.Message,
CronTimestamp: req.CronTimestamp,
})
}
@@ -113,12 +113,11 @@ func main() {
if req.Status == "error" && statusCode.IsSuccessful() {
// Q: Why here we check the data before updating the status in this scenario?
checker.UpdateStatus(ctx, checker.UpdateData{
- MonitorId: req.MonitorID,
- Status: "active",
- Region: flyRegion,
- StatusCode: res.StatusCode,
+ MonitorId: req.MonitorID,
+ Status: "active",
+ Region: flyRegion,
+ StatusCode: res.StatusCode,
CronTimestamp: req.CronTimestamp,
-
})
}
if err := tinybirdClient.SendEvent(ctx, res); err != nil {
@@ -143,10 +142,10 @@ func main() {
if req.Status == "active" {
checker.UpdateStatus(ctx, checker.UpdateData{
- MonitorId: req.MonitorID,
- Status: "error",
- Message: err.Error(),
- Region: flyRegion,
+ MonitorId: req.MonitorID,
+ Status: "error",
+ Message: err.Error(),
+ Region: flyRegion,
CronTimestamp: req.CronTimestamp,
})
}
@@ -170,19 +169,23 @@ func main() {
fmt.Printf("Start of /ping/%s\n", region)
apiKey := c.GetHeader("x-openstatus-key")
- if apiKey == "" {
- c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
- return
- }
- response, err := unkey.KeyVerify(apiKey)
- if err != nil {
+ if c.GetHeader("Authorization") != fmt.Sprintf("Basic %s", cronSecret) && apiKey == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
return
}
+ if apiKey != "" {
+ response, err := unkey.KeyVerify(apiKey)
+ if err != nil {
+ c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
+ return
+ }
- if !response.Valid {
- fmt.Println("Key is valid")
+ if !response.Valid {
+ fmt.Println("Key is not valid valid")
+ c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
+
+ }
}
if region != flyRegion {