mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
add jwt verification to stopJob nats handler
This commit is contained in:
parent
fafc729c86
commit
0bf316dbf4
@ -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) {
|
||||||
var req StopJobNatsRequest
|
user, err := nm.verifyMessageJWT(m)
|
||||||
if err := json.Unmarshal(m.Data, &req); err != nil {
|
|
||||||
log.Error("Error while unmarshaling raw json nats message content: stopJob")
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Respond(nm.stopJobHandler(req))
|
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
|
||||||
|
if err := json.Unmarshal(m.Data, &req); err != nil {
|
||||||
|
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))
|
||||||
|
} else {
|
||||||
|
log.Warnf("missing role for nats")
|
||||||
|
m.Respond([]byte("missing role for nats"))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user