Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
Signed-off-by: ianmuchyri <[email protected]>
  • Loading branch information
ianmuchyri committed Jan 27, 2025
1 parent 394223a commit 7002067
Show file tree
Hide file tree
Showing 31 changed files with 191 additions and 131 deletions.
2 changes: 1 addition & 1 deletion cmd/cassandra-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

chclient "github.com/absmach/callhome/pkg/client"
"github.com/absmach/magistrala"
"github.com/absmach/magistrala/consumers"
consumertracing "github.com/absmach/magistrala/consumers/tracing"
"github.com/absmach/magistrala/consumers/writers/api"
mglog "github.com/absmach/magistrala/logger"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/absmach/magistrala/pkg/uuid"
"github.com/absmach/mg-contrib/consumers/writers/cassandra"
cassandraclient "github.com/absmach/mg-contrib/pkg/clients/cassandra"
"github.com/absmach/supermq/consumers"
"github.com/caarlos0/env/v10"
"github.com/gocql/gocql"
"golang.org/x/sync/errgroup"
Expand Down
2 changes: 1 addition & 1 deletion cmd/influxdb-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

chclient "github.com/absmach/callhome/pkg/client"
"github.com/absmach/magistrala"
"github.com/absmach/magistrala/consumers"
consumertracing "github.com/absmach/magistrala/consumers/tracing"
"github.com/absmach/magistrala/consumers/writers/api"
mglog "github.com/absmach/magistrala/logger"
Expand All @@ -26,6 +25,7 @@ import (
"github.com/absmach/magistrala/pkg/uuid"
"github.com/absmach/mg-contrib/consumers/writers/influxdb"
influxdbclient "github.com/absmach/mg-contrib/pkg/clients/influxdb"
"github.com/absmach/supermq/consumers"
"github.com/caarlos0/env/v10"
"golang.org/x/sync/errgroup"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mongodb-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

chclient "github.com/absmach/callhome/pkg/client"
"github.com/absmach/magistrala"
"github.com/absmach/magistrala/consumers"
consumertracing "github.com/absmach/magistrala/consumers/tracing"
"github.com/absmach/magistrala/consumers/writers/api"
mglog "github.com/absmach/magistrala/logger"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/absmach/magistrala/pkg/uuid"
"github.com/absmach/mg-contrib/consumers/writers/mongodb"
mongoclient "github.com/absmach/mg-contrib/pkg/clients/mongo"
"github.com/absmach/supermq/consumers"
"github.com/caarlos0/env/v10"
"go.mongodb.org/mongo-driver/mongo"
"golang.org/x/sync/errgroup"
Expand Down
49 changes: 25 additions & 24 deletions cmd/smpp-notifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,26 @@ import (
"os"

chclient "github.com/absmach/callhome/pkg/client"
"github.com/absmach/magistrala"
"github.com/absmach/magistrala/consumers"
"github.com/absmach/magistrala/consumers/notifiers"
"github.com/absmach/magistrala/consumers/notifiers/api"
notifierpg "github.com/absmach/magistrala/consumers/notifiers/postgres"
"github.com/absmach/magistrala/consumers/notifiers/tracing"
mglog "github.com/absmach/magistrala/logger"
"github.com/absmach/magistrala/pkg/auth"
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
"github.com/absmach/magistrala/pkg/messaging/brokers"
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
pgclient "github.com/absmach/magistrala/pkg/postgres"
"github.com/absmach/magistrala/pkg/prometheus"
"github.com/absmach/magistrala/pkg/server"
httpserver "github.com/absmach/magistrala/pkg/server/http"
"github.com/absmach/magistrala/pkg/ulid"
"github.com/absmach/magistrala/pkg/uuid"
mgsmpp "github.com/absmach/mg-contrib/consumers/notifiers/smpp"
"github.com/absmach/supermq"
"github.com/absmach/supermq/consumers"
smqlog "github.com/absmach/supermq/logger"
smqauthn "github.com/absmach/supermq/pkg/authn"
authsvcAuthn "github.com/absmach/supermq/pkg/authn/authsvc"
"github.com/absmach/supermq/pkg/grpcclient"
jaegerclient "github.com/absmach/supermq/pkg/jaeger"
"github.com/absmach/supermq/pkg/messaging/brokers"
brokerstracing "github.com/absmach/supermq/pkg/messaging/brokers/tracing"
pgclient "github.com/absmach/supermq/pkg/postgres"
"github.com/absmach/supermq/pkg/server"
httpserver "github.com/absmach/supermq/pkg/server/http"
"github.com/absmach/supermq/pkg/ulid"
"github.com/absmach/supermq/pkg/uuid"
"github.com/caarlos0/env/v10"
"github.com/jmoiron/sqlx"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -66,13 +68,13 @@ func main() {
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}

logger, err := mglog.New(os.Stdout, cfg.LogLevel)
logger, err := smqlog.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf("failed to init logger: %s", err.Error())
}

var exitCode int
defer mglog.ExitWithError(&exitCode)
defer smqlog.ExitWithError(&exitCode)

if cfg.InstanceID == "" {
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
Expand Down Expand Up @@ -132,23 +134,22 @@ func main() {
defer pubSub.Close()
pubSub = brokerstracing.NewPubSub(httpServerConfig, tracer, pubSub)

authConfig := auth.Config{}
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
grpcCfg := grpcclient.Config{}
if err := env.ParseWithOptions(&grpcCfg, env.Options{Prefix: envPrefixAuth}); err != nil {
logger.Error(fmt.Sprintf("failed to load auth gRPC client configuration : %s", err))
exitCode = 1
return
}

authClient, authHandler, err := auth.Setup(ctx, authConfig)
authn, authnClient, err := authsvcAuthn.NewAuthentication(ctx, grpcCfg)
if err != nil {
logger.Error(err.Error())
exitCode = 1
return
}
defer authHandler.Close()
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
logger.Info("AuthN successfully connected to auth gRPC server " + authnClient.Secure())
defer authnClient.Close()

svc := newService(db, tracer, authClient, cfg, smppConfig, logger)
svc := newService(db, tracer, authn, cfg, smppConfig, logger)
if err = consumers.Start(ctx, svcName, pubSub, svc, cfg.ConfigPath, logger); err != nil {
logger.Error(fmt.Sprintf("failed to create Postgres writer: %s", err))
exitCode = 1
Expand All @@ -158,7 +159,7 @@ func main() {
hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, cfg.InstanceID), logger)

if cfg.SendTelemetry {
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
chc := chclient.New(svcName, supermq.Version, logger, cancel)
go chc.CallHome(ctx)
}

Expand All @@ -175,7 +176,7 @@ func main() {
}
}

func newService(db *sqlx.DB, tracer trace.Tracer, authClient magistrala.AuthServiceClient, c config, sc mgsmpp.Config, logger *slog.Logger) notifiers.Service {
func newService(db *sqlx.DB, tracer trace.Tracer, authClient smqauthn.Authentication, c config, sc mgsmpp.Config, logger *slog.Logger) notifiers.Service {
database := notifierpg.NewDatabase(db, tracer)
repo := tracing.New(tracer, notifierpg.New(database))
idp := ulid.New()
Expand Down
52 changes: 26 additions & 26 deletions cmd/smtp-notifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ import (
"os"

chclient "github.com/absmach/callhome/pkg/client"
"github.com/absmach/magistrala"
"github.com/absmach/magistrala/consumers"
"github.com/absmach/magistrala/consumers/notifiers"
"github.com/absmach/magistrala/consumers/notifiers/api"
notifierpg "github.com/absmach/magistrala/consumers/notifiers/postgres"
"github.com/absmach/magistrala/consumers/notifiers/tracing"
mglog "github.com/absmach/magistrala/logger"
"github.com/absmach/magistrala/pkg/auth"
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
"github.com/absmach/magistrala/pkg/messaging/brokers"
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
pgclient "github.com/absmach/magistrala/pkg/postgres"
"github.com/absmach/magistrala/pkg/prometheus"
"github.com/absmach/magistrala/pkg/server"
httpserver "github.com/absmach/magistrala/pkg/server/http"
"github.com/absmach/magistrala/pkg/ulid"
"github.com/absmach/magistrala/pkg/uuid"
"github.com/absmach/mg-contrib/consumers/notifiers/smtp"
email "github.com/absmach/mg-contrib/pkg/email"
"github.com/caarlos0/env/v10"
"github.com/absmach/supermq"
"github.com/absmach/supermq/consumers"
smqlog "github.com/absmach/supermq/logger"
smqauthn "github.com/absmach/supermq/pkg/authn"
authsvcAuthn "github.com/absmach/supermq/pkg/authn/authsvc"
"github.com/absmach/supermq/pkg/grpcclient"
jaegerclient "github.com/absmach/supermq/pkg/jaeger"
"github.com/absmach/supermq/pkg/messaging/brokers"
brokerstracing "github.com/absmach/supermq/pkg/messaging/brokers/tracing"
pgclient "github.com/absmach/supermq/pkg/postgres"
"github.com/absmach/supermq/pkg/server"
httpserver "github.com/absmach/supermq/pkg/server/http"
"github.com/absmach/supermq/pkg/ulid"
"github.com/absmach/supermq/pkg/uuid"
"github.com/caarlos0/env/v11"
"github.com/jmoiron/sqlx"
"go.opentelemetry.io/otel/trace"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -67,13 +69,13 @@ func main() {
log.Fatalf("failed to load %s configuration : %s", svcName, err)
}

logger, err := mglog.New(os.Stdout, cfg.LogLevel)
logger, err := smqlog.New(os.Stdout, cfg.LogLevel)
if err != nil {
log.Fatalf("failed to init logger: %s", err.Error())
}

var exitCode int
defer mglog.ExitWithError(&exitCode)
defer smqlog.ExitWithError(&exitCode)

if cfg.InstanceID == "" {
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
Expand Down Expand Up @@ -133,24 +135,22 @@ func main() {
defer pubSub.Close()
pubSub = brokerstracing.NewPubSub(httpServerConfig, tracer, pubSub)

authConfig := auth.Config{}
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
grpcCfg := grpcclient.Config{}
if err := env.ParseWithOptions(&grpcCfg, env.Options{Prefix: envPrefixAuth}); err != nil {
logger.Error(fmt.Sprintf("failed to load auth gRPC client configuration : %s", err))
exitCode = 1
return
}

authClient, authHandler, err := auth.Setup(ctx, authConfig)
authn, authnClient, err := authsvcAuthn.NewAuthentication(ctx, grpcCfg)
if err != nil {
logger.Error(err.Error())
exitCode = 1
return
}
defer authHandler.Close()

logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
logger.Info("AuthN successfully connected to auth gRPC server " + authnClient.Secure())
defer authnClient.Close()

svc, err := newService(db, tracer, authClient, cfg, ec, logger)
svc, err := newService(db, tracer, authn, cfg, ec, logger)
if err != nil {
logger.Error(err.Error())
exitCode = 1
Expand All @@ -166,7 +166,7 @@ func main() {
hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, cfg.InstanceID), logger)

if cfg.SendTelemetry {
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
chc := chclient.New(svcName, supermq.Version, logger, cancel)
go chc.CallHome(ctx)
}

Expand All @@ -183,7 +183,7 @@ func main() {
}
}

func newService(db *sqlx.DB, tracer trace.Tracer, authClient magistrala.AuthServiceClient, c config, ec email.Config, logger *slog.Logger) (notifiers.Service, error) {
func newService(db *sqlx.DB, tracer trace.Tracer, authClient smqauthn.Authentication, c config, ec email.Config, logger *slog.Logger) (notifiers.Service, error) {
database := notifierpg.NewDatabase(db, tracer)
repo := tracing.New(tracer, notifierpg.New(database))
idp := ulid.New()
Expand Down
12 changes: 6 additions & 6 deletions consumers/notifiers/smpp/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ package smpp
import (
"time"

"github.com/absmach/magistrala/consumers/notifiers"
"github.com/absmach/magistrala/pkg/messaging"
"github.com/absmach/magistrala/pkg/transformers"
"github.com/absmach/magistrala/pkg/transformers/json"
"github.com/absmach/supermq/consumers"
"github.com/absmach/supermq/pkg/messaging"
"github.com/absmach/supermq/pkg/transformers"
"github.com/absmach/supermq/pkg/transformers/json"
"github.com/fiorix/go-smpp/smpp"
"github.com/fiorix/go-smpp/smpp/pdu/pdufield"
"github.com/fiorix/go-smpp/smpp/pdu/pdutext"
)

var _ notifiers.Notifier = (*notifier)(nil)
var _ consumers.Notifier = (*notifier)(nil)

type notifier struct {
transmitter *smpp.Transmitter
Expand All @@ -27,7 +27,7 @@ type notifier struct {
}

// New instantiates SMTP message notifier.
func New(cfg Config) notifiers.Notifier {
func New(cfg Config) consumers.Notifier {
t := &smpp.Transmitter{
Addr: cfg.Address,
User: cfg.Username,
Expand Down
8 changes: 4 additions & 4 deletions consumers/notifiers/smtp/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ package smtp
import (
"fmt"

"github.com/absmach/magistrala/consumers/notifiers"
"github.com/absmach/magistrala/pkg/messaging"
"github.com/absmach/mg-contrib/pkg/email"
"github.com/absmach/supermq/consumers"
"github.com/absmach/supermq/pkg/messaging"
)

const (
footer = "Sent by Magistrala SMTP Notification"
contentTemplate = "A publisher with an id %s sent the message over %s with the following values \n %s"
)

var _ notifiers.Notifier = (*notifier)(nil)
var _ consumers.Notifier = (*notifier)(nil)

type notifier struct {
agent *email.Agent
}

// New instantiates SMTP message notifier.
func New(agent *email.Agent) notifiers.Notifier {
func New(agent *email.Agent) consumers.Notifier {
return &notifier{agent: agent}
}

Expand Down
6 changes: 3 additions & 3 deletions consumers/tracing/consumers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"context"
"fmt"

"github.com/absmach/magistrala/consumers"
"github.com/absmach/magistrala/pkg/server"
mgjson "github.com/absmach/magistrala/pkg/transformers/json"
"github.com/absmach/magistrala/pkg/transformers/senml"
"github.com/absmach/supermq/consumers"
mgjson "github.com/absmach/supermq/pkg/transformers/json"
"github.com/absmach/supermq/pkg/transformers/senml"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
Expand Down
6 changes: 3 additions & 3 deletions consumers/writers/cassandra/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"encoding/json"
"fmt"

"github.com/absmach/magistrala/consumers"
"github.com/absmach/magistrala/pkg/errors"
mgjson "github.com/absmach/magistrala/pkg/transformers/json"
"github.com/absmach/magistrala/pkg/transformers/senml"
"github.com/absmach/supermq/consumers"
mgjson "github.com/absmach/supermq/pkg/transformers/json"
"github.com/absmach/supermq/pkg/transformers/senml"
"github.com/gocql/gocql"
)

Expand Down
4 changes: 2 additions & 2 deletions consumers/writers/cassandra/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"testing"
"time"

"github.com/absmach/magistrala/pkg/transformers/json"
"github.com/absmach/magistrala/pkg/transformers/senml"
"github.com/absmach/mg-contrib/consumers/writers/cassandra"
casclient "github.com/absmach/mg-contrib/pkg/clients/cassandra"
"github.com/absmach/supermq/pkg/transformers/json"
"github.com/absmach/supermq/pkg/transformers/senml"
"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
6 changes: 3 additions & 3 deletions consumers/writers/influxdb/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"math"
"time"

"github.com/absmach/magistrala/consumers"
"github.com/absmach/magistrala/pkg/errors"
"github.com/absmach/magistrala/pkg/transformers/json"
"github.com/absmach/magistrala/pkg/transformers/senml"
"github.com/absmach/supermq/consumers"
"github.com/absmach/supermq/pkg/transformers/json"
"github.com/absmach/supermq/pkg/transformers/senml"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/influxdata/influxdb-client-go/v2/api"
"github.com/influxdata/influxdb-client-go/v2/api/write"
Expand Down
4 changes: 2 additions & 2 deletions consumers/writers/influxdb/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (

mglog "github.com/absmach/magistrala/logger"
"github.com/absmach/magistrala/pkg/errors"
"github.com/absmach/magistrala/pkg/transformers/json"
"github.com/absmach/magistrala/pkg/transformers/senml"
"github.com/absmach/magistrala/pkg/uuid"
writer "github.com/absmach/mg-contrib/consumers/writers/influxdb"
"github.com/absmach/supermq/pkg/transformers/json"
"github.com/absmach/supermq/pkg/transformers/senml"
influxdata "github.com/influxdata/influxdb-client-go/v2"
"github.com/stretchr/testify/assert"
)
Expand Down
2 changes: 1 addition & 1 deletion consumers/writers/influxdb/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package influxdb

import (
"github.com/absmach/magistrala/pkg/transformers/senml"
"github.com/absmach/supermq/pkg/transformers/senml"
)

type fields map[string]interface{}
Expand Down
Loading

0 comments on commit 7002067

Please sign in to comment.