@@ -21,6 +21,8 @@ func CloudRouter(bot *tgbotapi.BotAPI) *gin.Engine {
2121 router .GET ("/health" , health )
2222 router .GET ("/whoami" , Auth (), whoami )
2323
24+ router .POST ("/heartbeat" , Auth (), sentryHeartbeatHandler )
25+
2426 // Knocks
2527 // router.POST("/welcome/:invite_code", welcome)
2628 // router.POST("/trustedknock", Auth(), trustedKnock)
@@ -51,6 +53,35 @@ func whoami(c *gin.Context) {
5153 c .String (http .StatusOK , authenticatedUser )
5254}
5355
56+ func sentryHeartbeatHandler (c * gin.Context ) {
57+ // Protected by 'TrustedHmacAuthentication' middleware
58+ authenticatedUser := c .MustGet ("authenticatedUser" ).(string )
59+
60+ // Set no cache headers
61+ c .Header ("Cache-Control" , "no-cache, no-store, no-transform, must-revalidate, private, max-age=0" )
62+ c .Header ("Pragma" , "no-cache" )
63+ c .Header ("Expires" , "0" )
64+ c .Header ("X-Accel-Expires" , "0" )
65+
66+ // Parse JSON
67+ var heartbeat Heartbeat
68+ if err := c .ShouldBindJSON (& heartbeat ); err != nil {
69+ c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {"error" : err .Error ()})
70+ return
71+ }
72+
73+ // TEMP: Send to Telegram
74+ bot := c .MustGet (BOT_CONTEXT ).(* BotExtended )
75+ bot .SendMessageToPrimaryTelegramGroup (fmt .Sprintf ("Heartbeat from '%s' on '%s' at %d" , authenticatedUser , heartbeat .HostName , heartbeat .Timestamp ))
76+
77+ // Accept if we have not aborted.
78+ if ! c .IsAborted () {
79+ var response HeartbeatResponse
80+ response .accepted = true
81+ c .JSON (http .StatusAccepted , response )
82+ }
83+ }
84+
5485func trustedKnock (c * gin.Context ) {
5586 // Protected by 'TrustedHmacAuthentication' middleware
5687 authenticatedUser := c .MustGet ("authenticatedUser" ).(string )
0 commit comments