Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Change import name aliases #1868

Merged
merged 21 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bootstrap/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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})

Expand Down Expand Up @@ -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: "",
Expand Down
1 change: 0 additions & 1 deletion bootstrap/mocks/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion bootstrap/mocks/things.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions bootstrap/postgres/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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",
Expand All @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion bootstrap/redis/producer/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions bootstrap/redis/producer/streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion bootstrap/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion certs/mocks/things.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions certs/postgres/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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",
Expand All @@ -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))
}

Expand Down
2 changes: 0 additions & 2 deletions certs/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion cli/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ var cmdBootstrap = []cobra.Command{
return
}
logUsage(cmd.Use)

},
},
{
Expand Down
4 changes: 2 additions & 2 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions cli/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var cmdPolicies = []cobra.Command{
return
}

var policy = mfxsdk.Policy{
policy := mfxsdk.Policy{
Subject: args[1],
Object: args[2],
Actions: actions,
Expand Down Expand Up @@ -76,7 +76,7 @@ var cmdPolicies = []cobra.Command{
return
}

var policy = mfxsdk.Policy{
policy := mfxsdk.Policy{
Subject: args[1],
Object: args[2],
Actions: actions,
Expand Down Expand Up @@ -150,7 +150,7 @@ var cmdPolicies = []cobra.Command{
return
}

var policy = mfxsdk.Policy{
policy := mfxsdk.Policy{
Subject: args[1],
Object: args[2],
}
Expand Down Expand Up @@ -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],
Expand Down
6 changes: 4 additions & 2 deletions cli/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import (
"github.com/spf13/cobra"
)

const jsonExt = ".json"
const csvExt = ".csv"
const (
jsonExt = ".json"
csvExt = ".csv"
)

var cmdProvision = []cobra.Command{
{
Expand Down
2 changes: 0 additions & 2 deletions cli/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ var cmdUsers = []cobra.Command{
}

logJSON(token)

},
},
{
Expand All @@ -134,7 +133,6 @@ var cmdUsers = []cobra.Command{
}

logJSON(token)

},
},
{
Expand Down
2 changes: 1 addition & 1 deletion cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/fatih/color"
prettyjson "github.com/hokaccha/go-prettyjson"
"github.com/hokaccha/go-prettyjson"
)

var (
Expand Down
36 changes: 18 additions & 18 deletions cmd/bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pgclient and redis client are needed

"github.com/mainflux/mainflux/internal/env"
"github.com/mainflux/mainflux/internal/postgres"
"github.com/mainflux/mainflux/internal/server"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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())
}
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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))
Expand Down
Loading