func HandleGetEventingSecurityRules(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		projectID := vars["project"]
		id := "*"
		typ, exists := r.URL.Query()["id"]
		if exists {
			id = typ[0]
		}
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-rule", "read", map[string]string{"project": projectID, "id": id})
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, nil)
		status, securityRules, err := syncMan.GetEventingSecurityRules(ctx, projectID, id, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendResponse(ctx, w, status, model.Response{Result: securityRules})
	}
}
HandleGetEventingSecurityRules returns handler to get event security rules
package handlers
import (
	"context"
	"encoding/json"
	"net/http"
	"time"
	"github.com/gorilla/mux"
	"github.com/spaceuptech/helpers"
	"github.com/spaceuptech/space-cloud/gateway/config"
	"github.com/spaceuptech/space-cloud/gateway/managers/admin"
	"github.com/spaceuptech/space-cloud/gateway/managers/syncman"
	"github.com/spaceuptech/space-cloud/gateway/model"
	"github.com/spaceuptech/space-cloud/gateway/utils"
)
func HandleAddEventingTriggerRule(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		ruleName := vars["id"]
		projectID := vars["project"]
		value := config.EventingTrigger{}
		_ = json.NewDecoder(r.Body).Decode(&value)
		defer utils.CloseTheCloser(r.Body)
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-trigger", "modify", map[string]string{"project": projectID, "id": ruleName})
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, value)
		status, err := syncMan.SetEventingRule(ctx, projectID, ruleName, &value, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendOkayResponse(ctx, status, w)
	}
}
func HandleGetEventingTriggers(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		projectID := vars["project"]
		id := "*"
		ruleNameQuery, exists := r.URL.Query()["id"]
		if exists {
			id = ruleNameQuery[0]
		}
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-trigger", "read", map[string]string{"project": projectID, "id": id})
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, nil)
		status, rules, err := syncMan.GetEventingTriggerRules(ctx, projectID, id, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendResponse(ctx, w, status, model.Response{Result: rules})
	}
}
func HandleDeleteEventingTriggerRule(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		ruleName := vars["id"]
		projectID := vars["project"]
		defer utils.CloseTheCloser(r.Body)
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-trigger", "modify", map[string]string{"project": projectID, "id": ruleName})
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, nil)
		status, err := syncMan.SetDeleteEventingRule(ctx, projectID, ruleName, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendOkayResponse(ctx, status, w)
	}
}
func HandleSetEventingConfig(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		projectID := vars["project"]
		defer utils.CloseTheCloser(r.Body)
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-config", "modify", map[string]string{"project": projectID})
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		c := new(config.Eventing)
		_ = json.NewDecoder(r.Body).Decode(c)
		reqParams = utils.ExtractRequestParams(r, reqParams, c)
		status, err := syncMan.SetEventingConfig(ctx, projectID, c.DBAlias, c.Enabled, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendOkayResponse(ctx, status, w)
	}
}
func HandleGetEventingConfig(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		projectID := vars["project"]
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-config", "read", map[string]string{"project": projectID})
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, nil)
		status, e, err := syncMan.GetEventingConfig(ctx, projectID, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendResponse(ctx, w, status, model.Response{Result: []interface{}{e}})
	}
}
func HandleSetEventingSchema(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	type schemaRequest struct {
		Schema string `json:"schema"`
	}
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		projectID := vars["project"]
		evType := vars["id"]
		defer utils.CloseTheCloser(r.Body)
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-schema", "modify", map[string]string{"project": projectID, "id": evType})
		if err != nil {
			_ = helpers.Logger.LogError(helpers.GetRequestID(ctx), "Failed to validate token for set eventing schema", err, nil)
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		c := schemaRequest{}
		_ = json.NewDecoder(r.Body).Decode(&c)
		reqParams = utils.ExtractRequestParams(r, reqParams, c)
		status, err := syncMan.SetEventingSchema(ctx, projectID, evType, c.Schema, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendOkayResponse(ctx, status, w)
	}
}
func HandleGetEventingSchema(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		projectID := vars["project"]
		id := "*"
		typ, exists := r.URL.Query()["id"]
		if exists {
			id = typ[0]
		}
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-schema", "read", map[string]string{"project": projectID, "id": id})
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, nil)
		status, schemas, err := syncMan.GetEventingSchema(ctx, projectID, id, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendResponse(ctx, w, status, model.Response{Result: schemas})
	}
}
func HandleDeleteEventingSchema(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		projectID := vars["project"]
		evType := vars["id"]
		defer utils.CloseTheCloser(r.Body)
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-schema", "modify", map[string]string{"project": projectID, "id": evType})
		if err != nil {
			_ = helpers.Logger.LogError(helpers.GetRequestID(ctx), "Failed to validate token for delete eventing schema", err, nil)
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, nil)
		status, err := syncMan.SetDeleteEventingSchema(ctx, projectID, evType, reqParams)
		if err != nil {
			_ = helpers.Logger.LogError(helpers.GetRequestID(ctx), "Failed to delete eventing schema", err, nil)
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendOkayResponse(ctx, status, w)
	}
}
func HandleAddEventingSecurityRule(adminMan *admin.Manager, syncMan *syncman.Manager) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		token := utils.GetTokenFromHeader(r)
		vars := mux.Vars(r)
		projectID := vars["project"]
		evType := vars["id"]
		c := new(config.Rule)
		_ = json.NewDecoder(r.Body).Decode(&c)
		defer utils.CloseTheCloser(r.Body)
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		reqParams, err := adminMan.IsTokenValid(ctx, token, "eventing-rule", "modify", map[string]string{"project": projectID, "id": evType})
		if err != nil {
			_ = helpers.Logger.LogError(helpers.GetRequestID(ctx), "Failed to validate token for set eventing rules", err, nil)
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusUnauthorized, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, c)
		status, err := syncMan.SetEventingSecurityRules(ctx, projectID, evType, c, reqParams)
		if err != nil {
			_ = helpers.Logger.LogError(helpers.GetRequestID(ctx), "Failed to add eventing rules", err, nil)
			_ = helpers.Response.SendErrorResponse(ctx, w, status, err)
			return
		}
		_ = helpers.Response.SendOkayResponse(ctx, status, w)
	}
}