From c60987d940da6537612f10d2b777a0d7f3c22959 Mon Sep 17 00:00:00 2001 From: SammyOina Date: Wed, 23 Aug 2023 17:00:35 +0300 Subject: [PATCH] add docker files update readme Signed-off-by: SammyOina --- .gitignore | 27 ++++++ Makefile | 45 +++++++++- docker/.env | 3 + docker/Dockerfile | 20 +++++ docker/Dockerfile.dev | 5 ++ docker/brokers/nats.yml | 8 -- docker/brokers/rabbitmq.yml | 11 --- docker/docker-compose.yml | 14 +--- go.mod | 4 +- go.sum | 8 +- vendor/github.com/mainflux/mainflux/Makefile | 82 +++++++++++++++++-- .../mainflux/mainflux/mqtt/handler.go | 40 +++++---- .../mainflux/mainflux/pkg/errors/types.go | 3 + .../mainflux/mproxy/pkg/session/handler.go | 10 +-- .../mainflux/mproxy/pkg/session/stream.go | 16 ++-- vendor/modules.txt | 6 +- 16 files changed, 221 insertions(+), 81 deletions(-) create mode 100644 .gitignore create mode 100644 docker/Dockerfile create mode 100644 docker/Dockerfile.dev delete mode 100644 docker/brokers/nats.yml delete mode 100644 docker/brokers/rabbitmq.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c34af38 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +/build + +*.cov + +*.BIN diff --git a/Makefile b/Makefile index da6cc79..3b2eacc 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,56 @@ # Copyright (c) Mainflux # SPDX-License-Identifier: Apache-2.0 -PROGRAM = mproxy +PROGRAM = aproxy +MF_DOCKER_IMAGE_NAME_PREFIX ?= amdm SOURCES = $(wildcard *.go) cmd/main.go +CGO_ENABLED ?= 0 +GOARCH ?= amd64 +VERSION ?= $(shell git describe --abbrev=0 --tags 2>/dev/null || echo "0.13.0") +COMMIT ?= $(shell git rev-parse HEAD) +TIME ?= $(shell date +%F_%T) all: $(PROGRAM) .PHONY: all clean $(PROGRAM) +define make_docker + docker build \ + --no-cache \ + --build-arg SVC=$(PROGRAM) \ + --build-arg GOARCH=$(GOARCH) \ + --build-arg GOARM=$(GOARM) \ + --build-arg VERSION=$(VERSION) \ + --build-arg COMMIT=$(COMMIT) \ + --build-arg TIME=$(TIME) \ + --tag=$(MF_DOCKER_IMAGE_NAME_PREFIX)/$(PROGRAM) \ + -f docker/Dockerfile . +endef + +define make_docker_dev + docker build \ + --no-cache \ + --build-arg SVC=$(PROGRAM) \ + --tag=$(MF_DOCKER_IMAGE_NAME_PREFIX)/$(PROGRAM) \ + -f docker/Dockerfile.dev ./build +endef + $(PROGRAM): $(SOURCES) - go build -ldflags "-s -w" -o ./build/$@ cmd/main.go + CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) \ + go build -mod=vendor -ldflags "-s -w \ + -X 'github.com/mainflux/mainflux.BuildTime=$(TIME)' \ + -X 'github.com/mainflux/mainflux.Version=$(VERSION)' \ + -X 'github.com/mainflux/mainflux.Commit=$(COMMIT)'" \ + -o ./build/$(MF_DOCKER_IMAGE_NAME_PREFIX)-$(PROGRAM) cmd/main.go clean: rm -rf $(PROGRAM) + +docker-image: + $(call make_docker) +docker-dev: + $(call make_docker_dev) + +run: + docker compose -f ./docker/docker-compose.yml up + diff --git a/docker/.env b/docker/.env index b6f4ea2..514b163 100644 --- a/docker/.env +++ b/docker/.env @@ -32,3 +32,6 @@ MF_MQTT_ADAPTER_ES_PASS= MF_MQTT_ADAPTER_INSTANCE_ID= MF_MQTT_ADAPTER_ES_DB=0 MF_MQTT_ADAPTER_CONFIG_FILE="config.toml" + +# Docker image tag +MF_RELEASE_TAG=latest diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..5c57ab6 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.21.0-alpine AS builder +ARG SVC +ARG GOARCH +ARG GOARM +ARG VERSION +ARG COMMIT +ARG TIME + +WORKDIR /go/src/github.com/absmach/aproxy +COPY . . +RUN apk update \ + && apk add make\ + && make $SVC \ + && mv build/amdm-$SVC /exe + +FROM scratch +# Certificates are needed so that mailing util can work. +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /exe / +ENTRYPOINT ["/exe"] diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev new file mode 100644 index 0000000..51ebdc5 --- /dev/null +++ b/docker/Dockerfile.dev @@ -0,0 +1,5 @@ +FROM scratch +ARG SVC +COPY amdm-$SVC /exe +COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +ENTRYPOINT ["/exe"] diff --git a/docker/brokers/nats.yml b/docker/brokers/nats.yml deleted file mode 100644 index f2a53d9..0000000 --- a/docker/brokers/nats.yml +++ /dev/null @@ -1,8 +0,0 @@ -services: - broker: - image: nats:2.2.4-alpine - command: "-c /etc/nats/nats.conf -DV" - volumes: - - ./../nats/:/etc/nats - ports: - - ${MF_NATS_PORT}:${MF_NATS_PORT} diff --git a/docker/brokers/rabbitmq.yml b/docker/brokers/rabbitmq.yml deleted file mode 100644 index 90c81cf..0000000 --- a/docker/brokers/rabbitmq.yml +++ /dev/null @@ -1,11 +0,0 @@ -services: - broker: - image: rabbitmq:3.9.20-management-alpine - environment: - RABBITMQ_ERLANG_COOKIE: ${MF_RABBITMQ_COOKIE} - RABBITMQ_DEFAULT_USER: ${MF_RABBITMQ_USER} - RABBITMQ_DEFAULT_PASS: ${MF_RABBITMQ_PASS} - RABBITMQ_DEFAULT_VHOST: ${MF_RABBITMQ_VHOST} - ports: - - ${MF_RABBITMQ_PORT}:${MF_RABBITMQ_PORT} - - ${MF_RABBITMQ_HTTP_PORT}:${MF_RABBITMQ_HTTP_PORT} diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 8d0dbab..194e156 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,12 +2,10 @@ version: "3.7" networks: mainflux-base-net: - driver: bridge - external: true services: mqtt-adapter: - image: mainflux/mqtt:${MF_RELEASE_TAG} + image: amdm/aproxy:${MF_RELEASE_TAG} container_name: mainflux-mqtt restart: on-failure environment: @@ -35,13 +33,3 @@ services: MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY} networks: - mainflux-base-net - broker: - extends: - file: brokers/nats.yml - service: broker - container_name: mainflux-broker - restart: on-failure - networks: - - mainflux-base-net - ports: - - 4222:4222 \ No newline at end of file diff --git a/go.mod b/go.mod index 30938ca..1778842 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/cenkalti/backoff/v4 v4.2.1 github.com/mainflux/callhome v0.0.0-20230626140149-b03b1f4c46f2 github.com/mainflux/mainflux v0.12.0 - github.com/mainflux/mproxy v0.3.0 + github.com/mainflux/mproxy v0.3.1-0.20230822124450-4b4dfe600cc2 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 golang.org/x/sync v0.3.0 google.golang.org/grpc v1.56.1 @@ -64,4 +64,4 @@ require ( google.golang.org/protobuf v1.31.0 // indirect ) -replace github.com/mainflux/mainflux => github.com/mainflux/mainflux v0.0.0-20230811131717-9dbe87f03a1a +replace github.com/mainflux/mainflux => github.com/mainflux/mainflux v0.0.0-20230823124803-822a607e31fe diff --git a/go.sum b/go.sum index 9a81232..30645b1 100644 --- a/go.sum +++ b/go.sum @@ -184,10 +184,10 @@ github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mainflux/callhome v0.0.0-20230626140149-b03b1f4c46f2 h1:QN+yhU6Twwwwz8Mu9u12f2TbPsmM/zIvndAhH1dIdWU= github.com/mainflux/callhome v0.0.0-20230626140149-b03b1f4c46f2/go.mod h1:q4cTH8I3Y6kDyocJh5dBppuv4dY9drb/2kVdB6FP124= -github.com/mainflux/mainflux v0.0.0-20230811131717-9dbe87f03a1a h1:y4dbYC2XQKAhJ3Q8sGJe0WzDL8tADh7H0P15CSsyIzg= -github.com/mainflux/mainflux v0.0.0-20230811131717-9dbe87f03a1a/go.mod h1:N1M7LhMt/mvgjn0Z5m2kRfJir6aTv0mDOJZPNKVcacI= -github.com/mainflux/mproxy v0.3.0 h1:tU60nu/Bd5lWb7NlJJvW6ulKxeBGJFnp5uOS9j6JXBQ= -github.com/mainflux/mproxy v0.3.0/go.mod h1:nG9MP2YbS8ax26Z8mvJOYohhi3ebYwSlOmePzbfv2ew= +github.com/mainflux/mainflux v0.0.0-20230823124803-822a607e31fe h1:galNZWS6B/O0TM8ByATkpXgTTO18lpOmjmxZ9y0kNXg= +github.com/mainflux/mainflux v0.0.0-20230823124803-822a607e31fe/go.mod h1:cHi+VUm+VST3OaROF0W34pqtr7DHOhrjJ3PDNBTI5W4= +github.com/mainflux/mproxy v0.3.1-0.20230822124450-4b4dfe600cc2 h1:D5Ofrffx/4FWehczvJbmzD8lfcOkxcIS4XZE/fwl4mo= +github.com/mainflux/mproxy v0.3.1-0.20230822124450-4b4dfe600cc2/go.mod h1:nG9MP2YbS8ax26Z8mvJOYohhi3ebYwSlOmePzbfv2ew= github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI= github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc= github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY= diff --git a/vendor/github.com/mainflux/mainflux/Makefile b/vendor/github.com/mainflux/mainflux/Makefile index e8b7f80..68f6e57 100644 --- a/vendor/github.com/mainflux/mainflux/Makefile +++ b/vendor/github.com/mainflux/mainflux/Makefile @@ -13,7 +13,14 @@ GOARCH ?= amd64 VERSION ?= $(shell git describe --abbrev=0 --tags) COMMIT ?= $(shell git rev-parse HEAD) TIME ?= $(shell date +%F_%T) - +USER_REPO ?= $(shell git remote get-url origin | sed -e 's/.*\/\([^/]*\)\/\([^/]*\).*/\1_\2/' ) +BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || git describe --tags --abbrev=0 2>/dev/null ) +empty:= +space:= $(empty) $(empty) +DOCKER_PROJECT ?= $(shell echo $(subst $(space),,$(USER_REPO)_$(BRANCH)) | tr -c -s '[:alnum:][=-=]' '_' | tr '[:upper:]' '[:lower:]') +DOCKER_COMPOSE_COMMANDS_SUPPORTED := up down config +DEFAULT_DOCKER_COMPOSE_COMMAND := up +GRPC_MTLS_CERT_FILES_EXISTS = 0 ifneq ($(MF_BROKER_TYPE),) MF_BROKER_TYPE := $(MF_BROKER_TYPE) else @@ -54,9 +61,36 @@ define make_docker_dev -f docker/Dockerfile.dev ./build endef +ADDON_SERVICES = bootstrap cassandra-reader cassandra-writer certs \ + influxdb-reader influxdb-writer lora-adapter mongodb-reader mongodb-writer \ + opcua-adapter postgres-reader postgres-writer provision smpp-notifier smtp-notifier \ + timescale-reader timescale-writer twins + +EXTERNAL_SERVICES = vault prometheus + +ifneq ($(filter run%,$(firstword $(MAKECMDGOALS))),) + temp_args := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + DOCKER_COMPOSE_COMMAND := $(if $(filter $(DOCKER_COMPOSE_COMMANDS_SUPPORTED),$(temp_args)), $(filter $(DOCKER_COMPOSE_COMMANDS_SUPPORTED),$(temp_args)), $(DEFAULT_DOCKER_COMPOSE_COMMAND)) + $(eval $(DOCKER_COMPOSE_COMMAND):;@) +endif + +ifneq ($(filter run_addons%,$(firstword $(MAKECMDGOALS))),) + temp_args := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + RUN_ADDON_ARGS := $(if $(filter-out $(DOCKER_COMPOSE_COMMANDS_SUPPORTED),$(temp_args)), $(filter-out $(DOCKER_COMPOSE_COMMANDS_SUPPORTED),$(temp_args)),$(ADDON_SERVICES) $(EXTERNAL_SERVICES)) + $(eval $(RUN_ADDON_ARGS):;@) +endif + +ifneq ("$(wildcard docker/ssl/certs/*-grpc-*)","") +GRPC_MTLS_CERT_FILES_EXISTS = 1 +else +GRPC_MTLS_CERT_FILES_EXISTS = 0 +endif + +FILTERED_SERVICES = $(filter-out $(RUN_ADDON_ARGS), $(SERVICES)) + all: $(SERVICES) -.PHONY: all $(SERVICES) dockers dockers_dev latest release +.PHONY: all $(SERVICES) dockers dockers_dev latest release run run_addons grpc_mtls_certs check_mtls check_certs clean: rm -rf ${BUILD_DIR} @@ -81,7 +115,7 @@ proto: protoc -I. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative users/policies/*.proto protoc -I. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative things/policies/*.proto -$(SERVICES): +$(FILTERED_SERVICES): $(call compile_service,$(@)) $(DOCKERS): @@ -117,7 +151,45 @@ release: rundev: cd scripts && ./run.sh -run: +grpc_mtls_certs: + $(MAKE) -C docker/ssl users_grpc_certs things_grpc_certs + +check_tls: +ifeq ($(GRPC_TLS),true) + @unset GRPC_MTLS + @echo "gRPC TLS is enabled" + GRPC_MTLS= +else + @unset GRPC_TLS + GRPC_TLS= +endif + +check_mtls: +ifeq ($(GRPC_MTLS),true) + @unset GRPC_TLS + @echo "gRPC MTLS is enabled" + GRPC_TLS= +else + @unset GRPC_MTLS + GRPC_MTLS= +endif + +check_certs: check_mtls check_tls +ifeq ($(GRPC_MTLS_CERT_FILES_EXISTS),0) +ifeq ($(filter true,$(GRPC_MTLS) $(GRPC_TLS)),true) +ifeq ($(filter $(DEFAULT_DOCKER_COMPOSE_COMMAND),$(DOCKER_COMPOSE_COMMAND)),$(DEFAULT_DOCKER_COMPOSE_COMMAND)) + $(MAKE) -C docker/ssl users_grpc_certs things_grpc_certs +endif +endif +endif + +run: check_certs sed -i "s,file: brokers/.*.yml,file: brokers/${MF_BROKER_TYPE}.yml," docker/docker-compose.yml sed -i "s,MF_BROKER_URL=.*,MF_BROKER_URL=$$\{MF_$(shell echo ${MF_BROKER_TYPE} | tr 'a-z' 'A-Z')_URL\}," docker/.env - docker-compose -f docker/docker-compose.yml up + docker-compose -f docker/docker-compose.yml -p $(DOCKER_PROJECT) $(DOCKER_COMPOSE_COMMAND) $(args) + +run_addons: check_certs + $(foreach SVC,$(RUN_ADDON_ARGS),$(if $(filter $(SVC),$(ADDON_SERVICES) $(EXTERNAL_SERVICES)),,$(error Invalid Service $(SVC)))) + @for SVC in $(RUN_ADDON_ARGS); do \ + MF_ADDONS_CERTS_PATH_PREFIX="../." docker-compose -f docker/addons/$$SVC/docker-compose.yml -p $(DOCKER_PROJECT) --env-file ./docker/.env $(DOCKER_COMPOSE_COMMAND) $(args) & \ + done diff --git a/vendor/github.com/mainflux/mainflux/mqtt/handler.go b/vendor/github.com/mainflux/mainflux/mqtt/handler.go index d6fc024..fac0185 100644 --- a/vendor/github.com/mainflux/mainflux/mqtt/handler.go +++ b/vendor/github.com/mainflux/mainflux/mqtt/handler.go @@ -139,21 +139,20 @@ func (h *handler) AuthSubscribe(ctx context.Context, topics *[]string) error { } // Connect - after client successfully connected. -func (h *handler) Connect(ctx context.Context) { +func (h *handler) Connect(ctx context.Context) error { s, ok := session.FromContext(ctx) if !ok { - h.logger.Error(errors.Wrap(ErrFailedConnect, ErrClientNotInitialized).Error()) - return + return errors.Wrap(ErrFailedConnect, ErrClientNotInitialized) } h.logger.Info(fmt.Sprintf(LogInfoConnected, s.ID)) + return nil } // Publish - after client successfully published. -func (h *handler) Publish(ctx context.Context, topic *string, payload *[]byte) { +func (h *handler) Publish(ctx context.Context, topic *string, payload *[]byte) error { s, ok := session.FromContext(ctx) if !ok { - h.logger.Error(errors.Wrap(ErrFailedPublish, ErrClientNotInitialized).Error()) - return + return errors.Wrap(ErrFailedPublish, ErrClientNotInitialized) } h.logger.Info(fmt.Sprintf(LogInfoPublished, s.ID, *topic)) // Topics are in the format: @@ -161,8 +160,7 @@ func (h *handler) Publish(ctx context.Context, topic *string, payload *[]byte) { channelParts := channelRegExp.FindStringSubmatch(*topic) if len(channelParts) < 2 { - h.logger.Error(errors.Wrap(ErrFailedPublish, ErrMalformedTopic).Error()) - return + return errors.Wrap(ErrFailedPublish, ErrMalformedTopic) } chanID := channelParts[1] @@ -170,8 +168,7 @@ func (h *handler) Publish(ctx context.Context, topic *string, payload *[]byte) { subtopic, err := parseSubtopic(subtopic) if err != nil { - h.logger.Error(errors.Wrap(ErrFailedParseSubtopic, err).Error()) - return + return errors.Wrap(ErrFailedParseSubtopic, err) } msg := messaging.Message{ @@ -185,42 +182,43 @@ func (h *handler) Publish(ctx context.Context, topic *string, payload *[]byte) { for _, pub := range h.publishers { if err := pub.Publish(ctx, msg.Channel, &msg); err != nil { - h.logger.Error(errors.Wrap(ErrFailedPublishToMsgBroker, err).Error()) + return errors.Wrap(ErrFailedPublishToMsgBroker, err) } } + return nil } // Subscribe - after client successfully subscribed. -func (h *handler) Subscribe(ctx context.Context, topics *[]string) { +func (h *handler) Subscribe(ctx context.Context, topics *[]string) error { s, ok := session.FromContext(ctx) if !ok { - h.logger.Error(errors.Wrap(ErrFailedSubscribe, ErrClientNotInitialized).Error()) - return + return errors.Wrap(ErrFailedSubscribe, ErrClientNotInitialized) } h.logger.Info(fmt.Sprintf(LogInfoSubscribed, s.ID, strings.Join(*topics, ","))) + return nil } // Unsubscribe - after client unsubscribed. -func (h *handler) Unsubscribe(ctx context.Context, topics *[]string) { +func (h *handler) Unsubscribe(ctx context.Context, topics *[]string) error { s, ok := session.FromContext(ctx) if !ok { - h.logger.Error(errors.Wrap(ErrFailedUnsubscribe, ErrClientNotInitialized).Error()) - return + return errors.Wrap(ErrFailedUnsubscribe, ErrClientNotInitialized) } h.logger.Info(fmt.Sprintf(LogInfoUnsubscribed, s.ID, strings.Join(*topics, ","))) + return nil } // Disconnect - connection with broker or client lost. -func (h *handler) Disconnect(ctx context.Context) { +func (h *handler) Disconnect(ctx context.Context) error { s, ok := session.FromContext(ctx) if !ok { - h.logger.Error(errors.Wrap(ErrFailedDisconnect, ErrClientNotInitialized).Error()) - return + return errors.Wrap(ErrFailedDisconnect, ErrClientNotInitialized) } h.logger.Error(fmt.Sprintf(LogInfoDisconnected, s.ID, s.Password)) if err := h.es.Disconnect(ctx, string(s.Password)); err != nil { - h.logger.Error(errors.Wrap(ErrFailedPublishDisconnectEvent, err).Error()) + return errors.Wrap(ErrFailedPublishDisconnectEvent, err) } + return nil } func (h *handler) authAccess(ctx context.Context, password, topic, action string) error { diff --git a/vendor/github.com/mainflux/mainflux/pkg/errors/types.go b/vendor/github.com/mainflux/mainflux/pkg/errors/types.go index d62ccfc..b924148 100644 --- a/vendor/github.com/mainflux/mainflux/pkg/errors/types.go +++ b/vendor/github.com/mainflux/mainflux/pkg/errors/types.go @@ -36,4 +36,7 @@ var ( // ErrWrongSecret indicates a wrong secret was provided. ErrWrongSecret = New("wrong secret") + + // ErrLogin indicates wrong login credentials. + ErrLogin = New("invalid user id or secret") ) diff --git a/vendor/github.com/mainflux/mproxy/pkg/session/handler.go b/vendor/github.com/mainflux/mproxy/pkg/session/handler.go index de62ca7..a58bc6a 100644 --- a/vendor/github.com/mainflux/mproxy/pkg/session/handler.go +++ b/vendor/github.com/mainflux/mproxy/pkg/session/handler.go @@ -17,17 +17,17 @@ type Handler interface { AuthSubscribe(ctx context.Context, topics *[]string) error // After client successfully connected - Connect(ctx context.Context) + Connect(ctx context.Context) error // After client successfully published - Publish(ctx context.Context, topic *string, payload *[]byte) + Publish(ctx context.Context, topic *string, payload *[]byte) error // After client successfully subscribed - Subscribe(ctx context.Context, topics *[]string) + Subscribe(ctx context.Context, topics *[]string) error // After client unsubscribed - Unsubscribe(ctx context.Context, topics *[]string) + Unsubscribe(ctx context.Context, topics *[]string) error // Disconnect on connection with client lost - Disconnect(ctx context.Context) + Disconnect(ctx context.Context) error } diff --git a/vendor/github.com/mainflux/mproxy/pkg/session/stream.go b/vendor/github.com/mainflux/mproxy/pkg/session/stream.go index 48ca217..b73b254 100644 --- a/vendor/github.com/mainflux/mproxy/pkg/session/stream.go +++ b/vendor/github.com/mainflux/mproxy/pkg/session/stream.go @@ -67,7 +67,9 @@ func stream(ctx context.Context, dir direction, r, w net.Conn, h Handler, errs c } if dir == up { - notify(ctx, pkt, h) + if err := notify(ctx, pkt, h); err != nil { + errs <- wrap(ctx, err, dir) + } } } } @@ -101,18 +103,18 @@ func authorize(ctx context.Context, pkt packets.ControlPacket, h Handler) error } } -func notify(ctx context.Context, pkt packets.ControlPacket, h Handler) { +func notify(ctx context.Context, pkt packets.ControlPacket, h Handler) error { switch p := pkt.(type) { case *packets.ConnectPacket: - h.Connect(ctx) + return h.Connect(ctx) case *packets.PublishPacket: - h.Publish(ctx, &p.TopicName, &p.Payload) + return h.Publish(ctx, &p.TopicName, &p.Payload) case *packets.SubscribePacket: - h.Subscribe(ctx, &p.Topics) + return h.Subscribe(ctx, &p.Topics) case *packets.UnsubscribePacket: - h.Unsubscribe(ctx, &p.Topics) + return h.Unsubscribe(ctx, &p.Topics) default: - return + return nil } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 87f1455..80cacfa 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -155,7 +155,7 @@ github.com/lestrrat-go/option # github.com/mainflux/callhome v0.0.0-20230626140149-b03b1f4c46f2 ## explicit; go 1.20 github.com/mainflux/callhome/pkg/client -# github.com/mainflux/mainflux v0.12.0 => github.com/mainflux/mainflux v0.0.0-20230811131717-9dbe87f03a1a +# github.com/mainflux/mainflux v0.12.0 => github.com/mainflux/mainflux v0.0.0-20230823124803-822a607e31fe ## explicit; go 1.20 github.com/mainflux/mainflux github.com/mainflux/mainflux/internal/apiutil @@ -182,7 +182,7 @@ github.com/mainflux/mainflux/things/policies github.com/mainflux/mainflux/things/policies/api/grpc github.com/mainflux/mainflux/users/jwt github.com/mainflux/mainflux/users/policies -# github.com/mainflux/mproxy v0.3.0 +# github.com/mainflux/mproxy v0.3.1-0.20230822124450-4b4dfe600cc2 ## explicit; go 1.19 github.com/mainflux/mproxy/pkg/logger github.com/mainflux/mproxy/pkg/mqtt @@ -386,4 +386,4 @@ google.golang.org/protobuf/types/descriptorpb google.golang.org/protobuf/types/known/anypb google.golang.org/protobuf/types/known/durationpb google.golang.org/protobuf/types/known/timestamppb -# github.com/mainflux/mainflux => github.com/mainflux/mainflux v0.0.0-20230811131717-9dbe87f03a1a +# github.com/mainflux/mainflux => github.com/mainflux/mainflux v0.0.0-20230823124803-822a607e31fe