Skip to content

Commit

Permalink
feat: add test notification endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Apr 3, 2024
1 parent 2ec8d17 commit b12deec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions echo/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/flanksource/incident-commander/catalog"
"github.com/flanksource/incident-commander/db"
"github.com/flanksource/incident-commander/logs"
"github.com/flanksource/incident-commander/notification"
"github.com/flanksource/incident-commander/playbook"
"github.com/flanksource/incident-commander/rbac"
"github.com/flanksource/incident-commander/snapshot"
Expand Down Expand Up @@ -89,6 +90,7 @@ func New(ctx context.Context) *echov4.Echo {
artifacts.RegisterRoutes(e, "artifacts")

playbook.RegisterRoutes(e)
notification.RegisterRoutes(e)

e.POST("/agent/generate", agent.GenerateAgent, rbac.Authorization(rbac.ObjectAgentCreate, rbac.ActionWrite))
e.POST("/logs", logs.LogsHandler)
Expand Down
41 changes: 41 additions & 0 deletions notification/controllers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package notification

import (
"net/http"
"time"

dutyAPI "github.com/flanksource/duty/api"
"github.com/flanksource/duty/context"
"github.com/flanksource/postq"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
)

func RegisterRoutes(e *echo.Echo) {
apiGroup := e.Group("/notifications")
apiGroup.POST("/test", TestNotification)
}

func TestNotification(c echo.Context) error {
ctx := c.Request().Context().(context.Context)

var reqData struct {
ID uuid.UUID `json:"id"`
EventName string `json:"eventName"`
}
if err := c.Bind(&reqData); err != nil {
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINVALID, "invalid request: %v", err))
}

e := postq.Event{
Name: reqData.EventName,
Properties: map[string]string{"id": reqData.ID.String()},
CreatedAt: time.Now(),
}

if err := addNotificationEvent(ctx, e); err != nil {
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "unable to create notification event: %v", err))
}

return c.JSON(http.StatusOK, dutyAPI.HTTPSuccess{Message: "success"})
}

0 comments on commit b12deec

Please sign in to comment.