mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-16 13:04:34 +00:00
Multitenant streams api (#72)
This commit is contained in:
@@ -3,6 +3,8 @@ package handler
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/micro/micro/v3/service/auth"
|
||||
"github.com/micro/micro/v3/service/errors"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
pb "github.com/micro/services/streams/proto"
|
||||
)
|
||||
@@ -12,11 +14,18 @@ func (s *Streams) Publish(ctx context.Context, req *pb.Message, rsp *pb.PublishR
|
||||
if len(req.Topic) == 0 {
|
||||
return ErrMissingTopic
|
||||
}
|
||||
if err := validateTopicInput(req.Topic); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(req.Message) == 0 {
|
||||
return ErrMissingMessage
|
||||
}
|
||||
acc, ok := auth.AccountFromContext(ctx)
|
||||
if !ok {
|
||||
return errors.Unauthorized("UNAUTHORIZED", "Unauthorized")
|
||||
}
|
||||
|
||||
// publish the message
|
||||
logger.Infof("Publishing message to topic: %v", req.Topic)
|
||||
return s.Events.Publish(req.Topic, req.Message)
|
||||
return s.Events.Publish(fmtTopic(acc.Issuer, req.Topic), req.Message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user