add jwt verification to stopJob nats handler

This commit is contained in:
Christoph Kluge 2024-08-12 17:29:06 +02:00
parent fafc729c86
commit 0bf316dbf4

View File

@ -215,12 +215,22 @@ func (nm *NatsMessenger) startJobListener() (sub *nats.Subscription, err error)
func (nm *NatsMessenger) stopJobListener() (sub *nats.Subscription, err error) { func (nm *NatsMessenger) stopJobListener() (sub *nats.Subscription, err error) {
return nm.Connection.Subscribe("stop-job", func(m *nats.Msg) { return nm.Connection.Subscribe("stop-job", func(m *nats.Msg) {
user, err := nm.verifyMessageJWT(m)
if err != nil {
log.Warnf("not authd: %s", err.Error())
m.Respond([]byte("not authd: " + err.Error()))
} else if user != nil && user.HasRole(schema.RoleApi) {
var req StopJobNatsRequest var req StopJobNatsRequest
if err := json.Unmarshal(m.Data, &req); err != nil { if err := json.Unmarshal(m.Data, &req); err != nil {
log.Error("Error while unmarshaling raw json nats message content: stopJob") log.Error("Error while unmarshaling raw json nats message content: stopJob")
m.Respond([]byte("Error while unmarshaling raw json nats message content: stopJob"))
} }
m.Respond(nm.stopJobHandler(req)) m.Respond(nm.stopJobHandler(req))
} else {
log.Warnf("missing role for nats")
m.Respond([]byte("missing role for nats"))
}
}) })
} }