Add realtime gateway and simulator bridge
This commit is contained in:
24
realtime-gateway/internal/gateway/auth.go
Normal file
24
realtime-gateway/internal/gateway/auth.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"realtime-gateway/internal/config"
|
||||
"realtime-gateway/internal/model"
|
||||
)
|
||||
|
||||
func authorize(cfg config.AuthConfig, role model.Role, token string) bool {
|
||||
switch role {
|
||||
case model.RoleProducer:
|
||||
return slices.Contains(cfg.ProducerTokens, token)
|
||||
case model.RoleController:
|
||||
return slices.Contains(cfg.ControllerTokens, token)
|
||||
case model.RoleConsumer:
|
||||
if cfg.AllowAnonymousConsumers && token == "" {
|
||||
return true
|
||||
}
|
||||
return slices.Contains(cfg.ConsumerTokens, token)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user