mirror of
https://github.com/absmach/magistrala.git
synced 2026-08-07 07:14:46 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 436db8877d | |||
| 4da66aecbf |
@@ -31,7 +31,7 @@ const (
|
||||
authQuery = "auth"
|
||||
)
|
||||
|
||||
var channelPartRegExp = regexp.MustCompile(`^channels/([\w\-]+)/messages(/[^?]*)?(\?.*)?$`)
|
||||
var channelPartRegExp = regexp.MustCompile(`^ch/([\w\-]+)/msg(/[^?]*)?(\?.*)?$`)
|
||||
|
||||
var errMalformedSubtopic = errors.New("malformed subtopic")
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ var (
|
||||
errMalformedSubtopic = errors.New("malformed subtopic")
|
||||
)
|
||||
|
||||
var channelPartRegExp = regexp.MustCompile(`^/channels/([\w\-]+)/messages(/[^?]*)?(\?.*)?$`)
|
||||
var channelPartRegExp = regexp.MustCompile(`^/ch/([\w\-]+)/msg(/[^?]*)?(\?.*)?$`)
|
||||
|
||||
// MakeHandler returns a HTTP handler for API endpoints.
|
||||
func MakeHandler(svc adapter.Service, tracer opentracing.Tracer) http.Handler {
|
||||
@@ -43,14 +43,14 @@ func MakeHandler(svc adapter.Service, tracer opentracing.Tracer) http.Handler {
|
||||
}
|
||||
|
||||
r := bone.New()
|
||||
r.Post("/channels/:id/messages", kithttp.NewServer(
|
||||
r.Post("/ch/:id/msg", kithttp.NewServer(
|
||||
kitot.TraceServer(tracer, "publish")(sendMessageEndpoint(svc)),
|
||||
decodeRequest,
|
||||
encodeResponse,
|
||||
opts...,
|
||||
))
|
||||
|
||||
r.Post("/channels/:id/messages/*", kithttp.NewServer(
|
||||
r.Post("/ch/:id/msg/*", kithttp.NewServer(
|
||||
kitot.TraceServer(tracer, "publish")(sendMessageEndpoint(svc)),
|
||||
decodeRequest,
|
||||
encodeResponse,
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
channels = "channels"
|
||||
messages = "messages"
|
||||
channels = "ch"
|
||||
messages = "msg"
|
||||
)
|
||||
|
||||
// Forwarder specifies MQTT forwarder interface API.
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ var _ session.Handler = (*handler)(nil)
|
||||
const protocol = "mqtt"
|
||||
|
||||
var (
|
||||
channelRegExp = regexp.MustCompile(`^\/?channels\/([\w\-]+)\/messages(\/[^?]*)?(\?.*)?$`)
|
||||
channelRegExp = regexp.MustCompile(`^\/?ch\/([\w\-]+)\/msg(\/[^?]*)?(\?.*)?$`)
|
||||
errMalformedTopic = errors.New("malformed topic")
|
||||
errMalformedData = errors.New("malformed request data")
|
||||
errMalformedSubtopic = errors.New("malformed subtopic")
|
||||
@@ -125,7 +125,7 @@ func (h *handler) Publish(c *session.Client, topic *string, payload *[]byte) {
|
||||
}
|
||||
h.logger.Info("Publish - client ID " + c.ID + " to the topic: " + *topic)
|
||||
// Topics are in the format:
|
||||
// channels/<channel_id>/messages/<subtopic>/.../ct/<content_type>
|
||||
// ch/<channel_id>/msg/<subtopic>/.../ct/<content_type>
|
||||
|
||||
channelParts := channelRegExp.FindStringSubmatch(*topic)
|
||||
if len(channelParts) < 1 {
|
||||
@@ -190,7 +190,7 @@ func (h *handler) Disconnect(c *session.Client) {
|
||||
|
||||
func (h *handler) authAccess(username string, topic string) error {
|
||||
// Topics are in the format:
|
||||
// channels/<channel_id>/messages/<subtopic>/.../ct/<content_type>
|
||||
// ch/<channel_id>/msg/<subtopic>/.../ct/<content_type>
|
||||
if !channelRegExp.Match([]byte(topic)) {
|
||||
h.logger.Info("Malformed topic: " + topic)
|
||||
return errMalformedTopic
|
||||
|
||||
Reference in New Issue
Block a user