mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
NOISSUE - Change import name aliases (#1868)
* Change import name aliases Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Change import name aliases Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Change import aliases Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Remove unused aliases Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> Fix aliases Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> FIx errors Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> Fix error Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> FIx merge Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> FIx merge Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> FIx merge Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix import alias Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix errors Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix linter Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix linter Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix import Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Add linter to CI pipeline Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Changes Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Remove unused aliases Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix merge issues Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix gci Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix gci Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix gci Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Add gofumpt Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Remove multiple gofupmt in CI Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Remove unnecessary changes Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix linter Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> * Fix CI pipeline Signed-off-by: WashingtonKK <washingtonkigan@gmail.com> --------- Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
91e3873a13
commit
e2992cbede
@@ -120,7 +120,6 @@ func newConfig(channels []bootstrap.Channel) bootstrap.Config {
|
||||
|
||||
func (tr testRequest) make() (*http.Response, error) {
|
||||
req, err := http.NewRequest(tr.method, tr.url, tr.body)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -536,6 +535,7 @@ func TestUpdate(t *testing.T) {
|
||||
assert.Equal(t, tc.status, res.StatusCode, fmt.Sprintf("%s: expected status code %d got %d", tc.desc, tc.status, res.StatusCode))
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateCert(t *testing.T) {
|
||||
auth := mocks.NewAuthClient(map[string]string{validToken: email})
|
||||
|
||||
@@ -1012,7 +1012,8 @@ func TestRemove(t *testing.T) {
|
||||
id: saved.ThingID,
|
||||
auth: invalidToken,
|
||||
status: http.StatusUnauthorized,
|
||||
}, {
|
||||
},
|
||||
{
|
||||
desc: "remove with an empty token",
|
||||
id: saved.ThingID,
|
||||
auth: "",
|
||||
|
||||
@@ -75,7 +75,6 @@ func (crm *configRepositoryMock) RetrieveByID(_ context.Context, token, id strin
|
||||
}
|
||||
|
||||
return c, nil
|
||||
|
||||
}
|
||||
|
||||
func (crm *configRepositoryMock) RetrieveAll(_ context.Context, token string, filter bootstrap.Filter, offset, limit uint64) bootstrap.ConfigsPage {
|
||||
|
||||
@@ -62,7 +62,6 @@ func (svc *mainfluxThings) ViewClient(ctx context.Context, token, id string) (mf
|
||||
|
||||
if t, ok := svc.things[id]; ok && t.Owner == userID.GetId() {
|
||||
return t, nil
|
||||
|
||||
}
|
||||
|
||||
return mfclients.Client{}, errors.ErrNotFound
|
||||
|
||||
@@ -9,11 +9,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
bootstrapRepo "github.com/mainflux/mainflux/bootstrap/postgres"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/bootstrap/postgres"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -50,7 +49,7 @@ func TestMain(m *testing.M) {
|
||||
testLog.Error(fmt.Sprintf("Could not connect to docker: %s", err))
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{
|
||||
dbConfig := pgclient.Config{
|
||||
Host: "localhost",
|
||||
Port: port,
|
||||
User: "test",
|
||||
@@ -62,7 +61,7 @@ func TestMain(m *testing.M) {
|
||||
SSLRootCert: "",
|
||||
}
|
||||
|
||||
if db, err = pgClient.SetupDB(dbConfig, *bootstrapRepo.Migration()); err != nil {
|
||||
if db, err = pgclient.SetupDB(dbConfig, *postgres.Migration()); err != nil {
|
||||
testLog.Error(fmt.Sprintf("Could not setup test DB connection: %s", err))
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
var redisClient *redis.Client
|
||||
|
||||
@@ -15,13 +15,12 @@ import (
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/go-zoo/bone"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
|
||||
"github.com/mainflux/mainflux/bootstrap"
|
||||
"github.com/mainflux/mainflux/bootstrap/mocks"
|
||||
"github.com/mainflux/mainflux/bootstrap/redis/producer"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
mfclients "github.com/mainflux/mainflux/pkg/clients"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
mfgroups "github.com/mainflux/mainflux/pkg/groups"
|
||||
mfsdk "github.com/mainflux/mainflux/pkg/sdk/go"
|
||||
"github.com/mainflux/mainflux/things/clients"
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-zoo/bone"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/mainflux/mainflux/bootstrap"
|
||||
"github.com/mainflux/mainflux/bootstrap/mocks"
|
||||
|
||||
@@ -62,7 +62,6 @@ func (svc *mainfluxThings) ViewClient(ctx context.Context, token, id string) (mf
|
||||
|
||||
if t, ok := svc.things[id]; ok && t.Owner == userID.GetId() {
|
||||
return t, nil
|
||||
|
||||
}
|
||||
|
||||
return mfclients.Client{}, errors.ErrNotFound
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/mainflux/mainflux/certs/postgres"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -50,7 +50,7 @@ func TestMain(m *testing.M) {
|
||||
testLog.Error(fmt.Sprintf("Could not connect to docker: %s", err))
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{
|
||||
dbConfig := pgclient.Config{
|
||||
Host: "localhost",
|
||||
Port: port,
|
||||
User: "test",
|
||||
@@ -62,7 +62,7 @@ func TestMain(m *testing.M) {
|
||||
SSLRootCert: "",
|
||||
}
|
||||
|
||||
if db, err = pgClient.SetupDB(dbConfig, *postgres.Migration()); err != nil {
|
||||
if db, err = pgclient.SetupDB(dbConfig, *postgres.Migration()); err != nil {
|
||||
testLog.Error(fmt.Sprintf("Could not setup test DB connection: %s", err))
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,6 @@ func TestIssueCert(t *testing.T) {
|
||||
assert.True(t, strings.Contains(cert.Subject.CommonName, thingKey), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRevokeCert(t *testing.T) {
|
||||
@@ -177,7 +176,6 @@ func TestRevokeCert(t *testing.T) {
|
||||
_, err := svc.RevokeCert(context.Background(), tc.token, tc.thingID)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestListCerts(t *testing.T) {
|
||||
|
||||
@@ -125,7 +125,6 @@ var cmdBootstrap = []cobra.Command{
|
||||
return
|
||||
}
|
||||
logUsage(cmd.Use)
|
||||
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
+2
-2
@@ -41,7 +41,7 @@ type config struct {
|
||||
}
|
||||
|
||||
// Readable by all user groups but writeable by the user only.
|
||||
const filePermission = 0644
|
||||
const filePermission = 0o644
|
||||
|
||||
var (
|
||||
errReadFail = errors.New("failed to read config file")
|
||||
@@ -189,7 +189,7 @@ func setConfigValue(key string, value string) error {
|
||||
}
|
||||
}
|
||||
|
||||
var configKeyToField = map[string]interface{}{
|
||||
configKeyToField := map[string]interface{}{
|
||||
"things_url": &config.Remotes.ThingsURL,
|
||||
"users_url": &config.Remotes.UsersURL,
|
||||
"reader_url": &config.Remotes.ReaderURL,
|
||||
|
||||
+4
-4
@@ -35,7 +35,7 @@ var cmdPolicies = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
var policy = mfxsdk.Policy{
|
||||
policy := mfxsdk.Policy{
|
||||
Subject: args[1],
|
||||
Object: args[2],
|
||||
Actions: actions,
|
||||
@@ -76,7 +76,7 @@ var cmdPolicies = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
var policy = mfxsdk.Policy{
|
||||
policy := mfxsdk.Policy{
|
||||
Subject: args[1],
|
||||
Object: args[2],
|
||||
Actions: actions,
|
||||
@@ -150,7 +150,7 @@ var cmdPolicies = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
var policy = mfxsdk.Policy{
|
||||
policy := mfxsdk.Policy{
|
||||
Subject: args[1],
|
||||
Object: args[2],
|
||||
}
|
||||
@@ -183,7 +183,7 @@ var cmdPolicies = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
var areq = mfxsdk.AccessRequest{
|
||||
areq := mfxsdk.AccessRequest{
|
||||
Subject: args[1],
|
||||
Object: args[2],
|
||||
Action: args[3],
|
||||
|
||||
+4
-2
@@ -19,8 +19,10 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const jsonExt = ".json"
|
||||
const csvExt = ".csv"
|
||||
const (
|
||||
jsonExt = ".json"
|
||||
csvExt = ".csv"
|
||||
)
|
||||
|
||||
var cmdProvision = []cobra.Command{
|
||||
{
|
||||
|
||||
@@ -112,7 +112,6 @@ var cmdUsers = []cobra.Command{
|
||||
}
|
||||
|
||||
logJSON(token)
|
||||
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -134,7 +133,6 @@ var cmdUsers = []cobra.Command{
|
||||
}
|
||||
|
||||
logJSON(token)
|
||||
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
prettyjson "github.com/hokaccha/go-prettyjson"
|
||||
"github.com/hokaccha/go-prettyjson"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
+18
-18
@@ -16,15 +16,15 @@ import (
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/bootstrap"
|
||||
"github.com/mainflux/mainflux/bootstrap/api"
|
||||
bootstrapPg "github.com/mainflux/mainflux/bootstrap/postgres"
|
||||
rediscons "github.com/mainflux/mainflux/bootstrap/redis/consumer"
|
||||
redisprod "github.com/mainflux/mainflux/bootstrap/redis/producer"
|
||||
bootstrappg "github.com/mainflux/mainflux/bootstrap/postgres"
|
||||
"github.com/mainflux/mainflux/bootstrap/redis/consumer"
|
||||
"github.com/mainflux/mainflux/bootstrap/redis/producer"
|
||||
"github.com/mainflux/mainflux/bootstrap/tracing"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
redisClient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
"github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
redisclient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/postgres"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
@@ -82,11 +82,11 @@ func main() {
|
||||
}
|
||||
|
||||
// Create new postgres client
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
if err := dbConfig.LoadEnv(envPrefixDB); err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
db, err := pgClient.SetupWithConfig(envPrefixDB, *bootstrapPg.Migration(), dbConfig)
|
||||
db, err := pgclient.SetupWithConfig(envPrefixDB, *bootstrappg.Migration(), dbConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -95,7 +95,7 @@ func main() {
|
||||
defer db.Close()
|
||||
|
||||
// Create new redis client for bootstrap event store
|
||||
esClient, err := redisClient.Setup(envPrefixES)
|
||||
esClient, err := redisclient.Setup(envPrefixES)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup %s bootstrap event store redis client : %s", svcName, err))
|
||||
exitCode = 1
|
||||
@@ -104,7 +104,7 @@ func main() {
|
||||
defer esClient.Close()
|
||||
|
||||
// Create new auth grpc client api
|
||||
auth, authHandler, err := authClient.Setup(svcName)
|
||||
auth, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -113,7 +113,7 @@ func main() {
|
||||
defer authHandler.Close()
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaeger.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -151,7 +151,7 @@ func main() {
|
||||
})
|
||||
|
||||
// Subscribe to things event store
|
||||
thingsESClient, err := redisClient.Setup(envPrefixES)
|
||||
thingsESClient, err := redisclient.Setup(envPrefixES)
|
||||
if err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
@@ -164,10 +164,10 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, auth policies.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, esClient *redis.Client, cfg config, dbConfig pgClient.Config) bootstrap.Service {
|
||||
func newService(ctx context.Context, auth policies.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, esClient *redis.Client, cfg config, dbConfig pgclient.Config) bootstrap.Service {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
|
||||
repoConfig := bootstrapPg.NewConfigRepository(database, logger)
|
||||
repoConfig := bootstrappg.NewConfigRepository(database, logger)
|
||||
|
||||
config := mfsdk.Config{
|
||||
ThingsURL: cfg.ThingsURL,
|
||||
@@ -176,7 +176,7 @@ func newService(ctx context.Context, auth policies.AuthServiceClient, db *sqlx.D
|
||||
sdk := mfsdk.NewSDK(config)
|
||||
|
||||
svc := bootstrap.New(auth, repoConfig, sdk, []byte(cfg.EncKey))
|
||||
svc = redisprod.NewEventStoreMiddleware(ctx, svc, esClient)
|
||||
svc = producer.NewEventStoreMiddleware(ctx, svc, esClient)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics(svcName, "api")
|
||||
svc = api.MetricsMiddleware(svc, counter, latency)
|
||||
@@ -185,8 +185,8 @@ func newService(ctx context.Context, auth policies.AuthServiceClient, db *sqlx.D
|
||||
return svc
|
||||
}
|
||||
|
||||
func subscribeToThingsES(ctx context.Context, svc bootstrap.Service, client *redis.Client, consumer string, logger mflog.Logger) {
|
||||
eventStore := rediscons.NewEventStore(svc, client, consumer, logger)
|
||||
func subscribeToThingsES(ctx context.Context, svc bootstrap.Service, client *redis.Client, consumers string, logger mflog.Logger) {
|
||||
eventStore := consumer.NewEventStore(svc, client, consumers, logger)
|
||||
logger.Info("Subscribed to Redis Event Store")
|
||||
if err := eventStore.Subscribe(ctx, "mainflux.things"); err != nil {
|
||||
logger.Warn(fmt.Sprintf("Bootstrap service failed to subscribe to event sourcing: %s", err))
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
cassandraClient "github.com/mainflux/mainflux/internal/clients/cassandra"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsClient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
cassandraclient "github.com/mainflux/mainflux/internal/clients/cassandra"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsclient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -68,7 +68,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create new thing grpc client
|
||||
tc, tcHandler, err := thingsClient.Setup()
|
||||
tc, tcHandler, err := thingsclient.Setup()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -79,7 +79,7 @@ func main() {
|
||||
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())
|
||||
|
||||
// Create new auth grpc client
|
||||
auth, authHandler, err := authClient.Setup(svcName)
|
||||
auth, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -90,7 +90,7 @@ func main() {
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
|
||||
// Create new cassandra client
|
||||
csdSession, err := cassandraClient.Setup(envPrefixDB)
|
||||
csdSession, err := cassandraclient.Setup(envPrefixDB)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
|
||||
@@ -10,17 +10,16 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
"github.com/mainflux/mainflux/consumers"
|
||||
consumerTracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
consumertracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
"github.com/mainflux/mainflux/consumers/writers/api"
|
||||
"github.com/mainflux/mainflux/consumers/writers/cassandra"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
cassandraClient "github.com/mainflux/mainflux/internal/clients/cassandra"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
cassandraclient "github.com/mainflux/mainflux/internal/clients/cassandra"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -81,7 +80,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create new to cassandra client
|
||||
csdSession, err := cassandraClient.SetupDB(envPrefixDB, cassandra.Table)
|
||||
csdSession, err := cassandraclient.SetupDB(envPrefixDB, cassandra.Table)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -89,7 +88,7 @@ func main() {
|
||||
}
|
||||
defer csdSession.Close()
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -104,7 +103,7 @@ func main() {
|
||||
|
||||
// Create new cassandra-writer repo
|
||||
repo := newService(csdSession, logger)
|
||||
repo = consumerTracing.NewBlocking(tracer, repo, httpServerConfig)
|
||||
repo = consumertracing.NewBlocking(tracer, repo, httpServerConfig)
|
||||
|
||||
// Create new pub sub broker
|
||||
pubSub, err := brokers.NewPubSub(cfg.BrokerURL, "", logger)
|
||||
@@ -142,7 +141,6 @@ func main() {
|
||||
if err := g.Wait(); err != nil {
|
||||
logger.Error(fmt.Sprintf("Cassandra writer service terminated: %s", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func newService(session *gocql.Session, logger mflog.Logger) consumers.BlockingConsumer {
|
||||
|
||||
+12
-12
@@ -16,12 +16,12 @@ import (
|
||||
"github.com/mainflux/mainflux/certs"
|
||||
"github.com/mainflux/mainflux/certs/api"
|
||||
vault "github.com/mainflux/mainflux/certs/pki"
|
||||
certsPg "github.com/mainflux/mainflux/certs/postgres"
|
||||
certspg "github.com/mainflux/mainflux/certs/postgres"
|
||||
"github.com/mainflux/mainflux/certs/tracing"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/postgres"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
@@ -92,18 +92,18 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
pkiClient, err := vault.NewVaultClient(cfg.PkiToken, cfg.PkiHost, cfg.PkiPath, cfg.PkiRole)
|
||||
pkiclient, err := vault.NewVaultClient(cfg.PkiToken, cfg.PkiHost, cfg.PkiPath, cfg.PkiRole)
|
||||
if err != nil {
|
||||
logger.Error("failed to configure client for PKI engine")
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
if err := dbConfig.LoadEnv(envPrefixDB); err != nil {
|
||||
logger.Fatal(fmt.Sprintf("failed to load %s database configuration : %s", svcName, err))
|
||||
}
|
||||
db, err := pgClient.SetupWithConfig(envPrefixDB, *certsPg.Migration(), dbConfig)
|
||||
db, err := pgclient.SetupWithConfig(envPrefixDB, *certspg.Migration(), dbConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -111,7 +111,7 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
auth, authHandler, err := authClient.Setup(svcName)
|
||||
auth, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -121,7 +121,7 @@ func main() {
|
||||
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -134,7 +134,7 @@ func main() {
|
||||
}()
|
||||
tracer := tp.Tracer(svcName)
|
||||
|
||||
svc := newService(auth, db, tracer, logger, cfg, dbConfig, pkiClient)
|
||||
svc := newService(auth, db, tracer, logger, cfg, dbConfig, pkiclient)
|
||||
|
||||
httpServerConfig := server.Config{Port: defSvcHTTPPort}
|
||||
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
|
||||
@@ -162,9 +162,9 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(auth policies.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, cfg config, dbConfig pgClient.Config, pkiAgent vault.Agent) certs.Service {
|
||||
func newService(auth policies.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, cfg config, dbConfig pgclient.Config, pkiAgent vault.Agent) certs.Service {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
certsRepo := certsPg.NewRepository(database, logger)
|
||||
certsRepo := certspg.NewRepository(database, logger)
|
||||
config := mfsdk.Config{
|
||||
CertsURL: cfg.CertsURL,
|
||||
ThingsURL: cfg.ThingsURL,
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Root
|
||||
var rootCmd = &cobra.Command{
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "mainflux-cli",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
cliConf, err := cli.ParseConfig(sdkConf)
|
||||
|
||||
+4
-4
@@ -16,8 +16,8 @@ import (
|
||||
"github.com/mainflux/mainflux/coap/api"
|
||||
"github.com/mainflux/mainflux/coap/tracing"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
thingsClient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
thingsclient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
coapserver "github.com/mainflux/mainflux/internal/server/coap"
|
||||
@@ -84,7 +84,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
tc, tcHandler, err := thingsClient.Setup()
|
||||
tc, tcHandler, err := thingsclient.Setup()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -94,7 +94,7 @@ func main() {
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
|
||||
+4
-4
@@ -16,8 +16,8 @@ import (
|
||||
"github.com/mainflux/mainflux/http/api"
|
||||
"github.com/mainflux/mainflux/http/tracing"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
thingsClient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
thingsclient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -77,7 +77,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
tc, tcHandler, err := thingsClient.Setup()
|
||||
tc, tcHandler, err := thingsclient.Setup()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -87,7 +87,7 @@ func main() {
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
|
||||
@@ -10,14 +10,13 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
|
||||
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsClient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
influxDBClient "github.com/mainflux/mainflux/internal/clients/influxdb"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsclient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
influxdbclient "github.com/mainflux/mainflux/internal/clients/influxdb"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -67,7 +66,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
tc, tcHandler, err := thingsClient.Setup()
|
||||
tc, tcHandler, err := thingsclient.Setup()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -77,7 +76,7 @@ func main() {
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())
|
||||
|
||||
auth, authHandler, err := authClient.Setup(svcName)
|
||||
auth, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -87,7 +86,7 @@ func main() {
|
||||
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
|
||||
influxDBConfig := influxDBClient.Config{}
|
||||
influxDBConfig := influxdbclient.Config{}
|
||||
if err := env.Parse(&influxDBConfig, env.Options{Prefix: envPrefixDB}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load InfluxDB client configuration from environment variable : %s", err))
|
||||
exitCode = 1
|
||||
@@ -100,7 +99,7 @@ func main() {
|
||||
Org: influxDBConfig.Org,
|
||||
}
|
||||
|
||||
client, err := influxDBClient.Connect(ctx, influxDBConfig)
|
||||
client, err := influxdbclient.Connect(ctx, influxDBConfig)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to connect to InfluxDB : %s", err))
|
||||
exitCode = 1
|
||||
|
||||
@@ -13,11 +13,11 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/consumers"
|
||||
consumerTracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
consumertracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
"github.com/mainflux/mainflux/consumers/writers/api"
|
||||
"github.com/mainflux/mainflux/consumers/writers/influxdb"
|
||||
influxDBClient "github.com/mainflux/mainflux/internal/clients/influxdb"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
influxdbclient "github.com/mainflux/mainflux/internal/clients/influxdb"
|
||||
"github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -76,7 +76,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaeger.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -98,7 +98,7 @@ func main() {
|
||||
defer pubSub.Close()
|
||||
pubSub = brokerstracing.NewPubSub(httpServerConfig, tracer, pubSub)
|
||||
|
||||
influxDBConfig := influxDBClient.Config{}
|
||||
influxDBConfig := influxdbclient.Config{}
|
||||
if err := env.Parse(&influxDBConfig, env.Options{Prefix: envPrefixDB}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load InfluxDB client configuration from environment variable : %s", err))
|
||||
exitCode = 1
|
||||
@@ -111,7 +111,7 @@ func main() {
|
||||
Org: influxDBConfig.Org,
|
||||
}
|
||||
|
||||
client, err := influxDBClient.Connect(ctx, influxDBConfig)
|
||||
client, err := influxdbclient.Connect(ctx, influxDBConfig)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to connect to InfluxDB : %s", err))
|
||||
exitCode = 1
|
||||
@@ -120,7 +120,7 @@ func main() {
|
||||
defer client.Close()
|
||||
|
||||
repo := influxdb.NewAsync(client, repocfg)
|
||||
repo = consumerTracing.NewAsync(tracer, repo, httpServerConfig)
|
||||
repo = consumertracing.NewAsync(tracer, repo, httpServerConfig)
|
||||
|
||||
// Start consuming and logging errors.
|
||||
go func(log mflog.Logger) {
|
||||
|
||||
+19
-19
@@ -11,13 +11,13 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
mqttPaho "github.com/eclipse/paho.mqtt.golang"
|
||||
r "github.com/go-redis/redis/v8"
|
||||
mqttpaho "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/go-redis/redis/v8"
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
redisClient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
"github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
redisclient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"github.com/mainflux/mainflux/lora"
|
||||
"github.com/mainflux/mainflux/lora/api"
|
||||
"github.com/mainflux/mainflux/lora/mqtt"
|
||||
"github.com/mainflux/mainflux/lora/redis"
|
||||
loraredis "github.com/mainflux/mainflux/lora/redis"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
"github.com/mainflux/mainflux/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/mainflux/mainflux/pkg/messaging/brokers/tracing"
|
||||
@@ -91,7 +91,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
rmConn, err := redisClient.Setup(envPrefixRouteMap)
|
||||
rmConn, err := redisclient.Setup(envPrefixRouteMap)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup route map redis client : %s", err))
|
||||
exitCode = 1
|
||||
@@ -99,7 +99,7 @@ func main() {
|
||||
}
|
||||
defer rmConn.Close()
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaeger.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -123,7 +123,7 @@ func main() {
|
||||
|
||||
svc := newService(pub, rmConn, thingsRMPrefix, channelsRMPrefix, connsRMPrefix, logger)
|
||||
|
||||
esConn, err := redisClient.Setup(envPrefixThingsES)
|
||||
esConn, err := redisclient.Setup(envPrefixThingsES)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup things event store redis client : %s", err))
|
||||
exitCode = 1
|
||||
@@ -164,19 +164,19 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func connectToMQTTBroker(url, user, password string, timeout time.Duration, logger mflog.Logger) (mqttPaho.Client, error) {
|
||||
opts := mqttPaho.NewClientOptions()
|
||||
func connectToMQTTBroker(url, user, password string, timeout time.Duration, logger mflog.Logger) (mqttpaho.Client, error) {
|
||||
opts := mqttpaho.NewClientOptions()
|
||||
opts.AddBroker(url)
|
||||
opts.SetUsername(user)
|
||||
opts.SetPassword(password)
|
||||
opts.SetOnConnectHandler(func(_ mqttPaho.Client) {
|
||||
opts.SetOnConnectHandler(func(_ mqttpaho.Client) {
|
||||
logger.Info("Connected to Lora MQTT broker")
|
||||
})
|
||||
opts.SetConnectionLostHandler(func(c mqttPaho.Client, err error) {
|
||||
opts.SetConnectionLostHandler(func(c mqttpaho.Client, err error) {
|
||||
logger.Error(fmt.Sprintf("MQTT connection lost: %s", err))
|
||||
})
|
||||
|
||||
client := mqttPaho.NewClient(opts)
|
||||
client := mqttpaho.NewClient(opts)
|
||||
|
||||
if token := client.Connect(); token.WaitTimeout(timeout) && token.Error() != nil {
|
||||
return nil, fmt.Errorf("failed to connect to Lora MQTT broker: %s", token.Error())
|
||||
@@ -185,7 +185,7 @@ func connectToMQTTBroker(url, user, password string, timeout time.Duration, logg
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func subscribeToLoRaBroker(svc lora.Service, mc mqttPaho.Client, timeout time.Duration, topic string, logger mflog.Logger) error {
|
||||
func subscribeToLoRaBroker(svc lora.Service, mc mqttpaho.Client, timeout time.Duration, topic string, logger mflog.Logger) error {
|
||||
mqtt := mqtt.NewBroker(svc, mc, timeout, logger)
|
||||
logger.Info("Subscribed to Lora MQTT broker")
|
||||
if err := mqtt.Subscribe(topic); err != nil {
|
||||
@@ -194,20 +194,20 @@ func subscribeToLoRaBroker(svc lora.Service, mc mqttPaho.Client, timeout time.Du
|
||||
return nil
|
||||
}
|
||||
|
||||
func subscribeToThingsES(ctx context.Context, svc lora.Service, client *r.Client, consumer string, logger mflog.Logger) {
|
||||
eventStore := redis.NewEventStore(svc, client, consumer, logger)
|
||||
func subscribeToThingsES(ctx context.Context, svc lora.Service, client *redis.Client, consumer string, logger mflog.Logger) {
|
||||
eventStore := loraredis.NewEventStore(svc, client, consumer, logger)
|
||||
logger.Info("Subscribed to Redis Event Store")
|
||||
if err := eventStore.Subscribe(ctx, "mainflux.things"); err != nil {
|
||||
logger.Warn(fmt.Sprintf("Lora-adapter service failed to subscribe to Redis event source: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
func newRouteMapRepository(client *r.Client, prefix string, logger mflog.Logger) lora.RouteMapRepository {
|
||||
func newRouteMapRepository(client *redis.Client, prefix string, logger mflog.Logger) lora.RouteMapRepository {
|
||||
logger.Info(fmt.Sprintf("Connected to %s Redis Route-map", prefix))
|
||||
return redis.NewRouteMapRepository(client, prefix)
|
||||
return loraredis.NewRouteMapRepository(client, prefix)
|
||||
}
|
||||
|
||||
func newService(pub messaging.Publisher, rmConn *r.Client, thingsRMPrefix, channelsRMPrefix, connsRMPrefix string, logger mflog.Logger) lora.Service {
|
||||
func newService(pub messaging.Publisher, rmConn *redis.Client, thingsRMPrefix, channelsRMPrefix, connsRMPrefix string, logger mflog.Logger) lora.Service {
|
||||
thingsRM := newRouteMapRepository(rmConn, thingsRMPrefix, logger)
|
||||
chansRM := newRouteMapRepository(rmConn, channelsRMPrefix, logger)
|
||||
connsRM := newRouteMapRepository(rmConn, connsRMPrefix, logger)
|
||||
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsClient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
mongoClient "github.com/mainflux/mainflux/internal/clients/mongo"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsclient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
mongoclient "github.com/mainflux/mainflux/internal/clients/mongo"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -66,7 +66,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
db, err := mongoClient.Setup(envPrefixDB)
|
||||
db, err := mongoclient.Setup(envPrefixDB)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup mongo database : %s", err))
|
||||
exitCode = 1
|
||||
@@ -75,7 +75,7 @@ func main() {
|
||||
|
||||
repo := newService(db, logger)
|
||||
|
||||
tc, tcHandler, err := thingsClient.Setup()
|
||||
tc, tcHandler, err := thingsclient.Setup()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -85,7 +85,7 @@ func main() {
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())
|
||||
|
||||
auth, authHandler, err := authClient.Setup(svcName)
|
||||
auth, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
exitCode = 1
|
||||
|
||||
@@ -13,12 +13,12 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/consumers"
|
||||
consumerTracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
consumertracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
"github.com/mainflux/mainflux/consumers/writers/api"
|
||||
"github.com/mainflux/mainflux/consumers/writers/mongodb"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
mongoClient "github.com/mainflux/mainflux/internal/clients/mongo"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
mongoclient "github.com/mainflux/mainflux/internal/clients/mongo"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -78,7 +78,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -100,7 +100,7 @@ func main() {
|
||||
defer pubSub.Close()
|
||||
pubSub = brokerstracing.NewPubSub(httpServerConfig, tracer, pubSub)
|
||||
|
||||
db, err := mongoClient.Setup(envPrefixDB)
|
||||
db, err := mongoclient.Setup(envPrefixDB)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup mongo database : %s", err))
|
||||
exitCode = 1
|
||||
@@ -108,7 +108,7 @@ func main() {
|
||||
}
|
||||
|
||||
repo := newService(db, logger)
|
||||
repo = consumerTracing.NewBlocking(tracer, repo, httpServerConfig)
|
||||
repo = consumertracing.NewBlocking(tracer, repo, httpServerConfig)
|
||||
|
||||
if err := consumers.Start(ctx, svcName, pubSub, repo, cfg.ConfigPath, logger); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to start MongoDB writer: %s", err))
|
||||
|
||||
+8
-8
@@ -16,9 +16,9 @@ import (
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
thingsClient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
redisClient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
thingsclient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
redisclient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
"github.com/mainflux/mainflux/pkg/uuid"
|
||||
mp "github.com/mainflux/mproxy/pkg/mqtt"
|
||||
"github.com/mainflux/mproxy/pkg/session"
|
||||
ws "github.com/mainflux/mproxy/pkg/websocket"
|
||||
"github.com/mainflux/mproxy/pkg/websocket"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
@@ -103,7 +103,7 @@ func main() {
|
||||
Port: cfg.HTTPTargetPort,
|
||||
}
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -150,7 +150,7 @@ func main() {
|
||||
defer np.Close()
|
||||
np = brokerstracing.NewPublisher(serverConfig, tracer, np)
|
||||
|
||||
ec, err := redisClient.Setup(envPrefixES)
|
||||
ec, err := redisclient.Setup(envPrefixES)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup %s event store redis client : %s", svcName, err))
|
||||
exitCode = 1
|
||||
@@ -160,7 +160,7 @@ func main() {
|
||||
|
||||
es := mqttredis.NewEventStore(ctx, ec, cfg.Instance)
|
||||
|
||||
tc, tcHandler, err := thingsClient.Setup()
|
||||
tc, tcHandler, err := thingsclient.Setup()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -222,7 +222,7 @@ func proxyMQTT(ctx context.Context, cfg config, logger mflog.Logger, handler ses
|
||||
|
||||
func proxyWS(ctx context.Context, cfg config, logger mflog.Logger, handler session.Handler) error {
|
||||
target := fmt.Sprintf("%s:%s", cfg.HTTPTargetHost, cfg.HTTPTargetPort)
|
||||
wp := ws.New(target, cfg.HTTPTargetPath, "ws", handler, logger)
|
||||
wp := websocket.New(target, cfg.HTTPTargetPath, "ws", handler, logger)
|
||||
http.Handle("/mqtt", wp.Handler())
|
||||
|
||||
errCh := make(chan error)
|
||||
|
||||
+11
-11
@@ -10,12 +10,12 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
r "github.com/go-redis/redis/v8"
|
||||
"github.com/go-redis/redis/v8"
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
redisClient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
redisclient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/mainflux/mainflux/opcua/api"
|
||||
"github.com/mainflux/mainflux/opcua/db"
|
||||
"github.com/mainflux/mainflux/opcua/gopcua"
|
||||
"github.com/mainflux/mainflux/opcua/redis"
|
||||
opcuaredis "github.com/mainflux/mainflux/opcua/redis"
|
||||
"github.com/mainflux/mainflux/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/mainflux/mainflux/pkg/messaging/brokers/tracing"
|
||||
"github.com/mainflux/mainflux/pkg/uuid"
|
||||
@@ -89,7 +89,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
rmConn, err := redisClient.Setup(envPrefixRouteMap)
|
||||
rmConn, err := redisclient.Setup(envPrefixRouteMap)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup %s bootstrap event store redis client : %s", svcName, err))
|
||||
exitCode = 1
|
||||
@@ -101,7 +101,7 @@ func main() {
|
||||
chanRM := newRouteMapRepositoy(rmConn, channelsRMPrefix, logger)
|
||||
connRM := newRouteMapRepositoy(rmConn, connectionRMPrefix, logger)
|
||||
|
||||
esConn, err := redisClient.Setup(envPrefixES)
|
||||
esConn, err := redisclient.Setup(envPrefixES)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup %s bootstrap event store redis client : %s", svcName, err))
|
||||
exitCode = 1
|
||||
@@ -109,7 +109,7 @@ func main() {
|
||||
}
|
||||
defer esConn.Close()
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -177,16 +177,16 @@ func subscribeToStoredSubs(ctx context.Context, sub opcua.Subscriber, cfg opcua.
|
||||
}
|
||||
}
|
||||
|
||||
func subscribeToThingsES(ctx context.Context, svc opcua.Service, client *r.Client, prefix string, logger mflog.Logger) {
|
||||
eventStore := redis.NewEventStore(svc, client, prefix, logger)
|
||||
func subscribeToThingsES(ctx context.Context, svc opcua.Service, client *redis.Client, prefix string, logger mflog.Logger) {
|
||||
eventStore := opcuaredis.NewEventStore(svc, client, prefix, logger)
|
||||
if err := eventStore.Subscribe(ctx, "mainflux.things"); err != nil {
|
||||
logger.Warn(fmt.Sprintf("Failed to subscribe to Redis event source: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
func newRouteMapRepositoy(client *r.Client, prefix string, logger mflog.Logger) opcua.RouteMapRepository {
|
||||
func newRouteMapRepositoy(client *redis.Client, prefix string, logger mflog.Logger) opcua.RouteMapRepository {
|
||||
logger.Info(fmt.Sprintf("Connected to %s Redis Route-map", prefix))
|
||||
return redis.NewRouteMapRepository(client, prefix)
|
||||
return opcuaredis.NewRouteMapRepository(client, prefix)
|
||||
}
|
||||
|
||||
func newService(sub opcua.Subscriber, browser opcua.Browser, thingRM, chanRM, connRM opcua.RouteMapRepository, opcuaConfig opcua.Config, logger mflog.Logger) opcua.Service {
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsClient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsclient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -67,13 +67,13 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
if err := dbConfig.LoadEnv(envPrefixDB); err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
db, err := pgClient.Connect(dbConfig)
|
||||
db, err := pgclient.Connect(dbConfig)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup postgres database : %s", err))
|
||||
exitCode = 1
|
||||
@@ -81,7 +81,7 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
tc, tcHandler, err := thingsClient.Setup()
|
||||
tc, tcHandler, err := thingsclient.Setup()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -91,7 +91,7 @@ func main() {
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())
|
||||
|
||||
auth, authHandler, err := authClient.Setup(svcName)
|
||||
auth, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
|
||||
@@ -14,12 +14,12 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/consumers"
|
||||
consumerTracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
consumertracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
"github.com/mainflux/mainflux/consumers/writers/api"
|
||||
writerPg "github.com/mainflux/mainflux/consumers/writers/postgres"
|
||||
writerpg "github.com/mainflux/mainflux/consumers/writers/postgres"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -79,14 +79,14 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
db, err := pgClient.SetupWithConfig(envPrefixDB, *writerPg.Migration(), dbConfig)
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
db, err := pgclient.SetupWithConfig(envPrefixDB, *writerpg.Migration(), dbConfig)
|
||||
if err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -109,7 +109,7 @@ func main() {
|
||||
pubSub = brokerstracing.NewPubSub(httpServerConfig, tracer, pubSub)
|
||||
|
||||
repo := newService(db, logger)
|
||||
repo = consumerTracing.NewBlocking(tracer, repo, httpServerConfig)
|
||||
repo = consumertracing.NewBlocking(tracer, repo, httpServerConfig)
|
||||
|
||||
if err = consumers.Start(ctx, svcName, pubSub, repo, cfg.ConfigPath, logger); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to create Postgres writer: %s", err))
|
||||
@@ -138,7 +138,7 @@ func main() {
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, logger mflog.Logger) consumers.BlockingConsumer {
|
||||
svc := writerPg.New(db)
|
||||
svc := writerpg.New(db)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics("postgres", "message_writer")
|
||||
svc = api.MetricsMiddleware(svc, counter, latency)
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
mfclients "github.com/mainflux/mainflux/pkg/clients"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
mfgroups "github.com/mainflux/mainflux/pkg/groups"
|
||||
mfSDK "github.com/mainflux/mainflux/pkg/sdk/go"
|
||||
mfsdk "github.com/mainflux/mainflux/pkg/sdk/go"
|
||||
"github.com/mainflux/mainflux/pkg/uuid"
|
||||
"github.com/mainflux/mainflux/provision"
|
||||
"github.com/mainflux/mainflux/provision/api"
|
||||
@@ -123,7 +123,7 @@ func main() {
|
||||
logger.Info("Continue with settings from file: " + cfg.File)
|
||||
}
|
||||
|
||||
SDKCfg := mfSDK.Config{
|
||||
SDKCfg := mfsdk.Config{
|
||||
UsersURL: cfg.Server.UsersURL,
|
||||
ThingsURL: cfg.Server.ThingsURL,
|
||||
BootstrapURL: cfg.Server.MfBSURL,
|
||||
@@ -131,7 +131,7 @@ func main() {
|
||||
MsgContentType: contentType,
|
||||
TLSVerification: cfg.Server.TLS,
|
||||
}
|
||||
SDK := mfSDK.NewSDK(SDKCfg)
|
||||
SDK := mfsdk.NewSDK(SDKCfg)
|
||||
|
||||
svc := provision.New(cfg, SDK, logger)
|
||||
svc = api.NewLoggingMiddleware(svc, logger)
|
||||
@@ -155,7 +155,6 @@ func main() {
|
||||
if err := g.Wait(); err != nil {
|
||||
logger.Error(fmt.Sprintf("Provision service terminated: %s", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func loadConfigFromFile(file string) (provision.Config, error) {
|
||||
|
||||
+10
-11
@@ -16,13 +16,13 @@ import (
|
||||
"github.com/mainflux/mainflux/consumers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers/api"
|
||||
notifierPg "github.com/mainflux/mainflux/consumers/notifiers/postgres"
|
||||
notifierpg "github.com/mainflux/mainflux/consumers/notifiers/postgres"
|
||||
mfsmpp "github.com/mainflux/mainflux/consumers/notifiers/smpp"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers/tracing"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -79,8 +79,8 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
db, err := pgClient.SetupWithConfig(envPrefixDB, *notifierPg.Migration(), dbConfig)
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
db, err := pgclient.SetupWithConfig(envPrefixDB, *notifierpg.Migration(), dbConfig)
|
||||
if err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -122,7 +122,7 @@ func main() {
|
||||
defer pubSub.Close()
|
||||
pubSub = brokerstracing.NewPubSub(httpServerConfig, tracer, pubSub)
|
||||
|
||||
auth, authHandler, err := authClient.Setup(svcName)
|
||||
auth, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -156,12 +156,11 @@ func main() {
|
||||
if err := g.Wait(); err != nil {
|
||||
logger.Error(fmt.Sprintf("SMPP notifier service terminated: %s", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth policies.AuthServiceClient, c config, sc mfsmpp.Config, logger mflog.Logger) notifiers.Service {
|
||||
database := notifierPg.NewDatabase(db, tracer)
|
||||
repo := tracing.New(tracer, notifierPg.New(database))
|
||||
database := notifierpg.NewDatabase(db, tracer)
|
||||
repo := tracing.New(tracer, notifierpg.New(database))
|
||||
idp := ulid.New()
|
||||
notifier := mfsmpp.New(sc)
|
||||
svc := notifiers.New(auth, repo, idp, notifier, c.From)
|
||||
|
||||
+10
-11
@@ -16,13 +16,13 @@ import (
|
||||
"github.com/mainflux/mainflux/consumers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers/api"
|
||||
notifierPg "github.com/mainflux/mainflux/consumers/notifiers/postgres"
|
||||
notifierpg "github.com/mainflux/mainflux/consumers/notifiers/postgres"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers/smtp"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers/tracing"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/internal/email"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
@@ -80,8 +80,8 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
db, err := pgClient.SetupWithConfig(envPrefixDB, *notifierPg.Migration(), dbConfig)
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
db, err := pgclient.SetupWithConfig(envPrefixDB, *notifierpg.Migration(), dbConfig)
|
||||
if err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
exitCode = 1
|
||||
@@ -103,7 +103,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -125,7 +125,7 @@ func main() {
|
||||
defer pubSub.Close()
|
||||
pubSub = brokerstracing.NewPubSub(httpServerConfig, tracer, pubSub)
|
||||
|
||||
auth, authHandler, err := authClient.Setup(svcName)
|
||||
auth, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -166,12 +166,11 @@ func main() {
|
||||
if err := g.Wait(); err != nil {
|
||||
logger.Error(fmt.Sprintf("SMTP notifier service terminated: %s", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth policies.AuthServiceClient, c config, ec email.Config, logger mflog.Logger) (notifiers.Service, error) {
|
||||
database := notifierPg.NewDatabase(db, tracer)
|
||||
repo := tracing.New(tracer, notifierPg.New(database))
|
||||
database := notifierpg.NewDatabase(db, tracer)
|
||||
repo := tracing.New(tracer, notifierpg.New(database))
|
||||
idp := ulid.New()
|
||||
|
||||
agent, err := email.New(&ec)
|
||||
|
||||
+15
-15
@@ -17,10 +17,10 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
redisClient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
redisclient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/postgres"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
@@ -46,7 +46,7 @@ import (
|
||||
ppostgres "github.com/mainflux/mainflux/things/policies/postgres"
|
||||
pcache "github.com/mainflux/mainflux/things/policies/redis"
|
||||
ppracing "github.com/mainflux/mainflux/things/policies/tracing"
|
||||
thingsPg "github.com/mainflux/mainflux/things/postgres"
|
||||
thingspg "github.com/mainflux/mainflux/things/postgres"
|
||||
upolicies "github.com/mainflux/mainflux/users/policies"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@@ -103,11 +103,11 @@ func main() {
|
||||
}
|
||||
|
||||
// Create new database for things
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
if err := dbConfig.LoadEnv(envPrefixDB); err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
db, err := pgClient.SetupWithConfig(envPrefixDB, *thingsPg.Migration(), dbConfig)
|
||||
db, err := pgclient.SetupWithConfig(envPrefixDB, *thingspg.Migration(), dbConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -115,7 +115,7 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -129,22 +129,22 @@ func main() {
|
||||
tracer := tp.Tracer(svcName)
|
||||
|
||||
// Setup new redis cache client
|
||||
cacheClient, err := redisClient.Setup(envPrefixCache)
|
||||
cacheclient, err := redisclient.Setup(envPrefixCache)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer cacheClient.Close()
|
||||
defer cacheclient.Close()
|
||||
|
||||
// Setup new redis event store client
|
||||
esClient, err := redisClient.Setup(envPrefixES)
|
||||
esclient, err := redisclient.Setup(envPrefixES)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer esClient.Close()
|
||||
defer esclient.Close()
|
||||
|
||||
var auth upolicies.AuthServiceClient
|
||||
switch cfg.StandaloneID != "" && cfg.StandaloneToken != "" {
|
||||
@@ -152,7 +152,7 @@ func main() {
|
||||
auth = localusers.NewAuthService(cfg.StandaloneID, cfg.StandaloneToken)
|
||||
logger.Info("Using standalone auth service")
|
||||
default:
|
||||
authServiceClient, authHandler, err := authClient.Setup(svcName)
|
||||
authServiceClient, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -163,7 +163,7 @@ func main() {
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
}
|
||||
|
||||
csvc, gsvc, psvc := newService(ctx, db, dbConfig, auth, cacheClient, esClient, cfg.CacheKeyDuration, tracer, logger)
|
||||
csvc, gsvc, psvc := newService(ctx, db, dbConfig, auth, cacheclient, esclient, cfg.CacheKeyDuration, tracer, logger)
|
||||
|
||||
httpServerConfig := server.Config{Port: defSvcHTTPPort}
|
||||
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
|
||||
@@ -211,7 +211,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgClient.Config, auth upolicies.AuthServiceClient, cacheClient *redis.Client, esClient *redis.Client, keyDuration string, tracer trace.Tracer, logger mflog.Logger) (clients.Service, groups.Service, tpolicies.Service) {
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, auth upolicies.AuthServiceClient, cacheClient *redis.Client, esClient *redis.Client, keyDuration string, tracer trace.Tracer, logger mflog.Logger) (clients.Service, groups.Service, tpolicies.Service) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
cRepo := cpostgres.NewRepository(database)
|
||||
gRepo := gpostgres.New(database)
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsClient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
thingsclient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -67,13 +67,13 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
if err := dbConfig.LoadEnv(envPrefixDB); err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
db, err := pgClient.Connect(dbConfig)
|
||||
db, err := pgclient.Connect(dbConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func main() {
|
||||
|
||||
repo := newService(db, logger)
|
||||
|
||||
auth, authHandler, err := authClient.Setup(svcName)
|
||||
auth, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -91,7 +91,7 @@ func main() {
|
||||
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
|
||||
tc, tcHandler, err := thingsClient.Setup()
|
||||
tc, tcHandler, err := thingsclient.Setup()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
|
||||
@@ -14,12 +14,12 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/consumers"
|
||||
consumerTracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
consumertracing "github.com/mainflux/mainflux/consumers/tracing"
|
||||
"github.com/mainflux/mainflux/consumers/writers/api"
|
||||
"github.com/mainflux/mainflux/consumers/writers/timescale"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -79,8 +79,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
db, err := pgClient.SetupWithConfig(envPrefixDB, *timescale.Migration(), dbConfig)
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
db, err := pgclient.SetupWithConfig(envPrefixDB, *timescale.Migration(), dbConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -88,7 +88,7 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -102,7 +102,7 @@ func main() {
|
||||
tracer := tp.Tracer(svcName)
|
||||
|
||||
repo := newService(db, logger)
|
||||
repo = consumerTracing.NewBlocking(tracer, repo, httpServerConfig)
|
||||
repo = consumertracing.NewBlocking(tracer, repo, httpServerConfig)
|
||||
|
||||
pubSub, err := brokers.NewPubSub(cfg.BrokerURL, "", logger)
|
||||
if err != nil {
|
||||
|
||||
+11
-11
@@ -14,10 +14,10 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
authClient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
mongoClient "github.com/mainflux/mainflux/internal/clients/mongo"
|
||||
redisClient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
authclient "github.com/mainflux/mainflux/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
mongoclient "github.com/mainflux/mainflux/internal/clients/mongo"
|
||||
redisclient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -92,7 +92,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
cacheClient, err := redisClient.Setup(envPrefixCache)
|
||||
cacheClient, err := redisclient.Setup(envPrefixCache)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -101,7 +101,7 @@ func main() {
|
||||
defer cacheClient.Close()
|
||||
|
||||
// Setup new redis event store client
|
||||
esClient, err := redisClient.Setup(envPrefixES)
|
||||
esClient, err := redisclient.Setup(envPrefixES)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -109,14 +109,14 @@ func main() {
|
||||
}
|
||||
defer esClient.Close()
|
||||
|
||||
db, err := mongoClient.Setup(envPrefixDB)
|
||||
db, err := mongoclient.Setup(envPrefixDB)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup postgres database : %s", err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -134,7 +134,7 @@ func main() {
|
||||
case true:
|
||||
auth = localusers.NewAuthService(cfg.StandaloneID, cfg.StandaloneToken)
|
||||
default:
|
||||
authServiceClient, authHandler, err := authClient.Setup(svcName)
|
||||
authServiceClient, authHandler, err := authclient.Setup(svcName)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -176,7 +176,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, id string, ps messaging.PubSub, chanID string, users policies.AuthServiceClient, tracer trace.Tracer, db *mongo.Database, cacheClient *redis.Client, esClient *redis.Client, logger mflog.Logger) twins.Service {
|
||||
func newService(ctx context.Context, id string, ps messaging.PubSub, chanID string, users policies.AuthServiceClient, tracer trace.Tracer, db *mongo.Database, cacheclient *redis.Client, esClient *redis.Client, logger mflog.Logger) twins.Service {
|
||||
twinRepo := twmongodb.NewTwinRepository(db)
|
||||
twinRepo = tracing.TwinRepositoryMiddleware(tracer, twinRepo)
|
||||
|
||||
@@ -184,7 +184,7 @@ func newService(ctx context.Context, id string, ps messaging.PubSub, chanID stri
|
||||
stateRepo = tracing.StateRepositoryMiddleware(tracer, stateRepo)
|
||||
|
||||
idProvider := uuid.New()
|
||||
twinCache := rediscache.NewTwinCache(cacheClient)
|
||||
twinCache := rediscache.NewTwinCache(cacheclient)
|
||||
twinCache = tracing.TwinCacheMiddleware(tracer, twinCache)
|
||||
|
||||
svc := twins.New(ps, users, twinRepo, twinCache, stateRepo, idProvider, chanID, logger)
|
||||
|
||||
+9
-9
@@ -18,9 +18,9 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
redisClient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
redisclient "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
"github.com/mainflux/mainflux/internal/email"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/postgres"
|
||||
@@ -50,7 +50,7 @@ import (
|
||||
ppostgres "github.com/mainflux/mainflux/users/policies/postgres"
|
||||
pcache "github.com/mainflux/mainflux/users/policies/redis"
|
||||
ptracing "github.com/mainflux/mainflux/users/policies/tracing"
|
||||
clientsPg "github.com/mainflux/mainflux/users/postgres"
|
||||
clientspg "github.com/mainflux/mainflux/users/postgres"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"google.golang.org/grpc"
|
||||
@@ -120,11 +120,11 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{Name: defDB}
|
||||
dbConfig := pgclient.Config{Name: defDB}
|
||||
if err := dbConfig.LoadEnv(envPrefixDB); err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
db, err := pgClient.SetupWithConfig(envPrefixDB, *clientsPg.Migration(), dbConfig)
|
||||
db, err := pgclient.SetupWithConfig(envPrefixDB, *clientspg.Migration(), dbConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -132,7 +132,7 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
@@ -146,7 +146,7 @@ func main() {
|
||||
tracer := tp.Tracer(svcName)
|
||||
|
||||
// Setup new redis event store client
|
||||
esClient, err := redisClient.Setup(envPrefixES)
|
||||
esClient, err := redisclient.Setup(envPrefixES)
|
||||
if err != nil {
|
||||
logger.Fatal(err.Error())
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgClient.Config, esClient *redis.Client, tracer trace.Tracer, c config, ec email.Config, logger mflog.Logger) (clients.Service, groups.Service, policies.Service) {
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, esClient *redis.Client, tracer trace.Tracer, c config, ec email.Config, logger mflog.Logger) (clients.Service, groups.Service, policies.Service) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
cRepo := uclients.NewRepository(database)
|
||||
gRepo := gpostgres.New(database)
|
||||
|
||||
+4
-4
@@ -13,8 +13,8 @@ import (
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/internal"
|
||||
thingsClient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
thingsclient "github.com/mainflux/mainflux/internal/clients/grpc/things"
|
||||
jaegerclient "github.com/mainflux/mainflux/internal/clients/jaeger"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
httpserver "github.com/mainflux/mainflux/internal/server/http"
|
||||
@@ -77,7 +77,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
tc, tcHandler, err := thingsClient.Setup()
|
||||
tc, tcHandler, err := thingsclient.Setup()
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -87,7 +87,7 @@ func main() {
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())
|
||||
|
||||
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
tp, err := jaegerclient.NewProvider(svcName, cfg.JaegerURL, cfg.InstanceID)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to init Jaeger: %s", err))
|
||||
exitCode = 1
|
||||
|
||||
+1
-2
@@ -12,9 +12,8 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/things/policies"
|
||||
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
"github.com/mainflux/mainflux/things/policies"
|
||||
)
|
||||
|
||||
const chansPrefix = "channels"
|
||||
|
||||
@@ -82,5 +82,4 @@ func (lm *loggingMiddleware) Unsubscribe(ctx context.Context, key, chanID, subto
|
||||
}(time.Now())
|
||||
|
||||
return lm.svc.Unsubscribe(ctx, key, chanID, subtopic, token)
|
||||
|
||||
}
|
||||
|
||||
@@ -13,12 +13,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
|
||||
"github.com/go-zoo/bone"
|
||||
"github.com/mainflux/mainflux"
|
||||
"github.com/mainflux/mainflux/coap"
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
"github.com/plgd-dev/go-coap/v2/message"
|
||||
"github.com/plgd-dev/go-coap/v2/message/codes"
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pelletier/go-toml"
|
||||
|
||||
"github.com/mainflux/mainflux/internal/apiutil"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
@@ -19,6 +17,7 @@ import (
|
||||
"github.com/mainflux/mainflux/pkg/transformers"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/json"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/senml"
|
||||
"github.com/pelletier/go-toml"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -55,7 +54,6 @@ func Start(ctx context.Context, id string, sub messaging.Subscriber, consumer in
|
||||
default:
|
||||
return apiutil.ErrInvalidQueryParams
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
httpapi "github.com/mainflux/mainflux/consumers/notifiers/api"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers/mocks"
|
||||
"github.com/mainflux/mainflux/internal/apiutil"
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/kit/metrics"
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
)
|
||||
|
||||
var _ notifiers.Service = (*metricsMiddleware)(nil)
|
||||
|
||||
@@ -73,8 +73,7 @@ func (res listSubsRes) Empty() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type removeSubRes struct {
|
||||
}
|
||||
type removeSubRes struct{}
|
||||
|
||||
func (res removeSubRes) Code() int {
|
||||
return http.StatusNoContent
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
kithttp "github.com/go-kit/kit/transport/http"
|
||||
"github.com/go-zoo/bone"
|
||||
"github.com/mainflux/mainflux"
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/internal/apiutil"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
)
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
_ "github.com/jackc/pgx/v5/stdlib" // required for SQL access
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers/postgres"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/pkg/ulid"
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -53,7 +53,7 @@ func TestMain(m *testing.M) {
|
||||
log.Fatalf("Could not connect to docker: %s", err)
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{
|
||||
dbConfig := pgclient.Config{
|
||||
Host: "localhost",
|
||||
Port: port,
|
||||
User: "test",
|
||||
@@ -65,7 +65,7 @@ func TestMain(m *testing.M) {
|
||||
SSLRootCert: "",
|
||||
}
|
||||
|
||||
if db, err = pgClient.SetupDB(dbConfig, *postgres.Migration()); err != nil {
|
||||
if db, err = pgclient.SetupDB(dbConfig, *postgres.Migration()); err != nil {
|
||||
log.Fatalf("Could not setup test DB connection: %s", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/jackc/pgerrcode"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers/postgres"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
@@ -14,10 +14,8 @@ import (
|
||||
"github.com/mainflux/mainflux/users/policies"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrMessage indicates an error converting a message to Mainflux message.
|
||||
ErrMessage = errors.New("failed to convert to Mainflux message")
|
||||
)
|
||||
// ErrMessage indicates an error converting a message to Mainflux message.
|
||||
var ErrMessage = errors.New("failed to convert to Mainflux message")
|
||||
|
||||
var _ consumers.AsyncConsumer = (*notifierService)(nil)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers/mocks"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
|
||||
@@ -6,7 +6,7 @@ package smtp
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/internal/email"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ package tracing
|
||||
import (
|
||||
"context"
|
||||
|
||||
notifiers "github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"github.com/mainflux/mainflux/consumers/notifiers"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
@@ -28,8 +28,10 @@ var defaultAttributes = []attribute.KeyValue{
|
||||
attribute.String("network.type", "ipv4"),
|
||||
}
|
||||
|
||||
var _ consumers.AsyncConsumer = (*tracingMiddlewareAsync)(nil)
|
||||
var _ consumers.BlockingConsumer = (*tracingMiddlewareBlock)(nil)
|
||||
var (
|
||||
_ consumers.AsyncConsumer = (*tracingMiddlewareAsync)(nil)
|
||||
_ consumers.BlockingConsumer = (*tracingMiddlewareBlock)(nil)
|
||||
)
|
||||
|
||||
type tracingMiddlewareAsync struct {
|
||||
consumer consumers.AsyncConsumer
|
||||
@@ -106,7 +108,7 @@ func (tm *tracingMiddlewareAsync) Errors() <-chan error {
|
||||
}
|
||||
|
||||
func createSpan(ctx context.Context, operation, clientID, topic, subTopic string, noMessages int, cfg server.Config, spanKind trace.SpanKind, tracer trace.Tracer) (context.Context, trace.Span) {
|
||||
var subject = fmt.Sprintf("channels.%s.messages", topic)
|
||||
subject := fmt.Sprintf("channels.%s.messages", topic)
|
||||
if subTopic != "" {
|
||||
subject = fmt.Sprintf("%s.%s", subject, subTopic)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/mainflux/mainflux/consumers/writers/cassandra"
|
||||
casClient "github.com/mainflux/mainflux/internal/clients/cassandra"
|
||||
casclient "github.com/mainflux/mainflux/internal/clients/cassandra"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/json"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/senml"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -36,12 +36,12 @@ var (
|
||||
)
|
||||
|
||||
func TestSaveSenml(t *testing.T) {
|
||||
session, err := casClient.Connect(casClient.Config{
|
||||
session, err := casclient.Connect(casclient.Config{
|
||||
Hosts: []string{addr},
|
||||
Keyspace: keyspace,
|
||||
})
|
||||
require.Nil(t, err, fmt.Sprintf("failed to connect to Cassandra: %s", err))
|
||||
err = casClient.InitDB(session, cassandra.Table)
|
||||
err = casclient.InitDB(session, cassandra.Table)
|
||||
require.Nil(t, err, fmt.Sprintf("failed to initialize to Cassandra: %s", err))
|
||||
repo := cassandra.New(session)
|
||||
now := time.Now().Unix()
|
||||
@@ -78,7 +78,7 @@ func TestSaveSenml(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSaveJSON(t *testing.T) {
|
||||
session, err := casClient.Connect(casClient.Config{
|
||||
session, err := casclient.Connect(casclient.Config{
|
||||
Hosts: []string{addr},
|
||||
Keyspace: keyspace,
|
||||
})
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
casClient "github.com/mainflux/mainflux/internal/clients/cassandra"
|
||||
"github.com/mainflux/mainflux/internal/clients/cassandra"
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
var logger, _ = mflog.New(os.Stdout, mflog.Info.String())
|
||||
@@ -35,7 +35,7 @@ func TestMain(m *testing.M) {
|
||||
return err
|
||||
}
|
||||
|
||||
session, err := casClient.Connect(casClient.Config{
|
||||
session, err := cassandra.Connect(cassandra.Config{
|
||||
Hosts: []string{addr},
|
||||
Keyspace: keyspace,
|
||||
})
|
||||
|
||||
@@ -8,22 +8,23 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
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"
|
||||
"github.com/mainflux/mainflux/consumers"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/json"
|
||||
"github.com/mainflux/mainflux/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"
|
||||
)
|
||||
|
||||
const senmlPoints = "messages"
|
||||
|
||||
var errSaveMessage = errors.New("failed to save message to influxdb database")
|
||||
|
||||
var _ consumers.AsyncConsumer = (*influxRepo)(nil)
|
||||
var _ consumers.BlockingConsumer = (*influxRepo)(nil)
|
||||
var (
|
||||
_ consumers.AsyncConsumer = (*influxRepo)(nil)
|
||||
_ consumers.BlockingConsumer = (*influxRepo)(nil)
|
||||
)
|
||||
|
||||
type RepoConfig struct {
|
||||
Bucket string
|
||||
|
||||
@@ -10,11 +10,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
|
||||
influxdata "github.com/influxdata/influxdb-client-go/v2"
|
||||
writer "github.com/mainflux/mainflux/consumers/writers/influxdb"
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/json"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/senml"
|
||||
"github.com/mainflux/mainflux/pkg/uuid"
|
||||
@@ -70,6 +69,7 @@ func deleteBucket() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func createBucket() error {
|
||||
orgAPI := client.OrganizationsAPI()
|
||||
org, err := orgAPI.FindOrganizationByName(context.Background(), repoCfg.Org)
|
||||
@@ -83,6 +83,7 @@ func createBucket() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resetBucket() error {
|
||||
if err := deleteBucket(); err != nil {
|
||||
return err
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
influxdata "github.com/influxdata/influxdb-client-go/v2"
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -6,12 +6,11 @@ package mongodb
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
|
||||
"github.com/mainflux/mainflux/consumers"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/json"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/senml"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
const senmlCollection string = "messages"
|
||||
|
||||
@@ -11,14 +11,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mainflux/mainflux/consumers/writers/mongodb"
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/json"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/senml"
|
||||
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
|
||||
@@ -9,10 +9,9 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ory/dockertest/v3"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
@@ -9,12 +9,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/mainflux/mainflux/consumers/writers/postgres"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/json"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/senml"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/mainflux/mainflux/consumers/writers/postgres"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
var db *sqlx.DB
|
||||
|
||||
@@ -9,12 +9,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/mainflux/mainflux/consumers/writers/timescale"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/json"
|
||||
"github.com/mainflux/mainflux/pkg/transformers/senml"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -12,10 +12,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"github.com/mainflux/mainflux/consumers/writers/timescale"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
var db *sqlx.DB
|
||||
@@ -49,7 +48,7 @@ func TestMain(m *testing.M) {
|
||||
log.Fatalf("Could not connect to docker: %s", err)
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{
|
||||
dbConfig := pgclient.Config{
|
||||
Host: "localhost",
|
||||
Port: port,
|
||||
User: "test",
|
||||
@@ -61,7 +60,7 @@ func TestMain(m *testing.M) {
|
||||
SSLRootCert: "",
|
||||
}
|
||||
|
||||
db, err = pgClient.SetupDB(dbConfig, *timescale.Migration())
|
||||
db, err = pgclient.SetupDB(dbConfig, *timescale.Migration())
|
||||
if err != nil {
|
||||
log.Fatalf("Could not setup test DB connection: %s", err)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
adapter "github.com/mainflux/mainflux/http"
|
||||
server "github.com/mainflux/mainflux/http"
|
||||
"github.com/mainflux/mainflux/http/api"
|
||||
"github.com/mainflux/mainflux/http/mocks"
|
||||
"github.com/mainflux/mainflux/internal/apiutil"
|
||||
@@ -21,12 +21,12 @@ import (
|
||||
|
||||
const instanceID = "5de9b29a-feb9-11ed-be56-0242ac120002"
|
||||
|
||||
func newService(cc policies.AuthServiceClient) adapter.Service {
|
||||
func newService(cc policies.AuthServiceClient) server.Service {
|
||||
pub := mocks.NewPublisher()
|
||||
return adapter.New(pub, cc)
|
||||
return server.New(pub, cc)
|
||||
}
|
||||
|
||||
func newHTTPServer(svc adapter.Service) *httptest.Server {
|
||||
func newHTTPServer(svc server.Service) *httptest.Server {
|
||||
mux := api.MakeHandler(svc, instanceID)
|
||||
return httptest.NewServer(mux)
|
||||
}
|
||||
|
||||
@@ -17,13 +17,12 @@ import (
|
||||
kithttp "github.com/go-kit/kit/transport/http"
|
||||
"github.com/go-zoo/bone"
|
||||
"github.com/mainflux/mainflux"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
|
||||
adapter "github.com/mainflux/mainflux/http"
|
||||
"github.com/mainflux/mainflux/internal/apiutil"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -35,9 +34,7 @@ const (
|
||||
contentType = "application/json"
|
||||
)
|
||||
|
||||
var (
|
||||
errMalformedSubtopic = errors.New("malformed subtopic")
|
||||
)
|
||||
var errMalformedSubtopic = errors.New("malformed subtopic")
|
||||
|
||||
var channelPartRegExp = regexp.MustCompile(`^/channels/([\w\-]+)/messages(/[^?]*)?(\?.*)?$`)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
grpcClient "github.com/mainflux/mainflux/internal/clients/grpc"
|
||||
grpcclient "github.com/mainflux/mainflux/internal/clients/grpc"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/users/policies"
|
||||
@@ -16,12 +16,12 @@ const envAuthGrpcPrefix = "MF_AUTH_GRPC_"
|
||||
var errGrpcConfig = errors.New("failed to load grpc configuration")
|
||||
|
||||
// Setup loads Auth gRPC configuration from environment variable and creates new Auth gRPC API.
|
||||
func Setup(svcName string) (policies.AuthServiceClient, grpcClient.ClientHandler, error) {
|
||||
config := grpcClient.Config{}
|
||||
func Setup(svcName string) (policies.AuthServiceClient, grpcclient.ClientHandler, error) {
|
||||
config := grpcclient.Config{}
|
||||
if err := env.Parse(&config, env.Options{Prefix: envAuthGrpcPrefix}); err != nil {
|
||||
return nil, nil, errors.Wrap(errGrpcConfig, err)
|
||||
}
|
||||
c, ch, err := grpcClient.Setup(config, svcName)
|
||||
c, ch, err := grpcclient.Setup(config, svcName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package things
|
||||
|
||||
import (
|
||||
grpcClient "github.com/mainflux/mainflux/internal/clients/grpc"
|
||||
grpcclient "github.com/mainflux/mainflux/internal/clients/grpc"
|
||||
"github.com/mainflux/mainflux/internal/env"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/things/policies"
|
||||
@@ -16,13 +16,13 @@ const envThingsAuthGrpcPrefix = "MF_THINGS_AUTH_GRPC_"
|
||||
var errGrpcConfig = errors.New("failed to load grpc configuration")
|
||||
|
||||
// Setup loads Things gRPC configuration from environment variable and creates new Things gRPC API.
|
||||
func Setup() (policies.AuthServiceClient, grpcClient.ClientHandler, error) {
|
||||
config := grpcClient.Config{}
|
||||
func Setup() (policies.AuthServiceClient, grpcclient.ClientHandler, error) {
|
||||
config := grpcclient.Config{}
|
||||
if err := env.Parse(&config, env.Options{Prefix: envThingsAuthGrpcPrefix}); err != nil {
|
||||
return nil, nil, errors.Wrap(errGrpcConfig, err)
|
||||
}
|
||||
|
||||
c, ch, err := grpcClient.Setup(config, "things")
|
||||
c, ch, err := grpcclient.Setup(config, "things")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
jaegerp "go.opentelemetry.io/contrib/propagators/jaeger"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/exporters/jaeger"
|
||||
jaegerexp "go.opentelemetry.io/otel/exporters/jaeger"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
tracesdk "go.opentelemetry.io/otel/sdk/trace"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
|
||||
@@ -31,7 +31,7 @@ func NewProvider(svcName, url, instanceID string) (*tracesdk.TracerProvider, err
|
||||
return nil, errNoSvcName
|
||||
}
|
||||
|
||||
exporter, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url)))
|
||||
exporter, err := jaegerexp.New(jaegerexp.WithCollectorEndpoint(jaegerexp.WithEndpoint(url)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,11 +4,11 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
grpcClient "github.com/mainflux/mainflux/internal/clients/grpc"
|
||||
"github.com/mainflux/mainflux/internal/clients/grpc"
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
)
|
||||
|
||||
func Close(log mflog.Logger, clientHandler grpcClient.ClientHandler) {
|
||||
func Close(log mflog.Logger, clientHandler grpc.ClientHandler) {
|
||||
if err := clientHandler.Close(); err != nil {
|
||||
log.Warn(err.Error())
|
||||
}
|
||||
|
||||
Vendored
+1
-2
@@ -5,10 +5,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
|
||||
"github.com/mainflux/mainflux/internal/clients/grpc"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@ func (s *Server) Start() error {
|
||||
case err := <-errCh:
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) Stop() error {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
mfserver "github.com/mainflux/mainflux/internal/server"
|
||||
"github.com/mainflux/mainflux/internal/server"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
)
|
||||
|
||||
@@ -20,17 +20,17 @@ const (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
mfserver.BaseServer
|
||||
server.BaseServer
|
||||
server *http.Server
|
||||
}
|
||||
|
||||
var _ mfserver.Server = (*Server)(nil)
|
||||
var _ server.Server = (*Server)(nil)
|
||||
|
||||
func New(ctx context.Context, cancel context.CancelFunc, name string, config mfserver.Config, handler http.Handler, logger logger.Logger) mfserver.Server {
|
||||
func New(ctx context.Context, cancel context.CancelFunc, name string, config server.Config, handler http.Handler, logger logger.Logger) server.Server {
|
||||
listenFullAddress := fmt.Sprintf("%s:%s", config.Host, config.Port)
|
||||
server := &http.Server{Addr: listenFullAddress, Handler: handler}
|
||||
httpServer := &http.Server{Addr: listenFullAddress, Handler: handler}
|
||||
return &Server{
|
||||
BaseServer: mfserver.BaseServer{
|
||||
BaseServer: server.BaseServer{
|
||||
Ctx: ctx,
|
||||
Cancel: cancel,
|
||||
Name: name,
|
||||
@@ -38,7 +38,7 @@ func New(ctx context.Context, cancel context.CancelFunc, name string, config mfs
|
||||
Config: config,
|
||||
Logger: logger,
|
||||
},
|
||||
server: server,
|
||||
server: httpServer,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,12 @@ const (
|
||||
testFlagVal = "assert_test"
|
||||
)
|
||||
|
||||
var _ io.Writer = (*mockWriter)(nil)
|
||||
var logger mflog.Logger
|
||||
var err error
|
||||
var output logMsg
|
||||
var (
|
||||
_ io.Writer = (*mockWriter)(nil)
|
||||
logger mflog.Logger
|
||||
err error
|
||||
output logMsg
|
||||
)
|
||||
|
||||
type mockWriter struct {
|
||||
value []byte
|
||||
|
||||
+1
-2
@@ -7,10 +7,9 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/lora"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
)
|
||||
|
||||
// Subscriber represents the MQTT broker.
|
||||
|
||||
@@ -60,7 +60,6 @@ type handleFunc func(msg *messaging.Message) error
|
||||
|
||||
func (h handleFunc) Handle(msg *messaging.Message) error {
|
||||
return h(msg)
|
||||
|
||||
}
|
||||
|
||||
func (h handleFunc) Cancel() error {
|
||||
|
||||
+1
-4
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
"github.com/mainflux/mainflux/things/policies"
|
||||
|
||||
"github.com/mainflux/mproxy/pkg/session"
|
||||
)
|
||||
|
||||
@@ -63,8 +62,7 @@ type handler struct {
|
||||
}
|
||||
|
||||
// NewHandler creates new Handler entity.
|
||||
func NewHandler(publishers []messaging.Publisher, es redis.EventStore,
|
||||
logger logger.Logger, auth policies.AuthServiceClient) session.Handler {
|
||||
func NewHandler(publishers []messaging.Publisher, es redis.EventStore, logger logger.Logger, auth policies.AuthServiceClient) session.Handler {
|
||||
return &handler{
|
||||
es: es,
|
||||
logger: logger,
|
||||
@@ -135,7 +133,6 @@ func (h *handler) AuthSubscribe(ctx context.Context, topics *[]string) error {
|
||||
if err := h.authAccess(ctx, string(s.Password), v, policies.ReadAction); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -5,9 +5,7 @@ package redis
|
||||
|
||||
import "github.com/mainflux/mainflux/internal/clients/redis"
|
||||
|
||||
var (
|
||||
_ redis.Event = (*mqttEvent)(nil)
|
||||
)
|
||||
var _ redis.Event = (*mqttEvent)(nil)
|
||||
|
||||
type mqttEvent struct {
|
||||
clientID string
|
||||
|
||||
@@ -37,7 +37,7 @@ func New(config server.Config, tracer trace.Tracer, forwarder mqtt.Forwarder, to
|
||||
|
||||
// Forward traces mqtt forward operations.
|
||||
func (fm *forwarderMiddleware) Forward(ctx context.Context, id string, sub messaging.Subscriber, pub messaging.Publisher) error {
|
||||
var subject = fmt.Sprintf("channels.%s.messages", fm.topic)
|
||||
subject := fmt.Sprintf("channels.%s.messages", fm.topic)
|
||||
spanName := fmt.Sprintf("%s %s", subject, forwardOP)
|
||||
|
||||
ctx, span := fm.tracer.Start(ctx,
|
||||
|
||||
+4
-2
@@ -11,8 +11,10 @@ import (
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
)
|
||||
|
||||
const columns = 2
|
||||
const path = "/store/nodes.csv"
|
||||
const (
|
||||
columns = 2
|
||||
path = "/store/nodes.csv"
|
||||
)
|
||||
|
||||
var (
|
||||
errNotFound = errors.New("file not found")
|
||||
|
||||
+30
-30
@@ -6,9 +6,9 @@ package gopcua
|
||||
import (
|
||||
"context"
|
||||
|
||||
opcuaGopcua "github.com/gopcua/opcua"
|
||||
opcuagocpua "github.com/gopcua/opcua"
|
||||
"github.com/gopcua/opcua/id"
|
||||
uaGopcua "github.com/gopcua/opcua/ua"
|
||||
uagocpua "github.com/gopcua/opcua/ua"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/opcua"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
@@ -18,11 +18,11 @@ const maxChildrens = 4 // max browsing node children level
|
||||
|
||||
// NodeDef represents the node browser responnse.
|
||||
type NodeDef struct {
|
||||
NodeID *uaGopcua.NodeID
|
||||
NodeClass uaGopcua.NodeClass
|
||||
NodeID *uagocpua.NodeID
|
||||
NodeClass uagocpua.NodeClass
|
||||
BrowseName string
|
||||
Description string
|
||||
AccessLevel uaGopcua.AccessLevelType
|
||||
AccessLevel uagocpua.AccessLevelType
|
||||
Path string
|
||||
DataType string
|
||||
Writable bool
|
||||
@@ -48,11 +48,11 @@ func NewBrowser(ctx context.Context, log logger.Logger) opcua.Browser {
|
||||
}
|
||||
|
||||
func (c browser) Browse(serverURI, nodeID string) ([]opcua.BrowsedNode, error) {
|
||||
opts := []opcuaGopcua.Option{
|
||||
opcuaGopcua.SecurityMode(uaGopcua.MessageSecurityModeNone),
|
||||
opts := []opcuagocpua.Option{
|
||||
opcuagocpua.SecurityMode(uagocpua.MessageSecurityModeNone),
|
||||
}
|
||||
|
||||
oc := opcuaGopcua.NewClient(serverURI, opts...)
|
||||
oc := opcuagocpua.NewClient(serverURI, opts...)
|
||||
if err := oc.Connect(c.ctx); err != nil {
|
||||
return nil, errors.Wrap(errFailedConn, err)
|
||||
}
|
||||
@@ -79,67 +79,67 @@ func (c browser) Browse(serverURI, nodeID string) ([]opcua.BrowsedNode, error) {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func browse(oc *opcuaGopcua.Client, nodeID, path string, level int) ([]NodeDef, error) {
|
||||
func browse(oc *opcuagocpua.Client, nodeID, path string, level int) ([]NodeDef, error) {
|
||||
if level > maxChildrens {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
nid, err := uaGopcua.ParseNodeID(nodeID)
|
||||
nid, err := uagocpua.ParseNodeID(nodeID)
|
||||
if err != nil {
|
||||
return []NodeDef{}, err
|
||||
}
|
||||
n := oc.Node(nid)
|
||||
|
||||
attrs, err := n.Attributes(
|
||||
uaGopcua.AttributeIDNodeClass,
|
||||
uaGopcua.AttributeIDBrowseName,
|
||||
uaGopcua.AttributeIDDescription,
|
||||
uaGopcua.AttributeIDAccessLevel,
|
||||
uaGopcua.AttributeIDDataType,
|
||||
uagocpua.AttributeIDNodeClass,
|
||||
uagocpua.AttributeIDBrowseName,
|
||||
uagocpua.AttributeIDDescription,
|
||||
uagocpua.AttributeIDAccessLevel,
|
||||
uagocpua.AttributeIDDataType,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var def = NodeDef{
|
||||
def := NodeDef{
|
||||
NodeID: n.ID,
|
||||
}
|
||||
|
||||
switch err := attrs[0].Status; err {
|
||||
case uaGopcua.StatusOK:
|
||||
def.NodeClass = uaGopcua.NodeClass(attrs[0].Value.Int())
|
||||
case uagocpua.StatusOK:
|
||||
def.NodeClass = uagocpua.NodeClass(attrs[0].Value.Int())
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch err := attrs[1].Status; err {
|
||||
case uaGopcua.StatusOK:
|
||||
case uagocpua.StatusOK:
|
||||
def.BrowseName = attrs[1].Value.String()
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch err := attrs[2].Status; err {
|
||||
case uaGopcua.StatusOK:
|
||||
case uagocpua.StatusOK:
|
||||
def.Description = attrs[2].Value.String()
|
||||
case uaGopcua.StatusBadAttributeIDInvalid:
|
||||
case uagocpua.StatusBadAttributeIDInvalid:
|
||||
// ignore
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch err := attrs[3].Status; err {
|
||||
case uaGopcua.StatusOK:
|
||||
def.AccessLevel = uaGopcua.AccessLevelType(attrs[3].Value.Int())
|
||||
def.Writable = def.AccessLevel&uaGopcua.AccessLevelTypeCurrentWrite == uaGopcua.AccessLevelTypeCurrentWrite
|
||||
case uaGopcua.StatusBadAttributeIDInvalid:
|
||||
case uagocpua.StatusOK:
|
||||
def.AccessLevel = uagocpua.AccessLevelType(attrs[3].Value.Int())
|
||||
def.Writable = def.AccessLevel&uagocpua.AccessLevelTypeCurrentWrite == uagocpua.AccessLevelTypeCurrentWrite
|
||||
case uagocpua.StatusBadAttributeIDInvalid:
|
||||
// ignore
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch err := attrs[4].Status; err {
|
||||
case uaGopcua.StatusOK:
|
||||
case uagocpua.StatusOK:
|
||||
switch v := attrs[4].Value.NodeID().IntID(); v {
|
||||
case id.DateTime:
|
||||
def.DataType = "time.Time"
|
||||
@@ -168,7 +168,7 @@ func browse(oc *opcuaGopcua.Client, nodeID, path string, level int) ([]NodeDef,
|
||||
default:
|
||||
def.DataType = attrs[4].Value.NodeID().String()
|
||||
}
|
||||
case uaGopcua.StatusBadAttributeIDInvalid:
|
||||
case uagocpua.StatusBadAttributeIDInvalid:
|
||||
// ignore
|
||||
default:
|
||||
return nil, err
|
||||
@@ -177,7 +177,7 @@ func browse(oc *opcuaGopcua.Client, nodeID, path string, level int) ([]NodeDef,
|
||||
def.Path = join(path, def.BrowseName)
|
||||
|
||||
var nodes []NodeDef
|
||||
if def.NodeClass == uaGopcua.NodeClassVariable {
|
||||
if def.NodeClass == uagocpua.NodeClassVariable {
|
||||
nodes = append(nodes, def)
|
||||
}
|
||||
|
||||
@@ -202,9 +202,9 @@ func browse(oc *opcuaGopcua.Client, nodeID, path string, level int) ([]NodeDef,
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func browseChildren(c *opcuaGopcua.Client, n *opcuaGopcua.Node, path string, level int, typeDef uint32) ([]NodeDef, error) {
|
||||
func browseChildren(c *opcuagocpua.Client, n *opcuagocpua.Node, path string, level int, typeDef uint32) ([]NodeDef, error) {
|
||||
nodes := []NodeDef{}
|
||||
refs, err := n.ReferencedNodes(typeDef, uaGopcua.BrowseDirectionForward, uaGopcua.NodeClassAll, true)
|
||||
refs, err := n.ReferencedNodes(typeDef, uagocpua.BrowseDirectionForward, uagocpua.NodeClassAll, true)
|
||||
if err != nil {
|
||||
return []NodeDef{}, err
|
||||
}
|
||||
|
||||
+33
-31
@@ -9,16 +9,18 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
opcuaGopcua "github.com/gopcua/opcua"
|
||||
uaGopcua "github.com/gopcua/opcua/ua"
|
||||
opcuagopcua "github.com/gopcua/opcua"
|
||||
uagopcua "github.com/gopcua/opcua/ua"
|
||||
"github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/opcua"
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
)
|
||||
|
||||
const protocol = "opcua"
|
||||
const token = ""
|
||||
const (
|
||||
protocol = "opcua"
|
||||
token = ""
|
||||
)
|
||||
|
||||
var (
|
||||
errNotFoundServerURI = errors.New("route map not found for Server URI")
|
||||
@@ -69,32 +71,32 @@ func NewSubscriber(ctx context.Context, publisher messaging.Publisher, thingsRM,
|
||||
|
||||
// Subscribe subscribes to the OPC-UA Server.
|
||||
func (c client) Subscribe(ctx context.Context, cfg opcua.Config) error {
|
||||
opts := []opcuaGopcua.Option{
|
||||
opcuaGopcua.SecurityMode(uaGopcua.MessageSecurityModeNone),
|
||||
opts := []opcuagopcua.Option{
|
||||
opcuagopcua.SecurityMode(uagopcua.MessageSecurityModeNone),
|
||||
}
|
||||
|
||||
if cfg.Mode != "" {
|
||||
endpoints, err := opcuaGopcua.GetEndpoints(cfg.ServerURI)
|
||||
endpoints, err := opcuagopcua.GetEndpoints(cfg.ServerURI)
|
||||
if err != nil {
|
||||
return errors.Wrap(errFailedFetchEndpoint, err)
|
||||
}
|
||||
|
||||
ep := opcuaGopcua.SelectEndpoint(endpoints, cfg.Policy, uaGopcua.MessageSecurityModeFromString(cfg.Mode))
|
||||
ep := opcuagopcua.SelectEndpoint(endpoints, cfg.Policy, uagopcua.MessageSecurityModeFromString(cfg.Mode))
|
||||
if ep == nil {
|
||||
return errFailedFindEndpoint
|
||||
}
|
||||
|
||||
opts = []opcuaGopcua.Option{
|
||||
opcuaGopcua.SecurityPolicy(cfg.Policy),
|
||||
opcuaGopcua.SecurityModeString(cfg.Mode),
|
||||
opcuaGopcua.CertificateFile(cfg.CertFile),
|
||||
opcuaGopcua.PrivateKeyFile(cfg.KeyFile),
|
||||
opcuaGopcua.AuthAnonymous(),
|
||||
opcuaGopcua.SecurityFromEndpoint(ep, uaGopcua.UserTokenTypeAnonymous),
|
||||
opts = []opcuagopcua.Option{
|
||||
opcuagopcua.SecurityPolicy(cfg.Policy),
|
||||
opcuagopcua.SecurityModeString(cfg.Mode),
|
||||
opcuagopcua.CertificateFile(cfg.CertFile),
|
||||
opcuagopcua.PrivateKeyFile(cfg.KeyFile),
|
||||
opcuagopcua.AuthAnonymous(),
|
||||
opcuagopcua.SecurityFromEndpoint(ep, uagopcua.UserTokenTypeAnonymous),
|
||||
}
|
||||
}
|
||||
|
||||
oc := opcuaGopcua.NewClient(cfg.ServerURI, opts...)
|
||||
oc := opcuagopcua.NewClient(cfg.ServerURI, opts...)
|
||||
if err := oc.Connect(c.ctx); err != nil {
|
||||
return errors.Wrap(errFailedConn, err)
|
||||
}
|
||||
@@ -105,7 +107,7 @@ func (c client) Subscribe(ctx context.Context, cfg opcua.Config) error {
|
||||
return errors.Wrap(errFailedParseInterval, err)
|
||||
}
|
||||
|
||||
sub, err := oc.Subscribe(&opcuaGopcua.SubscriptionParameters{
|
||||
sub, err := oc.Subscribe(&opcuagopcua.SubscriptionParameters{
|
||||
Interval: time.Duration(i) * time.Millisecond,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -124,20 +126,20 @@ func (c client) Subscribe(ctx context.Context, cfg opcua.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c client) runHandler(ctx context.Context, sub *opcuaGopcua.Subscription, uri, node string) error {
|
||||
nodeID, err := uaGopcua.ParseNodeID(node)
|
||||
func (c client) runHandler(ctx context.Context, sub *opcuagopcua.Subscription, uri, node string) error {
|
||||
nodeID, err := uagopcua.ParseNodeID(node)
|
||||
if err != nil {
|
||||
return errors.Wrap(errFailedParseNodeID, err)
|
||||
}
|
||||
|
||||
// arbitrary client handle for the monitoring item
|
||||
handle := uint32(42)
|
||||
miCreateRequest := opcuaGopcua.NewMonitoredItemCreateRequestWithDefaults(nodeID, uaGopcua.AttributeIDValue, handle)
|
||||
res, err := sub.Monitor(uaGopcua.TimestampsToReturnBoth, miCreateRequest)
|
||||
miCreateRequest := opcuagopcua.NewMonitoredItemCreateRequestWithDefaults(nodeID, uagopcua.AttributeIDValue, handle)
|
||||
res, err := sub.Monitor(uagopcua.TimestampsToReturnBoth, miCreateRequest)
|
||||
if err != nil {
|
||||
return errors.Wrap(errFailedCreateReq, err)
|
||||
}
|
||||
if res.Results[0].StatusCode != uaGopcua.StatusOK {
|
||||
if res.Results[0].StatusCode != uagopcua.StatusOK {
|
||||
return errResponseStatus
|
||||
}
|
||||
|
||||
@@ -156,7 +158,7 @@ func (c client) runHandler(ctx context.Context, sub *opcuaGopcua.Subscription, u
|
||||
}
|
||||
|
||||
switch x := res.Value.(type) {
|
||||
case *uaGopcua.DataChangeNotification:
|
||||
case *uagopcua.DataChangeNotification:
|
||||
for _, item := range x.MonitoredItems {
|
||||
msg := message{
|
||||
ServerURI: uri,
|
||||
@@ -167,24 +169,24 @@ func (c client) runHandler(ctx context.Context, sub *opcuaGopcua.Subscription, u
|
||||
}
|
||||
|
||||
switch item.Value.Value.Type() {
|
||||
case uaGopcua.TypeIDBoolean:
|
||||
case uagopcua.TypeIDBoolean:
|
||||
msg.DataKey = "vb"
|
||||
msg.Data = item.Value.Value.Bool()
|
||||
case uaGopcua.TypeIDString, uaGopcua.TypeIDByteString:
|
||||
case uagopcua.TypeIDString, uagopcua.TypeIDByteString:
|
||||
msg.DataKey = "vs"
|
||||
msg.Data = item.Value.Value.String()
|
||||
case uaGopcua.TypeIDDataValue:
|
||||
case uagopcua.TypeIDDataValue:
|
||||
msg.DataKey = "vd"
|
||||
msg.Data = item.Value.Value.String()
|
||||
case uaGopcua.TypeIDInt64, uaGopcua.TypeIDInt32, uaGopcua.TypeIDInt16:
|
||||
case uagopcua.TypeIDInt64, uagopcua.TypeIDInt32, uagopcua.TypeIDInt16:
|
||||
msg.Data = float64(item.Value.Value.Int())
|
||||
case uaGopcua.TypeIDUint64, uaGopcua.TypeIDUint32, uaGopcua.TypeIDUint16:
|
||||
case uagopcua.TypeIDUint64, uagopcua.TypeIDUint32, uagopcua.TypeIDUint16:
|
||||
msg.Data = float64(item.Value.Value.Uint())
|
||||
case uaGopcua.TypeIDFloat, uaGopcua.TypeIDDouble:
|
||||
case uagopcua.TypeIDFloat, uagopcua.TypeIDDouble:
|
||||
msg.Data = item.Value.Value.Float()
|
||||
case uaGopcua.TypeIDByte:
|
||||
case uagopcua.TypeIDByte:
|
||||
msg.Data = float64(item.Value.Value.Uint())
|
||||
case uaGopcua.TypeIDDateTime:
|
||||
case uagopcua.TypeIDDateTime:
|
||||
msg.Data = item.Value.Value.Time().Unix()
|
||||
default:
|
||||
msg.Data = 0
|
||||
|
||||
@@ -68,7 +68,6 @@ type MembersPage struct {
|
||||
|
||||
// Repository specifies an account persistence API.
|
||||
type Repository interface {
|
||||
|
||||
// RetrieveByID retrieves client by its unique ID.
|
||||
RetrieveByID(ctx context.Context, id string) (Client, error)
|
||||
|
||||
|
||||
@@ -105,8 +105,8 @@ func TestClientsRetrieveAll(t *testing.T) {
|
||||
grepo := gpostgres.New(database)
|
||||
prepo := ppostgres.NewRepository(database)
|
||||
|
||||
var nClients = uint64(200)
|
||||
var ownerID = testsutil.GenerateUUID(t, idProvider)
|
||||
nClients := uint64(200)
|
||||
ownerID := testsutil.GenerateUUID(t, idProvider)
|
||||
|
||||
meta := mfclients.Metadata{
|
||||
"admin": "true",
|
||||
@@ -114,9 +114,9 @@ func TestClientsRetrieveAll(t *testing.T) {
|
||||
wrongMeta := mfclients.Metadata{
|
||||
"admin": "false",
|
||||
}
|
||||
var expectedClients = []mfclients.Client{}
|
||||
expectedClients := []mfclients.Client{}
|
||||
|
||||
var sharedGroup = mfgroups.Group{
|
||||
sharedGroup := mfgroups.Group{
|
||||
ID: testsutil.GenerateUUID(t, idProvider),
|
||||
Name: "shared-group",
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func TestClientsRetrieveAll(t *testing.T) {
|
||||
client, err = repo.Save(context.Background(), client)
|
||||
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
|
||||
expectedClients = append(expectedClients, client)
|
||||
var policy = policies.Policy{
|
||||
policy := policies.Policy{
|
||||
Subject: client.ID,
|
||||
Object: sharedGroup.ID,
|
||||
Actions: []string{"c_list"},
|
||||
@@ -218,7 +218,8 @@ func TestClientsRetrieveAll(t *testing.T) {
|
||||
Metadata: meta,
|
||||
Status: mfclients.AllStatus,
|
||||
},
|
||||
response: []mfclients.Client{expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
response: []mfclients.Client{
|
||||
expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
expectedClients[70], expectedClients[80], expectedClients[90], expectedClients[100], expectedClients[110], expectedClients[120], expectedClients[130],
|
||||
expectedClients[140], expectedClients[150], expectedClients[160], expectedClients[170], expectedClients[180], expectedClients[190],
|
||||
},
|
||||
@@ -265,7 +266,8 @@ func TestClientsRetrieveAll(t *testing.T) {
|
||||
Owner: ownerID,
|
||||
Status: mfclients.AllStatus,
|
||||
},
|
||||
response: []mfclients.Client{expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
response: []mfclients.Client{
|
||||
expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
expectedClients[70], expectedClients[80], expectedClients[90], expectedClients[100], expectedClients[110], expectedClients[120], expectedClients[130],
|
||||
expectedClients[140], expectedClients[150], expectedClients[160], expectedClients[170], expectedClients[180], expectedClients[190],
|
||||
},
|
||||
@@ -291,7 +293,8 @@ func TestClientsRetrieveAll(t *testing.T) {
|
||||
Action: "c_list",
|
||||
Status: mfclients.AllStatus,
|
||||
},
|
||||
response: []mfclients.Client{expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
response: []mfclients.Client{
|
||||
expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
expectedClients[70], expectedClients[80], expectedClients[90], expectedClients[100], expectedClients[110], expectedClients[120], expectedClients[130],
|
||||
expectedClients[140], expectedClients[150], expectedClients[160], expectedClients[170], expectedClients[180], expectedClients[190],
|
||||
},
|
||||
@@ -306,7 +309,8 @@ func TestClientsRetrieveAll(t *testing.T) {
|
||||
Owner: ownerID,
|
||||
Status: mfclients.AllStatus,
|
||||
},
|
||||
response: []mfclients.Client{expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
response: []mfclients.Client{
|
||||
expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
expectedClients[70], expectedClients[80], expectedClients[90], expectedClients[100], expectedClients[110], expectedClients[120], expectedClients[130],
|
||||
expectedClients[140], expectedClients[150], expectedClients[160], expectedClients[170], expectedClients[180], expectedClients[190],
|
||||
},
|
||||
@@ -350,7 +354,8 @@ func TestClientsRetrieveAll(t *testing.T) {
|
||||
Tag: "Test",
|
||||
Status: mfclients.AllStatus,
|
||||
},
|
||||
response: []mfclients.Client{expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
response: []mfclients.Client{
|
||||
expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
expectedClients[70], expectedClients[80], expectedClients[90], expectedClients[100], expectedClients[110], expectedClients[120], expectedClients[130],
|
||||
expectedClients[140], expectedClients[150], expectedClients[160], expectedClients[170], expectedClients[180], expectedClients[190],
|
||||
},
|
||||
@@ -376,7 +381,8 @@ func TestClientsRetrieveAll(t *testing.T) {
|
||||
Status: mfclients.AllStatus,
|
||||
Action: "c_list",
|
||||
},
|
||||
response: []mfclients.Client{expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
response: []mfclients.Client{
|
||||
expectedClients[0], expectedClients[10], expectedClients[20], expectedClients[30], expectedClients[40], expectedClients[50], expectedClients[60],
|
||||
expectedClients[70], expectedClients[80], expectedClients[90], expectedClients[100], expectedClients[110], expectedClients[120], expectedClients[130],
|
||||
expectedClients[140], expectedClients[150], expectedClients[160], expectedClients[170], expectedClients[180], expectedClients[190],
|
||||
},
|
||||
|
||||
@@ -33,10 +33,8 @@ const (
|
||||
Unknown = "unknown"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrStatusAlreadyAssigned indicated that the client or group has already been assigned the status.
|
||||
ErrStatusAlreadyAssigned = errors.New("status already assigned")
|
||||
)
|
||||
// ErrStatusAlreadyAssigned indicated that the client or group has already been assigned the status.
|
||||
var ErrStatusAlreadyAssigned = errors.New("status already assigned")
|
||||
|
||||
// String converts client/group status to string literal.
|
||||
func (s Status) String() string {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/mainflux/mainflux/pkg/errors"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -121,7 +120,6 @@ func TestContains(t *testing.T) {
|
||||
contains := errors.Contains(tc.container, tc.contained)
|
||||
assert.Equal(t, tc.contains, contains, fmt.Sprintf("%s: expected %v to contain %v\n", tc.desc, tc.container, tc.contained))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestWrap(t *testing.T) {
|
||||
|
||||
@@ -12,10 +12,8 @@ import (
|
||||
|
||||
const errorKey = "error"
|
||||
|
||||
var (
|
||||
// Failed to read response body.
|
||||
errRespBody = New("failed to read response body")
|
||||
)
|
||||
// Failed to read response body.
|
||||
var errRespBody = New("failed to read response body")
|
||||
|
||||
// SDKError is an error type for Mainflux SDK.
|
||||
type SDKError interface {
|
||||
@@ -86,7 +84,6 @@ func CheckError(resp *http.Response, expectedStatusCodes ...int) SDKError {
|
||||
if msg, ok := content[errorKey]; ok {
|
||||
if v, ok := msg.(string); ok {
|
||||
return NewSDKErrorWithStatus(New(v), resp.StatusCode)
|
||||
|
||||
}
|
||||
return NewSDKErrorWithStatus(fmt.Errorf("%v", msg), resp.StatusCode)
|
||||
}
|
||||
|
||||
@@ -274,6 +274,7 @@ func buildHierachy(gm mfgroups.GroupsPage) string {
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
func buildQuery(gm mfgroups.GroupsPage) (string, error) {
|
||||
queries := []string{}
|
||||
|
||||
|
||||
@@ -168,7 +168,6 @@ func TestGroupSave(t *testing.T) {
|
||||
_, err := groupRepo.Save(context.Background(), tc.group)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestGroupRetrieveByID(t *testing.T) {
|
||||
@@ -223,8 +222,8 @@ func TestGroupRetrieveAll(t *testing.T) {
|
||||
t.Cleanup(func() { testsutil.CleanUpDB(t, db) })
|
||||
groupRepo := gpostgres.New(database)
|
||||
|
||||
var nGroups = uint64(200)
|
||||
var ownerID = testsutil.GenerateUUID(t, idProvider)
|
||||
nGroups := uint64(200)
|
||||
ownerID := testsutil.GenerateUUID(t, idProvider)
|
||||
var parentID string
|
||||
for i := uint64(0); i < nGroups; i++ {
|
||||
creationTime := time.Now().UTC()
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
pgClient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
pgclient "github.com/mainflux/mainflux/internal/clients/postgres"
|
||||
"github.com/mainflux/mainflux/internal/postgres"
|
||||
upostgres "github.com/mainflux/mainflux/users/postgres"
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3/docker"
|
||||
"go.opentelemetry.io/otel"
|
||||
)
|
||||
@@ -64,7 +64,7 @@ func TestMain(m *testing.M) {
|
||||
log.Fatalf("Could not connect to docker: %s", err)
|
||||
}
|
||||
|
||||
dbConfig := pgClient.Config{
|
||||
dbConfig := pgclient.Config{
|
||||
Host: "localhost",
|
||||
Port: port,
|
||||
User: "test",
|
||||
@@ -76,7 +76,7 @@ func TestMain(m *testing.M) {
|
||||
SSLRootCert: "",
|
||||
}
|
||||
|
||||
if db, err = pgClient.SetupDB(dbConfig, *upostgres.Migration()); err != nil {
|
||||
if db, err = pgclient.SetupDB(dbConfig, *upostgres.Migration()); err != nil {
|
||||
log.Fatalf("Could not setup test DB connection: %s", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
mqtt_pubsub "github.com/mainflux/mainflux/pkg/messaging/mqtt"
|
||||
mqttpubsub "github.com/mainflux/mainflux/pkg/messaging/mqtt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@@ -25,9 +25,7 @@ const (
|
||||
tokenTimeout = 100 * time.Millisecond
|
||||
)
|
||||
|
||||
var (
|
||||
data = []byte("payload")
|
||||
)
|
||||
var data = []byte("payload")
|
||||
|
||||
// ErrFailedHandleMessage indicates that the message couldn't be handled.
|
||||
var errFailedHandleMessage = errors.New("failed to handle mainflux message")
|
||||
@@ -65,7 +63,7 @@ func TestPublisher(t *testing.T) {
|
||||
|
||||
// Test publish with an empty topic.
|
||||
err = pubsub.Publish(context.TODO(), "", &messaging.Message{Payload: data})
|
||||
assert.Equal(t, err, mqtt_pubsub.ErrEmptyTopic, fmt.Sprintf("Publish with empty topic: expected: %s, got: %s", mqtt_pubsub.ErrEmptyTopic, err))
|
||||
assert.Equal(t, err, mqttpubsub.ErrEmptyTopic, fmt.Sprintf("Publish with empty topic: expected: %s, got: %s", mqttpubsub.ErrEmptyTopic, err))
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -175,14 +173,14 @@ func TestSubscribe(t *testing.T) {
|
||||
desc: "Subscribe to an empty topic with an ID",
|
||||
topic: "",
|
||||
clientID: "clientid1",
|
||||
err: mqtt_pubsub.ErrEmptyTopic,
|
||||
err: mqttpubsub.ErrEmptyTopic,
|
||||
handler: handler{false, "clientid1", msgChan},
|
||||
},
|
||||
{
|
||||
desc: "Subscribe to a topic with empty id",
|
||||
topic: topic,
|
||||
clientID: "",
|
||||
err: mqtt_pubsub.ErrEmptyID,
|
||||
err: mqttpubsub.ErrEmptyID,
|
||||
handler: handler{false, "", msgChan},
|
||||
},
|
||||
}
|
||||
@@ -250,14 +248,14 @@ func TestPubSub(t *testing.T) {
|
||||
desc: "Subscribe to an empty topic with an ID",
|
||||
topic: "",
|
||||
clientID: "clientid7",
|
||||
err: mqtt_pubsub.ErrEmptyTopic,
|
||||
err: mqttpubsub.ErrEmptyTopic,
|
||||
handler: handler{false, "clientid7", msgChan},
|
||||
},
|
||||
{
|
||||
desc: "Subscribe to a topic with empty id",
|
||||
topic: topic,
|
||||
clientID: "",
|
||||
err: mqtt_pubsub.ErrEmptyID,
|
||||
err: mqttpubsub.ErrEmptyID,
|
||||
handler: handler{false, "", msgChan},
|
||||
},
|
||||
}
|
||||
@@ -336,7 +334,7 @@ func TestUnsubscribe(t *testing.T) {
|
||||
desc: "Unsubscribe from a non-existent topic with an ID",
|
||||
topic: "h",
|
||||
clientID: "clientid4",
|
||||
err: mqtt_pubsub.ErrNotSubscribed,
|
||||
err: mqttpubsub.ErrNotSubscribed,
|
||||
subscribe: false,
|
||||
handler: handler{false, "clientid4", msgChan},
|
||||
},
|
||||
@@ -344,7 +342,7 @@ func TestUnsubscribe(t *testing.T) {
|
||||
desc: "Unsubscribe from an already unsubscribed topic with an ID",
|
||||
topic: fmt.Sprintf("%s.%s", chansPrefix, topic),
|
||||
clientID: "clientid4",
|
||||
err: mqtt_pubsub.ErrNotSubscribed,
|
||||
err: mqttpubsub.ErrNotSubscribed,
|
||||
subscribe: false,
|
||||
handler: handler{false, "clientid4", msgChan},
|
||||
},
|
||||
@@ -368,7 +366,7 @@ func TestUnsubscribe(t *testing.T) {
|
||||
desc: "Unsubscribe from an already unsubscribed topic with a subtopic with an ID",
|
||||
topic: fmt.Sprintf("%s.%s.%s", chansPrefix, topic, subtopic),
|
||||
clientID: "clientid4",
|
||||
err: mqtt_pubsub.ErrNotSubscribed,
|
||||
err: mqttpubsub.ErrNotSubscribed,
|
||||
subscribe: false,
|
||||
handler: handler{false, "clientid4", msgChan},
|
||||
},
|
||||
@@ -376,7 +374,7 @@ func TestUnsubscribe(t *testing.T) {
|
||||
desc: "Unsubscribe from an empty topic with an ID",
|
||||
topic: "",
|
||||
clientID: "clientid4",
|
||||
err: mqtt_pubsub.ErrEmptyTopic,
|
||||
err: mqttpubsub.ErrEmptyTopic,
|
||||
subscribe: false,
|
||||
handler: handler{false, "clientid4", msgChan},
|
||||
},
|
||||
@@ -384,7 +382,7 @@ func TestUnsubscribe(t *testing.T) {
|
||||
desc: "Unsubscribe from a topic with empty ID",
|
||||
topic: fmt.Sprintf("%s.%s", chansPrefix, topic),
|
||||
clientID: "",
|
||||
err: mqtt_pubsub.ErrEmptyID,
|
||||
err: mqttpubsub.ErrEmptyID,
|
||||
subscribe: false,
|
||||
handler: handler{false, "", msgChan},
|
||||
},
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
mqtt_pubsub "github.com/mainflux/mainflux/pkg/messaging/mqtt"
|
||||
mqttpubsub "github.com/mainflux/mainflux/pkg/messaging/mqtt"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
if err := pool.Retry(func() error {
|
||||
pubsub, err = mqtt_pubsub.NewPubSub(address, "mainflux", brokerTimeout, logger)
|
||||
pubsub, err = mqttpubsub.NewPubSub(address, "mainflux", brokerTimeout, logger)
|
||||
return err
|
||||
}); err != nil {
|
||||
log.Fatalf("Could not connect to docker: %s", err)
|
||||
@@ -104,7 +104,7 @@ func newClient(address, id string, timeout time.Duration) (mqtt.Client, error) {
|
||||
|
||||
ok := token.WaitTimeout(timeout)
|
||||
if !ok {
|
||||
return nil, mqtt_pubsub.ErrConnect
|
||||
return nil, mqttpubsub.ErrConnect
|
||||
}
|
||||
|
||||
if token.Error() != nil {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user