From a34df79e9b7e8d0ff3eb1a5f7180ec357d947b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Borov=C4=8Danin?= Date: Tue, 31 Dec 2024 18:00:47 +0100 Subject: [PATCH] NOISSUE - Use Magistrala packages instead of SMQ (#24) * Use Magistrala packages where needed Signed-off-by: Dusan Borovcanin * Move SMQ scripts to MG Signed-off-by: Dusan Borovcanin --------- Signed-off-by: Dusan Borovcanin --- bootstrap/api/endpoint.go | 2 +- bootstrap/api/endpoint_test.go | 6 ++-- bootstrap/api/requests.go | 2 +- bootstrap/api/requests_test.go | 2 +- bootstrap/api/responses.go | 2 +- bootstrap/api/transport.go | 2 +- bootstrap/events/consumer/streams.go | 2 +- bootstrap/events/producer/events.go | 2 +- bootstrap/events/producer/streams.go | 2 +- bootstrap/events/producer/streams_test.go | 6 ++-- bootstrap/middleware/authorization.go | 2 +- bootstrap/middleware/logging.go | 2 +- bootstrap/middleware/metrics.go | 2 +- bootstrap/mocks/config_reader.go | 2 +- bootstrap/mocks/configs.go | 2 +- bootstrap/mocks/service.go | 2 +- bootstrap/postgres/configs.go | 2 +- bootstrap/postgres/configs_test.go | 4 +-- bootstrap/postgres/setup_test.go | 2 +- bootstrap/reader_test.go | 2 +- bootstrap/service_test.go | 4 +-- bootstrap/tracing/tracing.go | 2 +- cmd/bootstrap/main.go | 14 ++++----- cmd/postgres-reader/main.go | 2 +- cmd/postgres-writer/main.go | 6 ++-- cmd/timescale-reader/main.go | 2 +- cmd/timescale-writer/main.go | 6 ++-- consumers/notifiers/api/endpoint_test.go | 4 +-- consumers/notifiers/notifier.go | 22 -------------- consumers/notifiers/postgres/setup_test.go | 2 +- .../notifiers/postgres/subscriptions_test.go | 2 +- consumers/notifiers/service.go | 9 +++--- consumers/notifiers/service_test.go | 2 +- consumers/writers/postgres/consumer_test.go | 2 +- consumers/writers/postgres/setup_test.go | 2 +- consumers/writers/timescale/consumer_test.go | 2 +- consumers/writers/timescale/setup_test.go | 2 +- readers/postgres/messages_test.go | 4 +-- readers/postgres/setup_test.go | 2 +- readers/timescale/messages_test.go | 4 +-- readers/timescale/setup_test.go | 2 +- scripts/ci.sh | 10 +++---- scripts/csv/channels.csv | 3 ++ scripts/csv/clients.csv | 10 +++++++ scripts/provision-dev.sh | 30 +++++++++---------- scripts/run.sh | 20 ++++++------- 46 files changed, 106 insertions(+), 114 deletions(-) delete mode 100644 consumers/notifiers/notifier.go create mode 100644 scripts/csv/channels.csv create mode 100644 scripts/csv/clients.csv diff --git a/bootstrap/api/endpoint.go b/bootstrap/api/endpoint.go index 7889c1e98..59b534fb4 100644 --- a/bootstrap/api/endpoint.go +++ b/bootstrap/api/endpoint.go @@ -6,9 +6,9 @@ package api import ( "context" + "github.com/absmach/magistrala/bootstrap" api "github.com/absmach/supermq/api/http" apiutil "github.com/absmach/supermq/api/http/util" - "github.com/absmach/supermq/bootstrap" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/bootstrap/api/endpoint_test.go b/bootstrap/api/endpoint_test.go index 9429d3378..68db2106e 100644 --- a/bootstrap/api/endpoint_test.go +++ b/bootstrap/api/endpoint_test.go @@ -18,11 +18,11 @@ import ( "strings" "testing" + "github.com/absmach/magistrala/bootstrap" + bsapi "github.com/absmach/magistrala/bootstrap/api" + "github.com/absmach/magistrala/bootstrap/mocks" "github.com/absmach/magistrala/internal/testsutil" apiutil "github.com/absmach/supermq/api/http/util" - "github.com/absmach/supermq/bootstrap" - bsapi "github.com/absmach/supermq/bootstrap/api" - "github.com/absmach/supermq/bootstrap/mocks" smqlog "github.com/absmach/supermq/logger" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" diff --git a/bootstrap/api/requests.go b/bootstrap/api/requests.go index a83e31904..15a820e01 100644 --- a/bootstrap/api/requests.go +++ b/bootstrap/api/requests.go @@ -4,8 +4,8 @@ package api import ( + "github.com/absmach/magistrala/bootstrap" apiutil "github.com/absmach/supermq/api/http/util" - "github.com/absmach/supermq/bootstrap" ) const maxLimitSize = 100 diff --git a/bootstrap/api/requests_test.go b/bootstrap/api/requests_test.go index caf9e8fb8..4b30159fd 100644 --- a/bootstrap/api/requests_test.go +++ b/bootstrap/api/requests_test.go @@ -7,9 +7,9 @@ import ( "fmt" "testing" + "github.com/absmach/magistrala/bootstrap" "github.com/absmach/magistrala/internal/testsutil" apiutil "github.com/absmach/supermq/api/http/util" - "github.com/absmach/supermq/bootstrap" "github.com/stretchr/testify/assert" ) diff --git a/bootstrap/api/responses.go b/bootstrap/api/responses.go index 59d73df74..820da029f 100644 --- a/bootstrap/api/responses.go +++ b/bootstrap/api/responses.go @@ -7,8 +7,8 @@ import ( "fmt" "net/http" + "github.com/absmach/magistrala/bootstrap" "github.com/absmach/supermq" - "github.com/absmach/supermq/bootstrap" ) var ( diff --git a/bootstrap/api/transport.go b/bootstrap/api/transport.go index c5c9baacf..15944826e 100644 --- a/bootstrap/api/transport.go +++ b/bootstrap/api/transport.go @@ -11,10 +11,10 @@ import ( "net/url" "strings" + "github.com/absmach/magistrala/bootstrap" "github.com/absmach/supermq" api "github.com/absmach/supermq/api/http" apiutil "github.com/absmach/supermq/api/http/util" - "github.com/absmach/supermq/bootstrap" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" diff --git a/bootstrap/events/consumer/streams.go b/bootstrap/events/consumer/streams.go index 1e34e48e2..e8d8c2b22 100644 --- a/bootstrap/events/consumer/streams.go +++ b/bootstrap/events/consumer/streams.go @@ -7,7 +7,7 @@ import ( "context" "time" - "github.com/absmach/supermq/bootstrap" + "github.com/absmach/magistrala/bootstrap" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/absmach/supermq/pkg/events" ) diff --git a/bootstrap/events/producer/events.go b/bootstrap/events/producer/events.go index dd7ece9c2..0e05ff2e1 100644 --- a/bootstrap/events/producer/events.go +++ b/bootstrap/events/producer/events.go @@ -4,7 +4,7 @@ package producer import ( - "github.com/absmach/supermq/bootstrap" + "github.com/absmach/magistrala/bootstrap" "github.com/absmach/supermq/pkg/events" ) diff --git a/bootstrap/events/producer/streams.go b/bootstrap/events/producer/streams.go index 55408e07e..37fedee9a 100644 --- a/bootstrap/events/producer/streams.go +++ b/bootstrap/events/producer/streams.go @@ -6,7 +6,7 @@ package producer import ( "context" - "github.com/absmach/supermq/bootstrap" + "github.com/absmach/magistrala/bootstrap" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/events" ) diff --git a/bootstrap/events/producer/streams_test.go b/bootstrap/events/producer/streams_test.go index 3c8bb2ddc..15aa9eaf1 100644 --- a/bootstrap/events/producer/streams_test.go +++ b/bootstrap/events/producer/streams_test.go @@ -11,10 +11,10 @@ import ( "testing" "time" + "github.com/absmach/magistrala/bootstrap" + "github.com/absmach/magistrala/bootstrap/events/producer" + "github.com/absmach/magistrala/bootstrap/mocks" "github.com/absmach/magistrala/internal/testsutil" - "github.com/absmach/supermq/bootstrap" - "github.com/absmach/supermq/bootstrap/events/producer" - "github.com/absmach/supermq/bootstrap/mocks" "github.com/absmach/supermq/pkg/authn" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" diff --git a/bootstrap/middleware/authorization.go b/bootstrap/middleware/authorization.go index de04f65fb..a8e9002af 100644 --- a/bootstrap/middleware/authorization.go +++ b/bootstrap/middleware/authorization.go @@ -6,7 +6,7 @@ package middleware import ( "context" - "github.com/absmach/supermq/bootstrap" + "github.com/absmach/magistrala/bootstrap" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/authz" smqauthz "github.com/absmach/supermq/pkg/authz" diff --git a/bootstrap/middleware/logging.go b/bootstrap/middleware/logging.go index a6d23497c..3d484b479 100644 --- a/bootstrap/middleware/logging.go +++ b/bootstrap/middleware/logging.go @@ -10,7 +10,7 @@ import ( "log/slog" "time" - "github.com/absmach/supermq/bootstrap" + "github.com/absmach/magistrala/bootstrap" smqauthn "github.com/absmach/supermq/pkg/authn" ) diff --git a/bootstrap/middleware/metrics.go b/bootstrap/middleware/metrics.go index 89f64ecd4..cc2959019 100644 --- a/bootstrap/middleware/metrics.go +++ b/bootstrap/middleware/metrics.go @@ -9,7 +9,7 @@ import ( "context" "time" - "github.com/absmach/supermq/bootstrap" + "github.com/absmach/magistrala/bootstrap" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/go-kit/kit/metrics" ) diff --git a/bootstrap/mocks/config_reader.go b/bootstrap/mocks/config_reader.go index e4a0d4d9d..5a3361bd5 100644 --- a/bootstrap/mocks/config_reader.go +++ b/bootstrap/mocks/config_reader.go @@ -5,7 +5,7 @@ package mocks import ( - bootstrap "github.com/absmach/supermq/bootstrap" + bootstrap "github.com/absmach/magistrala/bootstrap" mock "github.com/stretchr/testify/mock" ) diff --git a/bootstrap/mocks/configs.go b/bootstrap/mocks/configs.go index 2d80ed0b4..679460c94 100644 --- a/bootstrap/mocks/configs.go +++ b/bootstrap/mocks/configs.go @@ -7,7 +7,7 @@ package mocks import ( context "context" - bootstrap "github.com/absmach/supermq/bootstrap" + bootstrap "github.com/absmach/magistrala/bootstrap" mock "github.com/stretchr/testify/mock" ) diff --git a/bootstrap/mocks/service.go b/bootstrap/mocks/service.go index b822601c4..9d2cf9b03 100644 --- a/bootstrap/mocks/service.go +++ b/bootstrap/mocks/service.go @@ -5,7 +5,7 @@ package mocks import ( - bootstrap "github.com/absmach/supermq/bootstrap" + bootstrap "github.com/absmach/magistrala/bootstrap" authn "github.com/absmach/supermq/pkg/authn" context "context" diff --git a/bootstrap/postgres/configs.go b/bootstrap/postgres/configs.go index 5bc6f3b59..73b3130b1 100644 --- a/bootstrap/postgres/configs.go +++ b/bootstrap/postgres/configs.go @@ -12,7 +12,7 @@ import ( "strings" "time" - "github.com/absmach/supermq/bootstrap" + "github.com/absmach/magistrala/bootstrap" "github.com/absmach/supermq/clients" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" diff --git a/bootstrap/postgres/configs_test.go b/bootstrap/postgres/configs_test.go index 32ca71b8b..dfbb6cf89 100644 --- a/bootstrap/postgres/configs_test.go +++ b/bootstrap/postgres/configs_test.go @@ -9,9 +9,9 @@ import ( "strconv" "testing" + "github.com/absmach/magistrala/bootstrap" + "github.com/absmach/magistrala/bootstrap/postgres" "github.com/absmach/magistrala/internal/testsutil" - "github.com/absmach/supermq/bootstrap" - "github.com/absmach/supermq/bootstrap/postgres" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" "github.com/gofrs/uuid/v5" diff --git a/bootstrap/postgres/setup_test.go b/bootstrap/postgres/setup_test.go index 4151768d9..b762730dc 100644 --- a/bootstrap/postgres/setup_test.go +++ b/bootstrap/postgres/setup_test.go @@ -9,7 +9,7 @@ import ( "os" "testing" - "github.com/absmach/supermq/bootstrap/postgres" + "github.com/absmach/magistrala/bootstrap/postgres" smqlog "github.com/absmach/supermq/logger" pgclient "github.com/absmach/supermq/pkg/postgres" "github.com/jmoiron/sqlx" diff --git a/bootstrap/reader_test.go b/bootstrap/reader_test.go index 28a36bd42..5c12a02b9 100644 --- a/bootstrap/reader_test.go +++ b/bootstrap/reader_test.go @@ -11,8 +11,8 @@ import ( "net/http" "testing" + "github.com/absmach/magistrala/bootstrap" "github.com/absmach/supermq" - "github.com/absmach/supermq/bootstrap" "github.com/absmach/supermq/pkg/errors" "github.com/stretchr/testify/assert" ) diff --git a/bootstrap/service_test.go b/bootstrap/service_test.go index 5f269640c..3a98af978 100644 --- a/bootstrap/service_test.go +++ b/bootstrap/service_test.go @@ -14,9 +14,9 @@ import ( "sort" "testing" + "github.com/absmach/magistrala/bootstrap" + "github.com/absmach/magistrala/bootstrap/mocks" "github.com/absmach/magistrala/internal/testsutil" - "github.com/absmach/supermq/bootstrap" - "github.com/absmach/supermq/bootstrap/mocks" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/bootstrap/tracing/tracing.go b/bootstrap/tracing/tracing.go index c18530e03..877539a7d 100644 --- a/bootstrap/tracing/tracing.go +++ b/bootstrap/tracing/tracing.go @@ -6,7 +6,7 @@ package tracing import ( "context" - "github.com/absmach/supermq/bootstrap" + "github.com/absmach/magistrala/bootstrap" smqauthn "github.com/absmach/supermq/pkg/authn" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index 2476aab73..c7906caee 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -13,14 +13,14 @@ import ( "os" chclient "github.com/absmach/callhome/pkg/client" + "github.com/absmach/magistrala/bootstrap" + httpapi "github.com/absmach/magistrala/bootstrap/api" + "github.com/absmach/magistrala/bootstrap/events/consumer" + "github.com/absmach/magistrala/bootstrap/events/producer" + "github.com/absmach/magistrala/bootstrap/middleware" + bootstrappg "github.com/absmach/magistrala/bootstrap/postgres" + "github.com/absmach/magistrala/bootstrap/tracing" "github.com/absmach/supermq" - "github.com/absmach/supermq/bootstrap" - httpapi "github.com/absmach/supermq/bootstrap/api" - "github.com/absmach/supermq/bootstrap/events/consumer" - "github.com/absmach/supermq/bootstrap/events/producer" - "github.com/absmach/supermq/bootstrap/middleware" - bootstrappg "github.com/absmach/supermq/bootstrap/postgres" - "github.com/absmach/supermq/bootstrap/tracing" smqlog "github.com/absmach/supermq/logger" authsvcAuthn "github.com/absmach/supermq/pkg/authn/authsvc" smqauthz "github.com/absmach/supermq/pkg/authz" diff --git a/cmd/postgres-reader/main.go b/cmd/postgres-reader/main.go index 5157c9270..db4f5dc7f 100644 --- a/cmd/postgres-reader/main.go +++ b/cmd/postgres-reader/main.go @@ -12,6 +12,7 @@ import ( "os" chclient "github.com/absmach/callhome/pkg/client" + "github.com/absmach/magistrala/readers/postgres" "github.com/absmach/supermq" smqlog "github.com/absmach/supermq/logger" "github.com/absmach/supermq/pkg/authn/authsvc" @@ -23,7 +24,6 @@ import ( "github.com/absmach/supermq/pkg/uuid" "github.com/absmach/supermq/readers" httpapi "github.com/absmach/supermq/readers/api" - "github.com/absmach/supermq/readers/postgres" "github.com/caarlos0/env/v11" "github.com/jmoiron/sqlx" "golang.org/x/sync/errgroup" diff --git a/cmd/postgres-writer/main.go b/cmd/postgres-writer/main.go index c6923b217..9455c6fcb 100644 --- a/cmd/postgres-writer/main.go +++ b/cmd/postgres-writer/main.go @@ -13,11 +13,11 @@ import ( "os" chclient "github.com/absmach/callhome/pkg/client" + consumertracing "github.com/absmach/magistrala/consumers/tracing" + httpapi "github.com/absmach/magistrala/consumers/writers/api" + writerpg "github.com/absmach/magistrala/consumers/writers/postgres" "github.com/absmach/supermq" "github.com/absmach/supermq/consumers" - consumertracing "github.com/absmach/supermq/consumers/tracing" - httpapi "github.com/absmach/supermq/consumers/writers/api" - writerpg "github.com/absmach/supermq/consumers/writers/postgres" smqlog "github.com/absmach/supermq/logger" jaegerclient "github.com/absmach/supermq/pkg/jaeger" "github.com/absmach/supermq/pkg/messaging/brokers" diff --git a/cmd/timescale-reader/main.go b/cmd/timescale-reader/main.go index ed5e22913..1f9b2fabb 100644 --- a/cmd/timescale-reader/main.go +++ b/cmd/timescale-reader/main.go @@ -12,6 +12,7 @@ import ( "os" chclient "github.com/absmach/callhome/pkg/client" + "github.com/absmach/magistrala/readers/timescale" "github.com/absmach/supermq" smqlog "github.com/absmach/supermq/logger" "github.com/absmach/supermq/pkg/authn/authsvc" @@ -23,7 +24,6 @@ import ( "github.com/absmach/supermq/pkg/uuid" "github.com/absmach/supermq/readers" httpapi "github.com/absmach/supermq/readers/api" - "github.com/absmach/supermq/readers/timescale" "github.com/caarlos0/env/v11" "github.com/jmoiron/sqlx" "golang.org/x/sync/errgroup" diff --git a/cmd/timescale-writer/main.go b/cmd/timescale-writer/main.go index 394abca9f..62fe2ae41 100644 --- a/cmd/timescale-writer/main.go +++ b/cmd/timescale-writer/main.go @@ -13,11 +13,11 @@ import ( "os" chclient "github.com/absmach/callhome/pkg/client" + consumertracing "github.com/absmach/magistrala/consumers/tracing" + httpapi "github.com/absmach/magistrala/consumers/writers/api" + "github.com/absmach/magistrala/consumers/writers/timescale" "github.com/absmach/supermq" "github.com/absmach/supermq/consumers" - consumertracing "github.com/absmach/supermq/consumers/tracing" - httpapi "github.com/absmach/supermq/consumers/writers/api" - "github.com/absmach/supermq/consumers/writers/timescale" smqlog "github.com/absmach/supermq/logger" jaegerclient "github.com/absmach/supermq/pkg/jaeger" "github.com/absmach/supermq/pkg/messaging/brokers" diff --git a/consumers/notifiers/api/endpoint_test.go b/consumers/notifiers/api/endpoint_test.go index f91635b14..ed248b208 100644 --- a/consumers/notifiers/api/endpoint_test.go +++ b/consumers/notifiers/api/endpoint_test.go @@ -13,11 +13,11 @@ import ( "strings" "testing" + "github.com/absmach/magistrala/consumers/notifiers/api" + "github.com/absmach/magistrala/consumers/notifiers/mocks" "github.com/absmach/magistrala/internal/testsutil" apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/consumers/notifiers" - "github.com/absmach/supermq/consumers/notifiers/api" - "github.com/absmach/supermq/consumers/notifiers/mocks" smqlog "github.com/absmach/supermq/logger" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/absmach/supermq/pkg/uuid" diff --git a/consumers/notifiers/notifier.go b/consumers/notifiers/notifier.go deleted file mode 100644 index 0337176d4..000000000 --- a/consumers/notifiers/notifier.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -package notifiers - -import ( - "errors" - - "github.com/absmach/supermq/pkg/messaging" -) - -// ErrNotify wraps sending notification errors. -var ErrNotify = errors.New("error sending notification") - -// Notifier represents an API for sending notification. -// -//go:generate mockery --name Notifier --output=./mocks --filename notifier.go --quiet --note "Copyright (c) Abstract Machines" -type Notifier interface { - // Notify method is used to send notification for the - // received message to the provided list of receivers. - Notify(from string, to []string, msg *messaging.Message) error -} diff --git a/consumers/notifiers/postgres/setup_test.go b/consumers/notifiers/postgres/setup_test.go index 523bf92de..da06187db 100644 --- a/consumers/notifiers/postgres/setup_test.go +++ b/consumers/notifiers/postgres/setup_test.go @@ -11,7 +11,7 @@ import ( "os" "testing" - "github.com/absmach/supermq/consumers/notifiers/postgres" + "github.com/absmach/magistrala/consumers/notifiers/postgres" pgclient "github.com/absmach/supermq/pkg/postgres" "github.com/absmach/supermq/pkg/ulid" _ "github.com/jackc/pgx/v5/stdlib" // required for SQL access diff --git a/consumers/notifiers/postgres/subscriptions_test.go b/consumers/notifiers/postgres/subscriptions_test.go index 3eac5badc..d974fbfb9 100644 --- a/consumers/notifiers/postgres/subscriptions_test.go +++ b/consumers/notifiers/postgres/subscriptions_test.go @@ -8,8 +8,8 @@ import ( "fmt" "testing" + "github.com/absmach/magistrala/consumers/notifiers/postgres" "github.com/absmach/supermq/consumers/notifiers" - "github.com/absmach/supermq/consumers/notifiers/postgres" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" "github.com/stretchr/testify/assert" diff --git a/consumers/notifiers/service.go b/consumers/notifiers/service.go index 02d02503f..0b864a1c6 100644 --- a/consumers/notifiers/service.go +++ b/consumers/notifiers/service.go @@ -9,6 +9,7 @@ import ( "github.com/absmach/supermq" "github.com/absmach/supermq/consumers" + notif "github.com/absmach/supermq/consumers/notifiers" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" @@ -46,13 +47,13 @@ type notifierService struct { authn smqauthn.Authentication subs SubscriptionsRepository idp supermq.IDProvider - notifier Notifier + notifier notif.Notifier errCh chan error from string } // New instantiates the subscriptions service implementation. -func New(authn smqauthn.Authentication, subs SubscriptionsRepository, idp supermq.IDProvider, notifier Notifier, from string) Service { +func New(authn smqauthn.Authentication, subs SubscriptionsRepository, idp supermq.IDProvider, notifier notif.Notifier, from string) Service { return ¬ifierService{ authn: authn, subs: subs, @@ -131,7 +132,7 @@ func (ns *notifierService) ConsumeBlocking(ctx context.Context, message interfac if len(to) > 0 { err := ns.notifier.Notify(ns.from, to, msg) if err != nil { - return errors.Wrap(ErrNotify, err) + return errors.Wrap(notif.ErrNotify, err) } } @@ -165,7 +166,7 @@ func (ns *notifierService) ConsumeAsync(ctx context.Context, message interface{} } if len(to) > 0 { if err := ns.notifier.Notify(ns.from, to, msg); err != nil { - ns.errCh <- errors.Wrap(ErrNotify, err) + ns.errCh <- errors.Wrap(notif.ErrNotify, err) } } } diff --git a/consumers/notifiers/service_test.go b/consumers/notifiers/service_test.go index 234359681..ee61a64cb 100644 --- a/consumers/notifiers/service_test.go +++ b/consumers/notifiers/service_test.go @@ -8,9 +8,9 @@ import ( "fmt" "testing" + "github.com/absmach/magistrala/consumers/notifiers/mocks" "github.com/absmach/magistrala/internal/testsutil" "github.com/absmach/supermq/consumers/notifiers" - "github.com/absmach/supermq/consumers/notifiers/mocks" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/consumers/writers/postgres/consumer_test.go b/consumers/writers/postgres/consumer_test.go index 1f1b4ab4e..2d3889a44 100644 --- a/consumers/writers/postgres/consumer_test.go +++ b/consumers/writers/postgres/consumer_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/absmach/supermq/consumers/writers/postgres" + "github.com/absmach/magistrala/consumers/writers/postgres" "github.com/absmach/supermq/pkg/transformers/json" "github.com/absmach/supermq/pkg/transformers/senml" "github.com/gofrs/uuid/v5" diff --git a/consumers/writers/postgres/setup_test.go b/consumers/writers/postgres/setup_test.go index ecb2ab34c..aa6014b1c 100644 --- a/consumers/writers/postgres/setup_test.go +++ b/consumers/writers/postgres/setup_test.go @@ -11,7 +11,7 @@ import ( "os" "testing" - "github.com/absmach/supermq/consumers/writers/postgres" + "github.com/absmach/magistrala/consumers/writers/postgres" pgclient "github.com/absmach/supermq/pkg/postgres" "github.com/jmoiron/sqlx" "github.com/ory/dockertest/v3" diff --git a/consumers/writers/timescale/consumer_test.go b/consumers/writers/timescale/consumer_test.go index 1704d1b68..837a94a36 100644 --- a/consumers/writers/timescale/consumer_test.go +++ b/consumers/writers/timescale/consumer_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/absmach/supermq/consumers/writers/timescale" + "github.com/absmach/magistrala/consumers/writers/timescale" "github.com/absmach/supermq/pkg/transformers/json" "github.com/absmach/supermq/pkg/transformers/senml" "github.com/gofrs/uuid/v5" diff --git a/consumers/writers/timescale/setup_test.go b/consumers/writers/timescale/setup_test.go index aacf15c05..97c06c5dd 100644 --- a/consumers/writers/timescale/setup_test.go +++ b/consumers/writers/timescale/setup_test.go @@ -11,7 +11,7 @@ import ( "os" "testing" - "github.com/absmach/supermq/consumers/writers/timescale" + "github.com/absmach/magistrala/consumers/writers/timescale" pgclient "github.com/absmach/supermq/pkg/postgres" "github.com/jmoiron/sqlx" "github.com/ory/dockertest/v3" diff --git a/readers/postgres/messages_test.go b/readers/postgres/messages_test.go index e0a3831a0..43ca0ee9e 100644 --- a/readers/postgres/messages_test.go +++ b/readers/postgres/messages_test.go @@ -9,12 +9,12 @@ import ( "testing" "time" + pwriter "github.com/absmach/magistrala/consumers/writers/postgres" "github.com/absmach/magistrala/internal/testsutil" - pwriter "github.com/absmach/supermq/consumers/writers/postgres" + preader "github.com/absmach/magistrala/readers/postgres" "github.com/absmach/supermq/pkg/transformers/json" "github.com/absmach/supermq/pkg/transformers/senml" "github.com/absmach/supermq/readers" - preader "github.com/absmach/supermq/readers/postgres" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/readers/postgres/setup_test.go b/readers/postgres/setup_test.go index 4636f6a28..4e3bb0e41 100644 --- a/readers/postgres/setup_test.go +++ b/readers/postgres/setup_test.go @@ -11,7 +11,7 @@ import ( "os" "testing" - "github.com/absmach/supermq/readers/postgres" + "github.com/absmach/magistrala/readers/postgres" _ "github.com/jackc/pgx/v5/stdlib" // required for SQL access "github.com/jmoiron/sqlx" "github.com/ory/dockertest/v3" diff --git a/readers/timescale/messages_test.go b/readers/timescale/messages_test.go index 23b2ba294..92c037d4b 100644 --- a/readers/timescale/messages_test.go +++ b/readers/timescale/messages_test.go @@ -9,12 +9,12 @@ import ( "testing" "time" + twriter "github.com/absmach/magistrala/consumers/writers/timescale" "github.com/absmach/magistrala/internal/testsutil" - twriter "github.com/absmach/supermq/consumers/writers/timescale" + treader "github.com/absmach/magistrala/readers/timescale" "github.com/absmach/supermq/pkg/transformers/json" "github.com/absmach/supermq/pkg/transformers/senml" "github.com/absmach/supermq/readers" - treader "github.com/absmach/supermq/readers/timescale" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/readers/timescale/setup_test.go b/readers/timescale/setup_test.go index 519a6e717..b4d14da50 100644 --- a/readers/timescale/setup_test.go +++ b/readers/timescale/setup_test.go @@ -11,7 +11,7 @@ import ( "os" "testing" - "github.com/absmach/supermq/readers/timescale" + "github.com/absmach/magistrala/readers/timescale" _ "github.com/jackc/pgx/v5/stdlib" // required for SQL access "github.com/jmoiron/sqlx" "github.com/ory/dockertest/v3" diff --git a/scripts/ci.sh b/scripts/ci.sh index 48097ea4e..6944ea2aa 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -49,7 +49,7 @@ setup_protoc() { } setup_mg() { - echo "Setting up Magistrala..." + echo "Setting up SuperMQ..." for p in $(ls *.pb.go); do mv $p $p.tmp done @@ -70,15 +70,15 @@ setup_mg() { fi done echo "Compile check for rabbitmq..." - MG_MESSAGE_BROKER_TYPE=rabbitmq make http + SMQ_MESSAGE_BROKER_TYPE=rabbitmq make http echo "Compile check for redis..." - MG_ES_TYPE=redis make http + SMQ_ES_TYPE=redis make http make -j$NPROC } setup_lint() { # binary will be $(go env GOBIN)/golangci-lint - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOBIN) $GOLANGCI_LINT_VERSION + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/main/install.sh | sh -s -- -b $(go env GOBIN) $GOLANGCI_LINT_VERSION } setup() { @@ -105,7 +105,7 @@ run_test() { } push() { - if test -n "$BRANCH_NAME" && test "$BRANCH_NAME" = "master"; then + if test -n "$BRANCH_NAME" && test "$BRANCH_NAME" = "main"; then echo "Pushing Docker images..." make -j$NPROC latest fi diff --git a/scripts/csv/channels.csv b/scripts/csv/channels.csv new file mode 100644 index 000000000..9b367f7c2 --- /dev/null +++ b/scripts/csv/channels.csv @@ -0,0 +1,3 @@ +channel_1 +channel_2 +channel_3 diff --git a/scripts/csv/clients.csv b/scripts/csv/clients.csv new file mode 100644 index 000000000..b5bc8e7fb --- /dev/null +++ b/scripts/csv/clients.csv @@ -0,0 +1,10 @@ +client_1 +client_2 +client_3 +client_4 +client_5 +client_6 +client_7 +client_8 +client_9 +client_10 diff --git a/scripts/provision-dev.sh b/scripts/provision-dev.sh index 49b508088..437d1a6e5 100755 --- a/scripts/provision-dev.sh +++ b/scripts/provision-dev.sh @@ -5,9 +5,9 @@ # ### -# Provisions example user, thing and channel on a clean Magistrala installation. +# Provisions example user, client and channel on a clean SuperMQ installation. # -# Expects a running Magistrala installation. +# Expects a running SuperMQ installation. # # ### @@ -25,26 +25,26 @@ CHANNEL=$4 #provision user: printf "Provisoning user with email $EMAIL and password $PASSWORD \n" -curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/users -d '{"credentials": {"identity": "'"$EMAIL"'","secret": "'"$PASSWORD"'"}, "status": "enabled", "role": "admin" }' +curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/users -d '{"credentials": {"identity": "'"$EMAIL"'","secret": "'"$PASSWORD"'"}, "status": "enabled", "role": "admin" }' #get jwt token -JWTTOKEN=$(curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/users/tokens/issue -d '{"identity":"'"$EMAIL"'", "secret":"'"$PASSWORD"'"}' | grep -oP '"access_token":"\K[^"]+' ) +JWTTOKEN=$(curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/users/tokens/issue -d '{"identity":"'"$EMAIL"'", "secret":"'"$PASSWORD"'"}' | grep -oP '"access_token":"\K[^"]+' ) printf "JWT TOKEN for user is $JWTTOKEN \n" -#provision thing -printf "Provisioning thing with name $DEVICE \n" -DEVICEID=$(curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/things -d '{"name":"'"$DEVICE"'", "status": "enabled"}' | grep -oP '"id":"\K[^"]+' ) -curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/things/$DEVICEID +#provision client +printf "Provisioning client with name $DEVICE \n" +DEVICEID=$(curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/clients -d '{"name":"'"$DEVICE"'", "status": "enabled"}' | grep -oP '"id":"\K[^"]+' ) +curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/clients/$DEVICEID -#get thing token -DEVICETOKEN=$(curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -H "Authorization: Bearer $JWTTOKEN" https://localhost/things/$DEVICEID | grep -oP '"secret":"\K[^"]+' ) +#get client token +DEVICETOKEN=$(curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -H "Authorization: Bearer $JWTTOKEN" https://localhost/clients/$DEVICEID | grep -oP '"secret":"\K[^"]+' ) printf "Device token is $DEVICETOKEN \n" #provision channel printf "Provisioning channel with name $CHANNEL \n" -CHANNELID=$(curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels -d '{"name":"'"$CHANNEL"'", "status": "enabled"}' | grep -oP '"id":"\K[^"]+' ) -curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels/$CHANNELID +CHANNELID=$(curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels -d '{"name":"'"$CHANNEL"'", "status": "enabled"}' | grep -oP '"id":"\K[^"]+' ) +curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels/$CHANNELID -#connect thing to channel -printf "Connecting thing of id $DEVICEID to channel of id $CHANNELID \n" -curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X PUT -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels/$CHANNELID/things/$DEVICEID +#connect client to channel +printf "Connecting client of id $DEVICEID to channel of id $CHANNELID \n" +curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X PUT -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels/$CHANNELID/clients/$DEVICEID diff --git a/scripts/run.sh b/scripts/run.sh index 0cdd52ca6..635f7d8cf 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 ### -# Runs all Magistrala microservices (must be previously built and installed). +# Runs all SuperMQ microservices (must be previously built and installed). # # Expects that PostgreSQL and needed messaging DB are alredy running. # Additionally, MQTT microservice demands that Redis is up and running. @@ -12,9 +12,9 @@ BUILD_DIR=../build -# Kill all magistrala-* stuff +# Kill all supermq-* stuff function cleanup { - pkill magistrala + pkill supermq pkill nats } @@ -38,32 +38,32 @@ done ### # Users ### -MG_USERS_LOG_LEVEL=info MG_USERS_HTTP_PORT=9002 MG_USERS_GRPC_PORT=7001 MG_USERS_ADMIN_EMAIL=admin@magistrala.com MG_USERS_ADMIN_PASSWORD=12345678 MG_USERS_ADMIN_USERNAME=admin MG_EMAIL_TEMPLATE=../docker/templates/users.tmpl $BUILD_DIR/magistrala-users & +SMQ_USERS_LOG_LEVEL=info SMQ_USERS_HTTP_PORT=9002 SMQ_USERS_GRPC_PORT=7001 SMQ_USERS_ADMIN_EMAIL=admin@supermq.com SMQ_USERS_ADMIN_PASSWORD=12345678 SMQ_USERS_ADMIN_USERNAME=admin SMQ_EMAIL_TEMPLATE=../docker/templates/users.tmpl $BUILD_DIR/supermq-users & ### -# Things +# Clients ### -MG_THINGS_LOG_LEVEL=info MG_THINGS_HTTP_PORT=9000 MG_THINGS_AUTH_GRPC_PORT=7000 MG_THINGS_AUTH_HTTP_PORT=9002 $BUILD_DIR/magistrala-things & +SMQ_CLIENTS_LOG_LEVEL=info SMQ_CLIENTS_HTTP_PORT=9000 SMQ_CLIENTS_AUTH_GRPC_PORT=7000 SMQ_CLIENTS_AUTH_HTTP_PORT=9002 $BUILD_DIR/supermq-clients & ### # HTTP ### -MG_HTTP_ADAPTER_LOG_LEVEL=info MG_HTTP_ADAPTER_PORT=8008 MG_THINGS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/magistrala-http & +SMQ_HTTP_ADAPTER_LOG_LEVEL=info SMQ_HTTP_ADAPTER_PORT=8008 SMQ_CLIENTS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/supermq-http & ### # WS ### -MG_WS_ADAPTER_LOG_LEVEL=info MG_WS_ADAPTER_HTTP_PORT=8190 MG_THINGS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/magistrala-ws & +SMQ_WS_ADAPTER_LOG_LEVEL=info SMQ_WS_ADAPTER_HTTP_PORT=8190 SMQ_CLIENTS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/supermq-ws & ### # MQTT ### -MG_MQTT_ADAPTER_LOG_LEVEL=info MG_THINGS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/magistrala-mqtt & +SMQ_MQTT_ADAPTER_LOG_LEVEL=info SMQ_CLIENTS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/supermq-mqtt & ### # CoAP ### -MG_COAP_ADAPTER_LOG_LEVEL=info MG_COAP_ADAPTER_PORT=5683 MG_THINGS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/magistrala-coap & +SMQ_COAP_ADAPTER_LOG_LEVEL=info SMQ_COAP_ADAPTER_PORT=5683 SMQ_CLIENTS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/supermq-coap & trap cleanup EXIT