1
0
mirror of synced 2024-11-25 13:16:02 +03:00

Merge pull request #49 from DmitryZagorulko/master

add tags in sentry
This commit is contained in:
Alex Lushpai 2018-10-24 17:15:23 +03:00 committed by GitHub
commit cfdc6015a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 24 deletions

View File

@ -67,6 +67,30 @@ func ErrorCaptureHandler(client *raven.Client, errorsStacktrace bool) ErrorHandl
"endpoint": c.Request.RequestURI,
}
var (
ok bool
conn Connection
)
connection, ok := c.Get("connection")
if ok {
conn = connection.(Connection)
}
b, ok := c.Get("bot")
if ok {
tags["bot"] = b.(Bot).Token
conn = *getConnectionById(b.(Bot).ConnectionID)
}
if conn.APIURL != "" {
tags["crm"] = conn.APIURL
}
if conn.ClientID != "" {
tags["clientID"] = conn.ClientID
}
if recovery != nil {
stacktrace := raven.NewStacktrace(4, 3, nil)
recStr := fmt.Sprint(recovery)

View File

@ -406,17 +406,7 @@ func updateBots(conn *Connection, hashSettings string) {
}
func telegramWebhookHandler(c *gin.Context) {
token := c.Param("token")
b, err := getBotByToken(token)
if err != nil {
c.Error(err)
return
}
if b.ID == 0 {
c.AbortWithStatus(http.StatusOK)
return
}
b := c.MustGet("bot").(Bot)
conn := getConnectionById(b.ConnectionID)
if !conn.Active {
@ -559,17 +549,7 @@ func telegramWebhookHandler(c *gin.Context) {
}
func mgWebhookHandler(c *gin.Context) {
clientID := c.GetHeader("Clientid")
if clientID == "" {
c.AbortWithStatus(http.StatusBadRequest)
return
}
conn := getConnection(clientID)
if !conn.Active {
c.AbortWithStatus(http.StatusBadRequest)
return
}
conn := c.MustGet("connection").(Connection)
var msg v1.WebhookRequest
if err := c.ShouldBindJSON(&msg); err != nil {

View File

@ -1,6 +1,7 @@
package main
import (
"net/http"
"os"
"os/signal"
"syscall"
@ -92,8 +93,8 @@ func setup() *gin.Engine {
r.POST("/delete-bot/", checkBotForRequest(), deleteBotHandler)
r.POST("/set-lang/", checkBotForRequest(), setLangBotHandler)
r.POST("/actions/activity", activityHandler)
r.POST("/telegram/:token", telegramWebhookHandler)
r.POST("/webhook/", mgWebhookHandler)
r.POST("/telegram/:token", checkBotForWebhook(), telegramWebhookHandler)
r.POST("/webhook/", checkConnectionForWebhook(), mgWebhookHandler)
return r
}
@ -147,3 +148,40 @@ func checkConnectionForRequest() gin.HandlerFunc {
c.Set("connection", conn)
}
}
func checkConnectionForWebhook() gin.HandlerFunc {
return func(c *gin.Context) {
clientID := c.GetHeader("Clientid")
if clientID == "" {
c.AbortWithStatus(http.StatusBadRequest)
return
}
conn := getConnection(clientID)
if !conn.Active {
c.AbortWithStatus(http.StatusBadRequest)
return
}
c.Set("connection", *conn)
}
}
func checkBotForWebhook() gin.HandlerFunc {
return func(c *gin.Context) {
token := c.Param("token")
b, err := getBotByToken(token)
if err != nil {
c.Error(err)
return
}
if b.ID == 0 {
c.AbortWithStatus(http.StatusOK)
return
}
c.Set("bot", *b)
}
}