From f0d014eba278adc08291f27f90e29d0f1105e196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Borov=C4=8Danin?= Date: Thu, 19 Dec 2024 18:29:53 +0100 Subject: [PATCH] NOISSUE - Move API to the common package (#2608) Signed-off-by: Dusan Borovcanin --- {internal/api => api}/doc.go | 2 +- internal/api/auth.go => api/http/authn.go | 15 +-- {internal/api => api/http}/common.go | 4 +- {internal/api => api/http}/common_test.go | 6 +- api/http/doc.go | 6 ++ {pkg/apiutil => api/http/util}/errors.go | 2 +- {pkg/apiutil => api/http/util}/responses.go | 2 +- {pkg/apiutil => api/http/util}/token.go | 2 +- {pkg/apiutil => api/http/util}/token_test.go | 4 +- {pkg/apiutil => api/http/util}/transport.go | 2 +- .../http/util}/transport_test.go | 4 +- {api => apidocs}/asyncapi/mqtt.yml | 0 {api => apidocs}/asyncapi/websocket.yml | 0 {api => apidocs}/openapi/README.md | 0 {api => apidocs}/openapi/auth.yml | 0 {api => apidocs}/openapi/bootstrap.yml | 0 {api => apidocs}/openapi/certs.yml | 0 {api => apidocs}/openapi/channels.yml | 0 {api => apidocs}/openapi/clients.yml | 0 {api => apidocs}/openapi/domains.yml | 0 {api => apidocs}/openapi/groups.yml | 0 {api => apidocs}/openapi/http.yml | 0 {api => apidocs}/openapi/invitations.yml | 0 {api => apidocs}/openapi/journal.yml | 0 {api => apidocs}/openapi/notifiers.yml | 0 {api => apidocs}/openapi/provision.yml | 0 {api => apidocs}/openapi/readers.yml | 0 .../openapi/schemas/health_info.yml | 0 {api => apidocs}/openapi/schemas/roles.yml | 0 {api => apidocs}/openapi/twins.yml | 0 {api => apidocs}/openapi/users.yml | 12 +-- auth/api/grpc/auth/endpoint_test.go | 2 +- auth/api/grpc/auth/requests.go | 2 +- auth/api/grpc/token/endpoint_test.go | 2 +- auth/api/grpc/token/requests.go | 2 +- auth/api/grpc/utils.go | 2 +- auth/api/http/keys/endpoint_test.go | 2 +- auth/api/http/keys/requests.go | 2 +- auth/api/http/keys/requests_test.go | 2 +- auth/api/http/keys/transport.go | 4 +- auth/api/http/pats/requests.go | 2 +- auth/api/http/pats/transport.go | 4 +- bootstrap/api/endpoint.go | 4 +- bootstrap/api/endpoint_test.go | 2 +- bootstrap/api/requests.go | 2 +- bootstrap/api/requests_test.go | 2 +- bootstrap/api/transport.go | 4 +- certs/api/endpoint.go | 2 +- certs/api/endpoint_test.go | 6 +- certs/api/requests.go | 2 +- certs/api/transport.go | 4 +- channels/api/grpc/server.go | 2 +- channels/api/http/decode.go | 4 +- channels/api/http/endpoint_test.go | 6 +- channels/api/http/endpoints.go | 4 +- channels/api/http/requests.go | 4 +- channels/api/http/requests_test.go | 4 +- channels/api/http/transport.go | 4 +- channels/postgres/channels.go | 4 +- channels/service.go | 2 +- channels/service_test.go | 2 +- cli/clients_test.go | 2 +- cli/provision.go | 4 +- cli/users.go | 4 +- cli/users_test.go | 4 +- clients/api/grpc/server.go | 2 +- clients/api/http/clients.go | 4 +- clients/api/http/decode.go | 4 +- clients/api/http/endpoints.go | 4 +- clients/api/http/endpoints_test.go | 8 +- clients/api/http/requests.go | 4 +- clients/api/http/requests_test.go | 4 +- clients/postgres/clients.go | 4 +- clients/roles.go | 2 +- clients/roles_test.go | 2 +- clients/service.go | 2 +- clients/service_test.go | 2 +- cmd/bootstrap/main.go | 4 +- cmd/certs/main.go | 8 +- cmd/coap/main.go | 10 +- cmd/http/main.go | 8 +- cmd/invitations/main.go | 4 +- cmd/journal/main.go | 4 +- cmd/postgres-reader/main.go | 8 +- cmd/postgres-writer/main.go | 8 +- cmd/provision/main.go | 6 +- cmd/timescale-reader/main.go | 8 +- cmd/timescale-writer/main.go | 8 +- cmd/users/main.go | 4 +- cmd/ws/main.go | 12 +-- consumers/messages.go | 2 +- consumers/notifiers/api/endpoint.go | 2 +- consumers/notifiers/api/endpoint_test.go | 6 +- consumers/notifiers/api/requests.go | 2 +- consumers/notifiers/api/transport.go | 4 +- docker/Dockerfile.livereload | 6 -- docker/docker-compose-live.yaml | 96 ------------------- domains/api/grpc/endpoint_test.go | 2 +- domains/api/grpc/requests.go | 2 +- domains/api/http/decode.go | 4 +- domains/api/http/endpoint.go | 4 +- domains/api/http/endpoint_test.go | 8 +- domains/api/http/requests.go | 2 +- domains/api/http/transport.go | 4 +- domains/postgres/domains.go | 2 +- groups/api/grpc/server.go | 2 +- groups/api/http/decode.go | 4 +- groups/api/http/decode_test.go | 4 +- groups/api/http/endpoint_test.go | 6 +- groups/api/http/endpoints.go | 4 +- groups/api/http/requests.go | 4 +- groups/api/http/requests_test.go | 4 +- groups/api/http/transport.go | 4 +- groups/service.go | 2 +- groups/service_test.go | 2 +- http/api/endpoint.go | 2 +- http/api/endpoint_test.go | 2 +- http/api/request.go | 2 +- http/api/transport.go | 4 +- http/handler.go | 2 +- http/handler_test.go | 2 +- invitations/api/endpoint.go | 4 +- invitations/api/endpoint_test.go | 2 +- invitations/api/requests.go | 2 +- invitations/api/requests_test.go | 2 +- invitations/api/transport.go | 4 +- invitations/invitations.go | 2 +- invitations/invitations_test.go | 2 +- invitations/service_test.go | 2 +- invitations/state.go | 2 +- invitations/state_test.go | 2 +- journal/api/endpoint.go | 4 +- journal/api/endpoint_test.go | 2 +- journal/api/requests.go | 4 +- journal/api/requests_test.go | 4 +- journal/api/transport.go | 4 +- journal/journal.go | 2 +- journal/journal_test.go | 2 +- pkg/roles/repo/postgres/roles.go | 2 +- pkg/roles/rolemanager/api/decoders.go | 4 +- pkg/roles/rolemanager/api/endpoints.go | 4 +- pkg/roles/rolemanager/api/requests.go | 4 +- pkg/roles/rolemanager/api/router.go | 2 +- pkg/sdk/bootstrap.go | 2 +- pkg/sdk/bootstrap_test.go | 2 +- pkg/sdk/certs.go | 2 +- pkg/sdk/certs_test.go | 2 +- pkg/sdk/channels.go | 2 +- pkg/sdk/channels_test.go | 2 +- pkg/sdk/clients.go | 2 +- pkg/sdk/clients_test.go | 2 +- pkg/sdk/consumers_test.go | 2 +- pkg/sdk/domains.go | 2 +- pkg/sdk/domains_test.go | 20 ++-- pkg/sdk/groups.go | 2 +- pkg/sdk/groups_test.go | 2 +- pkg/sdk/invitations_test.go | 2 +- pkg/sdk/journal.go | 2 +- pkg/sdk/journal_test.go | 2 +- pkg/sdk/message.go | 2 +- pkg/sdk/message_test.go | 2 +- pkg/sdk/tokens.go | 4 +- pkg/sdk/tokens_test.go | 26 ++--- pkg/sdk/users.go | 2 +- pkg/sdk/users_test.go | 40 ++++---- pkg/server/coap/coap.go | 2 +- provision/api/endpoint.go | 2 +- provision/api/endpoint_test.go | 2 +- provision/api/requests.go | 2 +- provision/api/requests_test.go | 2 +- provision/api/transport.go | 4 +- provision/service.go | 4 +- provision/service_test.go | 4 +- readers/api/endpoint.go | 2 +- readers/api/endpoint_test.go | 2 +- readers/api/requests.go | 2 +- readers/api/transport.go | 2 +- tools/config/golangci.yml | 5 +- tools/e2e/e2e.go | 8 +- tools/provision/provision.go | 6 +- users/api/endpoint_test.go | 21 ++-- users/api/endpoints.go | 6 +- users/api/requests.go | 12 +-- users/api/requests_test.go | 16 ++-- users/api/users.go | 4 +- users/postgres/users.go | 2 +- users/roles.go | 2 +- users/service.go | 2 +- ws/handler.go | 2 +- 189 files changed, 351 insertions(+), 448 deletions(-) rename {internal/api => api}/doc.go (83%) rename internal/api/auth.go => api/http/authn.go (75%) rename {internal/api => api/http}/common.go (99%) rename {internal/api => api/http}/common_test.go (98%) create mode 100644 api/http/doc.go rename {pkg/apiutil => api/http/util}/errors.go (99%) rename {pkg/apiutil => api/http/util}/responses.go (92%) rename {pkg/apiutil => api/http/util}/token.go (98%) rename {pkg/apiutil => api/http/util}/token_test.go (96%) rename {pkg/apiutil => api/http/util}/transport.go (99%) rename {pkg/apiutil => api/http/util}/transport_test.go (99%) rename {api => apidocs}/asyncapi/mqtt.yml (100%) rename {api => apidocs}/asyncapi/websocket.yml (100%) rename {api => apidocs}/openapi/README.md (100%) rename {api => apidocs}/openapi/auth.yml (100%) rename {api => apidocs}/openapi/bootstrap.yml (100%) rename {api => apidocs}/openapi/certs.yml (100%) rename {api => apidocs}/openapi/channels.yml (100%) rename {api => apidocs}/openapi/clients.yml (100%) rename {api => apidocs}/openapi/domains.yml (100%) rename {api => apidocs}/openapi/groups.yml (100%) rename {api => apidocs}/openapi/http.yml (100%) rename {api => apidocs}/openapi/invitations.yml (100%) rename {api => apidocs}/openapi/journal.yml (100%) rename {api => apidocs}/openapi/notifiers.yml (100%) rename {api => apidocs}/openapi/provision.yml (100%) rename {api => apidocs}/openapi/readers.yml (100%) rename {api => apidocs}/openapi/schemas/health_info.yml (100%) rename {api => apidocs}/openapi/schemas/roles.yml (100%) rename {api => apidocs}/openapi/twins.yml (100%) rename {api => apidocs}/openapi/users.yml (99%) delete mode 100644 docker/Dockerfile.livereload delete mode 100644 docker/docker-compose-live.yaml diff --git a/internal/api/doc.go b/api/doc.go similarity index 83% rename from internal/api/doc.go rename to api/doc.go index 6bffadcf7..415ce7958 100644 --- a/internal/api/doc.go +++ b/api/doc.go @@ -2,5 +2,5 @@ // SPDX-License-Identifier: Apache-2.0 // Package api contains commonly used constants and functions -// for the HTTP endpoints. +// for the HTTP and gRPC API. package api diff --git a/internal/api/auth.go b/api/http/authn.go similarity index 75% rename from internal/api/auth.go rename to api/http/authn.go index 107b5207a..b45197e75 100644 --- a/internal/api/auth.go +++ b/api/http/authn.go @@ -1,23 +1,20 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package api +package http import ( "context" "net/http" - "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/go-chi/chi/v5" ) type sessionKeyType string -const ( - SessionKey = sessionKeyType("session") -) +const SessionKey = sessionKeyType("session") func AuthenticateMiddleware(authn smqauthn.Authentication, domainCheck bool) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { @@ -27,10 +24,8 @@ func AuthenticateMiddleware(authn smqauthn.Authentication, domainCheck bool) fun EncodeError(r.Context(), apiutil.ErrBearerToken, w) return } - var resp smqauthn.Session - var err error - resp, err = authn.Authenticate(r.Context(), token) + resp, err := authn.Authenticate(r.Context(), token) if err != nil { EncodeError(r.Context(), err, w) return @@ -43,7 +38,7 @@ func AuthenticateMiddleware(authn smqauthn.Authentication, domainCheck bool) fun return } resp.DomainID = domain - resp.DomainUserID = auth.EncodeDomainUserID(domain, resp.UserID) + resp.DomainUserID = domain + "_" + resp.UserID } ctx := context.WithValue(r.Context(), SessionKey, resp) diff --git a/internal/api/common.go b/api/http/common.go similarity index 99% rename from internal/api/common.go rename to api/http/common.go index 9f28ac852..dd3e0ce58 100644 --- a/internal/api/common.go +++ b/api/http/common.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package api +package http import ( "context" @@ -9,11 +9,11 @@ import ( "net/http" "github.com/absmach/supermq" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/bootstrap" "github.com/absmach/supermq/certs" "github.com/absmach/supermq/clients" "github.com/absmach/supermq/groups" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/absmach/supermq/users" diff --git a/internal/api/common_test.go b/api/http/common_test.go similarity index 98% rename from internal/api/common_test.go rename to api/http/common_test.go index e1a945e4c..c6b2fcce8 100644 --- a/internal/api/common_test.go +++ b/api/http/common_test.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package api_test +package http_test import ( "context" @@ -11,9 +11,9 @@ import ( "time" "github.com/absmach/supermq" - "github.com/absmach/supermq/internal/api" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/stretchr/testify/assert" diff --git a/api/http/doc.go b/api/http/doc.go new file mode 100644 index 000000000..cf7d39378 --- /dev/null +++ b/api/http/doc.go @@ -0,0 +1,6 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package api contains commonly used constants and functions +// for the HTTP API. +package http diff --git a/pkg/apiutil/errors.go b/api/http/util/errors.go similarity index 99% rename from pkg/apiutil/errors.go rename to api/http/util/errors.go index 3e6bc34cc..e4b05abf7 100644 --- a/pkg/apiutil/errors.go +++ b/api/http/util/errors.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package apiutil +package util import "github.com/absmach/supermq/pkg/errors" diff --git a/pkg/apiutil/responses.go b/api/http/util/responses.go similarity index 92% rename from pkg/apiutil/responses.go rename to api/http/util/responses.go index 9b032d7cd..b154c5cf7 100644 --- a/pkg/apiutil/responses.go +++ b/api/http/util/responses.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package apiutil +package util // ErrorRes represents the HTTP error response body. type ErrorRes struct { diff --git a/pkg/apiutil/token.go b/api/http/util/token.go similarity index 98% rename from pkg/apiutil/token.go rename to api/http/util/token.go index d0ff3589d..2dbae36af 100644 --- a/pkg/apiutil/token.go +++ b/api/http/util/token.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package apiutil +package util import ( "net/http" diff --git a/pkg/apiutil/token_test.go b/api/http/util/token_test.go similarity index 96% rename from pkg/apiutil/token_test.go rename to api/http/util/token_test.go index d23530f47..c21d1000e 100644 --- a/pkg/apiutil/token_test.go +++ b/api/http/util/token_test.go @@ -1,13 +1,13 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package apiutil_test +package util_test import ( "net/http" "testing" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/stretchr/testify/assert" ) diff --git a/pkg/apiutil/transport.go b/api/http/util/transport.go similarity index 99% rename from pkg/apiutil/transport.go rename to api/http/util/transport.go index 1ee479139..fb78ee2a6 100644 --- a/pkg/apiutil/transport.go +++ b/api/http/util/transport.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package apiutil +package util import ( "context" diff --git a/pkg/apiutil/transport_test.go b/api/http/util/transport_test.go similarity index 99% rename from pkg/apiutil/transport_test.go rename to api/http/util/transport_test.go index 40a11c3d9..cc8a59a95 100644 --- a/pkg/apiutil/transport_test.go +++ b/api/http/util/transport_test.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package apiutil_test +package util_test import ( "context" @@ -11,8 +11,8 @@ import ( "net/url" "testing" + apiutil "github.com/absmach/supermq/api/http/util" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/stretchr/testify/assert" diff --git a/api/asyncapi/mqtt.yml b/apidocs/asyncapi/mqtt.yml similarity index 100% rename from api/asyncapi/mqtt.yml rename to apidocs/asyncapi/mqtt.yml diff --git a/api/asyncapi/websocket.yml b/apidocs/asyncapi/websocket.yml similarity index 100% rename from api/asyncapi/websocket.yml rename to apidocs/asyncapi/websocket.yml diff --git a/api/openapi/README.md b/apidocs/openapi/README.md similarity index 100% rename from api/openapi/README.md rename to apidocs/openapi/README.md diff --git a/api/openapi/auth.yml b/apidocs/openapi/auth.yml similarity index 100% rename from api/openapi/auth.yml rename to apidocs/openapi/auth.yml diff --git a/api/openapi/bootstrap.yml b/apidocs/openapi/bootstrap.yml similarity index 100% rename from api/openapi/bootstrap.yml rename to apidocs/openapi/bootstrap.yml diff --git a/api/openapi/certs.yml b/apidocs/openapi/certs.yml similarity index 100% rename from api/openapi/certs.yml rename to apidocs/openapi/certs.yml diff --git a/api/openapi/channels.yml b/apidocs/openapi/channels.yml similarity index 100% rename from api/openapi/channels.yml rename to apidocs/openapi/channels.yml diff --git a/api/openapi/clients.yml b/apidocs/openapi/clients.yml similarity index 100% rename from api/openapi/clients.yml rename to apidocs/openapi/clients.yml diff --git a/api/openapi/domains.yml b/apidocs/openapi/domains.yml similarity index 100% rename from api/openapi/domains.yml rename to apidocs/openapi/domains.yml diff --git a/api/openapi/groups.yml b/apidocs/openapi/groups.yml similarity index 100% rename from api/openapi/groups.yml rename to apidocs/openapi/groups.yml diff --git a/api/openapi/http.yml b/apidocs/openapi/http.yml similarity index 100% rename from api/openapi/http.yml rename to apidocs/openapi/http.yml diff --git a/api/openapi/invitations.yml b/apidocs/openapi/invitations.yml similarity index 100% rename from api/openapi/invitations.yml rename to apidocs/openapi/invitations.yml diff --git a/api/openapi/journal.yml b/apidocs/openapi/journal.yml similarity index 100% rename from api/openapi/journal.yml rename to apidocs/openapi/journal.yml diff --git a/api/openapi/notifiers.yml b/apidocs/openapi/notifiers.yml similarity index 100% rename from api/openapi/notifiers.yml rename to apidocs/openapi/notifiers.yml diff --git a/api/openapi/provision.yml b/apidocs/openapi/provision.yml similarity index 100% rename from api/openapi/provision.yml rename to apidocs/openapi/provision.yml diff --git a/api/openapi/readers.yml b/apidocs/openapi/readers.yml similarity index 100% rename from api/openapi/readers.yml rename to apidocs/openapi/readers.yml diff --git a/api/openapi/schemas/health_info.yml b/apidocs/openapi/schemas/health_info.yml similarity index 100% rename from api/openapi/schemas/health_info.yml rename to apidocs/openapi/schemas/health_info.yml diff --git a/api/openapi/schemas/roles.yml b/apidocs/openapi/schemas/roles.yml similarity index 100% rename from api/openapi/schemas/roles.yml rename to apidocs/openapi/schemas/roles.yml diff --git a/api/openapi/twins.yml b/apidocs/openapi/twins.yml similarity index 100% rename from api/openapi/twins.yml rename to apidocs/openapi/twins.yml diff --git a/api/openapi/users.yml b/apidocs/openapi/users.yml similarity index 99% rename from api/openapi/users.yml rename to apidocs/openapi/users.yml index 9d7d679a7..e246b9656 100644 --- a/api/openapi/users.yml +++ b/apidocs/openapi/users.yml @@ -1130,18 +1130,18 @@ components: IssueToken: type: object properties: - identity: + username: type: string - example: user@supermq.com - description: User identity - email address. - secret: + example: myUsername + description: Users' username. + password: type: string example: password minimum: 8 description: User secret password. required: - - identity - - secret + - username + - password Error: type: object diff --git a/auth/api/grpc/auth/endpoint_test.go b/auth/api/grpc/auth/endpoint_test.go index 8ee61c4e1..b8a3f6d30 100644 --- a/auth/api/grpc/auth/endpoint_test.go +++ b/auth/api/grpc/auth/endpoint_test.go @@ -10,11 +10,11 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" grpcapi "github.com/absmach/supermq/auth/api/grpc/auth" grpcAuthV1 "github.com/absmach/supermq/internal/grpc/auth/v1" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/stretchr/testify/assert" diff --git a/auth/api/grpc/auth/requests.go b/auth/api/grpc/auth/requests.go index d5fc3bd54..11db7338b 100644 --- a/auth/api/grpc/auth/requests.go +++ b/auth/api/grpc/auth/requests.go @@ -4,8 +4,8 @@ package auth import ( + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/pkg/apiutil" ) type authenticateReq struct { diff --git a/auth/api/grpc/token/endpoint_test.go b/auth/api/grpc/token/endpoint_test.go index ea20052ac..ad23563c4 100644 --- a/auth/api/grpc/token/endpoint_test.go +++ b/auth/api/grpc/token/endpoint_test.go @@ -10,11 +10,11 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" grpcapi "github.com/absmach/supermq/auth/api/grpc/token" grpcTokenV1 "github.com/absmach/supermq/internal/grpc/token/v1" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/stretchr/testify/assert" diff --git a/auth/api/grpc/token/requests.go b/auth/api/grpc/token/requests.go index 3cc183901..040c69fbd 100644 --- a/auth/api/grpc/token/requests.go +++ b/auth/api/grpc/token/requests.go @@ -4,8 +4,8 @@ package token import ( + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/pkg/apiutil" ) type issueReq struct { diff --git a/auth/api/grpc/utils.go b/auth/api/grpc/utils.go index 58fcb5c5b..aef3da53c 100644 --- a/auth/api/grpc/utils.go +++ b/auth/api/grpc/utils.go @@ -6,8 +6,8 @@ package grpc import ( "fmt" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" "google.golang.org/grpc/codes" diff --git a/auth/api/http/keys/endpoint_test.go b/auth/api/http/keys/endpoint_test.go index f9d2cf4a7..5b2693f75 100644 --- a/auth/api/http/keys/endpoint_test.go +++ b/auth/api/http/keys/endpoint_test.go @@ -14,12 +14,12 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" httpapi "github.com/absmach/supermq/auth/api/http" "github.com/absmach/supermq/auth/jwt" "github.com/absmach/supermq/auth/mocks" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" svcerr "github.com/absmach/supermq/pkg/errors/service" policymocks "github.com/absmach/supermq/pkg/policies/mocks" "github.com/absmach/supermq/pkg/uuid" diff --git a/auth/api/http/keys/requests.go b/auth/api/http/keys/requests.go index d99eb5e0c..20568427c 100644 --- a/auth/api/http/keys/requests.go +++ b/auth/api/http/keys/requests.go @@ -6,8 +6,8 @@ package keys import ( "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/pkg/apiutil" ) type issueKeyReq struct { diff --git a/auth/api/http/keys/requests_test.go b/auth/api/http/keys/requests_test.go index 708dac681..cf4433734 100644 --- a/auth/api/http/keys/requests_test.go +++ b/auth/api/http/keys/requests_test.go @@ -6,8 +6,8 @@ package keys import ( "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/pkg/apiutil" "github.com/stretchr/testify/assert" ) diff --git a/auth/api/http/keys/transport.go b/auth/api/http/keys/transport.go index d2e79ed1d..30e3e11de 100644 --- a/auth/api/http/keys/transport.go +++ b/auth/api/http/keys/transport.go @@ -10,9 +10,9 @@ import ( "net/http" "strings" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" kithttp "github.com/go-kit/kit/transport/http" diff --git a/auth/api/http/pats/requests.go b/auth/api/http/pats/requests.go index 39d69efe1..0a7f0a3f3 100644 --- a/auth/api/http/pats/requests.go +++ b/auth/api/http/pats/requests.go @@ -8,8 +8,8 @@ import ( "strings" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/pkg/apiutil" ) type createPatReq struct { diff --git a/auth/api/http/pats/transport.go b/auth/api/http/pats/transport.go index d32ac4064..910bf323b 100644 --- a/auth/api/http/pats/transport.go +++ b/auth/api/http/pats/transport.go @@ -10,9 +10,9 @@ import ( "net/http" "strings" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" kithttp "github.com/go-kit/kit/transport/http" diff --git a/bootstrap/api/endpoint.go b/bootstrap/api/endpoint.go index 8be3780b7..7889c1e98 100644 --- a/bootstrap/api/endpoint.go +++ b/bootstrap/api/endpoint.go @@ -6,9 +6,9 @@ package api import ( "context" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/bootstrap" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/bootstrap/api/endpoint_test.go b/bootstrap/api/endpoint_test.go index 3511e2ca5..07c604bc9 100644 --- a/bootstrap/api/endpoint_test.go +++ b/bootstrap/api/endpoint_test.go @@ -18,12 +18,12 @@ import ( "strings" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/bootstrap" bsapi "github.com/absmach/supermq/bootstrap/api" "github.com/absmach/supermq/bootstrap/mocks" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/bootstrap/api/requests.go b/bootstrap/api/requests.go index 446d5597e..a83e31904 100644 --- a/bootstrap/api/requests.go +++ b/bootstrap/api/requests.go @@ -4,8 +4,8 @@ package api import ( + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/bootstrap" - "github.com/absmach/supermq/pkg/apiutil" ) const maxLimitSize = 100 diff --git a/bootstrap/api/requests_test.go b/bootstrap/api/requests_test.go index 9c25ed944..9d8f0668f 100644 --- a/bootstrap/api/requests_test.go +++ b/bootstrap/api/requests_test.go @@ -7,9 +7,9 @@ import ( "fmt" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/bootstrap" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/stretchr/testify/assert" ) diff --git a/bootstrap/api/transport.go b/bootstrap/api/transport.go index 78d46dd80..c5c9baacf 100644 --- a/bootstrap/api/transport.go +++ b/bootstrap/api/transport.go @@ -12,9 +12,9 @@ import ( "strings" "github.com/absmach/supermq" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/bootstrap" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" diff --git a/certs/api/endpoint.go b/certs/api/endpoint.go index f91089de4..70d52e1f1 100644 --- a/certs/api/endpoint.go +++ b/certs/api/endpoint.go @@ -6,8 +6,8 @@ package api import ( "context" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/certs" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/go-kit/kit/endpoint" ) diff --git a/certs/api/endpoint_test.go b/certs/api/endpoint_test.go index f650531d5..66be87e00 100644 --- a/certs/api/endpoint_test.go +++ b/certs/api/endpoint_test.go @@ -13,12 +13,12 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/certs" - httpapi "github.com/absmach/supermq/certs/api" + "github.com/absmach/supermq/certs/api" "github.com/absmach/supermq/certs/mocks" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" @@ -70,7 +70,7 @@ func newCertServer() (*httptest.Server, *mocks.Service, *authnmocks.Authenticati svc := new(mocks.Service) logger := smqlog.NewMock() authn := new(authnmocks.Authentication) - mux := httpapi.MakeHandler(svc, authn, logger, "") + mux := api.MakeHandler(svc, authn, logger, "") return httptest.NewServer(mux), svc, authn } diff --git a/certs/api/requests.go b/certs/api/requests.go index 520651177..c9b3fac94 100644 --- a/certs/api/requests.go +++ b/certs/api/requests.go @@ -6,8 +6,8 @@ package api import ( "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/certs" - "github.com/absmach/supermq/pkg/apiutil" ) const maxLimitSize = 100 diff --git a/certs/api/transport.go b/certs/api/transport.go index c6bb9dac1..726e53793 100644 --- a/certs/api/transport.go +++ b/certs/api/transport.go @@ -10,9 +10,9 @@ import ( "net/http" "github.com/absmach/supermq" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/certs" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" diff --git a/channels/api/grpc/server.go b/channels/api/grpc/server.go index 4d6e4f1a9..a3f42d234 100644 --- a/channels/api/grpc/server.go +++ b/channels/api/grpc/server.go @@ -6,11 +6,11 @@ package grpc import ( "context" + apiutil "github.com/absmach/supermq/api/http/util" smqauth "github.com/absmach/supermq/auth" channels "github.com/absmach/supermq/channels/private" grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcCommonV1 "github.com/absmach/supermq/internal/grpc/common/v1" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/connections" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/channels/api/http/decode.go b/channels/api/http/decode.go index 98a96db04..ea662f8da 100644 --- a/channels/api/http/decode.go +++ b/channels/api/http/decode.go @@ -9,9 +9,9 @@ import ( "net/http" "strings" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" smqclients "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" ) diff --git a/channels/api/http/endpoint_test.go b/channels/api/http/endpoint_test.go index 88e9de1fb..19e48e3f4 100644 --- a/channels/api/http/endpoint_test.go +++ b/channels/api/http/endpoint_test.go @@ -13,13 +13,13 @@ import ( "testing" "time" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/channels" "github.com/absmach/supermq/channels/mocks" "github.com/absmach/supermq/clients" - smqapi "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/connections" @@ -517,7 +517,7 @@ func TestListChannels(t *testing.T) { desc: "list channels with limit greater than max", token: validToken, domainID: validID, - query: fmt.Sprintf("limit=%d", smqapi.MaxLimitSize+1), + query: fmt.Sprintf("limit=%d", api.MaxLimitSize+1), status: http.StatusBadRequest, err: apiutil.ErrValidation, }, diff --git a/channels/api/http/endpoints.go b/channels/api/http/endpoints.go index eabca13cc..cd33b30ca 100644 --- a/channels/api/http/endpoints.go +++ b/channels/api/http/endpoints.go @@ -6,9 +6,9 @@ package http import ( "context" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/channels" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/channels/api/http/requests.go b/channels/api/http/requests.go index d8dddd237..cd5b64e2c 100644 --- a/channels/api/http/requests.go +++ b/channels/api/http/requests.go @@ -6,10 +6,10 @@ package http import ( "strings" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/channels" smqclients "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/connections" ) diff --git a/channels/api/http/requests_test.go b/channels/api/http/requests_test.go index d212b540c..42a91d0d0 100644 --- a/channels/api/http/requests_test.go +++ b/channels/api/http/requests_test.go @@ -8,10 +8,10 @@ import ( "strings" "testing" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/channels" - "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/connections" "github.com/stretchr/testify/assert" ) diff --git a/channels/api/http/transport.go b/channels/api/http/transport.go index 255c19422..562fe7b94 100644 --- a/channels/api/http/transport.go +++ b/channels/api/http/transport.go @@ -7,9 +7,9 @@ import ( "log/slog" "github.com/absmach/supermq" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/channels" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/go-chi/chi/v5" kithttp "github.com/go-kit/kit/transport/http" diff --git a/channels/postgres/channels.go b/channels/postgres/channels.go index f05a212ad..0905ea00f 100644 --- a/channels/postgres/channels.go +++ b/channels/postgres/channels.go @@ -11,10 +11,10 @@ import ( "strings" "time" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/channels" clients "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/connections" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" diff --git a/channels/service.go b/channels/service.go index 8fc8c204d..e06a596bf 100644 --- a/channels/service.go +++ b/channels/service.go @@ -9,11 +9,11 @@ import ( "time" "github.com/absmach/supermq" + apiutil "github.com/absmach/supermq/api/http/util" smqclients "github.com/absmach/supermq/clients" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" grpcCommonV1 "github.com/absmach/supermq/internal/grpc/common/v1" grpcGroupsV1 "github.com/absmach/supermq/internal/grpc/groups/v1" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/connections" "github.com/absmach/supermq/pkg/errors" diff --git a/channels/service_test.go b/channels/service_test.go index 6b5fc8305..3ba586676 100644 --- a/channels/service_test.go +++ b/channels/service_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/0x6flab/namegenerator" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/channels" "github.com/absmach/supermq/channels/mocks" "github.com/absmach/supermq/clients" @@ -19,7 +20,6 @@ import ( grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" grpcCommonV1 "github.com/absmach/supermq/internal/grpc/common/v1" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/connections" "github.com/absmach/supermq/pkg/errors" diff --git a/cli/clients_test.go b/cli/clients_test.go index 99160d340..a6a0724fc 100644 --- a/cli/clients_test.go +++ b/cli/clients_test.go @@ -10,10 +10,10 @@ import ( "strings" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/cli" "github.com/absmach/supermq/clients" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" sdk "github.com/absmach/supermq/pkg/sdk" diff --git a/cli/provision.go b/cli/provision.go index ec722c830..e1956753d 100644 --- a/cli/provision.go +++ b/cli/provision.go @@ -151,7 +151,7 @@ var cmdProvision = []cobra.Command{ return } - ut, err := sdk.CreateToken(smqsdk.Login{Identity: user.Credentials.Username, Secret: user.Credentials.Secret}) + ut, err := sdk.CreateToken(smqsdk.Login{Username: user.Credentials.Username, Password: user.Credentials.Secret}) if err != nil { logErrorCmd(*cmd, err) return @@ -168,7 +168,7 @@ var cmdProvision = []cobra.Command{ return } - ut, err = sdk.CreateToken(smqsdk.Login{Identity: user.Email, Secret: user.Credentials.Secret}) + ut, err = sdk.CreateToken(smqsdk.Login{Username: user.Email, Password: user.Credentials.Secret}) if err != nil { logErrorCmd(*cmd, err) return diff --git a/cli/users.go b/cli/users.go index b36272a5b..cfc9ac1c6 100644 --- a/cli/users.go +++ b/cli/users.go @@ -106,8 +106,8 @@ var cmdUsers = []cobra.Command{ } loginReq := smqsdk.Login{ - Identity: args[0], - Secret: args[1], + Username: args[0], + Password: args[1], } token, err := sdk.CreateToken(loginReq) diff --git a/cli/users_test.go b/cli/users_test.go index caae31fda..89c64eeb3 100644 --- a/cli/users_test.go +++ b/cli/users_test.go @@ -338,8 +338,8 @@ func TestIssueTokenCmd(t *testing.T) { for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { lg := mgsdk.Login{ - Identity: tc.args[0], - Secret: tc.args[1], + Username: tc.args[0], + Password: tc.args[1], } sdkCall := sdkMock.On("CreateToken", lg).Return(tc.token, tc.sdkerr) diff --git a/clients/api/grpc/server.go b/clients/api/grpc/server.go index fd12bf832..acfdf60e5 100644 --- a/clients/api/grpc/server.go +++ b/clients/api/grpc/server.go @@ -6,11 +6,11 @@ package grpc import ( "context" + apiutil "github.com/absmach/supermq/api/http/util" smqauth "github.com/absmach/supermq/auth" clients "github.com/absmach/supermq/clients/private" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" grpcCommonV1 "github.com/absmach/supermq/internal/grpc/common/v1" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/connections" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/clients/api/http/clients.go b/clients/api/http/clients.go index f1c64d772..29cd6ff32 100644 --- a/clients/api/http/clients.go +++ b/clients/api/http/clients.go @@ -6,9 +6,9 @@ package http import ( "log/slog" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" roleManagerHttp "github.com/absmach/supermq/pkg/roles/rolemanager/api" "github.com/go-chi/chi/v5" diff --git a/clients/api/http/decode.go b/clients/api/http/decode.go index f213da81c..4c2377bbb 100644 --- a/clients/api/http/decode.go +++ b/clients/api/http/decode.go @@ -9,9 +9,9 @@ import ( "net/http" "strings" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" ) diff --git a/clients/api/http/endpoints.go b/clients/api/http/endpoints.go index 590d709a2..cb8936f88 100644 --- a/clients/api/http/endpoints.go +++ b/clients/api/http/endpoints.go @@ -6,9 +6,9 @@ package http import ( "context" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/clients/api/http/endpoints_test.go b/clients/api/http/endpoints_test.go index 9115ddd03..5fd8491a2 100644 --- a/clients/api/http/endpoints_test.go +++ b/clients/api/http/endpoints_test.go @@ -13,13 +13,13 @@ import ( "testing" "github.com/0x6flab/namegenerator" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/clients" - httpapi "github.com/absmach/supermq/clients/api/http" + clientsapi "github.com/absmach/supermq/clients/api/http" "github.com/absmach/supermq/clients/mocks" - "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" @@ -93,7 +93,7 @@ func newClientsServer() (*httptest.Server, *mocks.Service, *authnmocks.Authentic logger := smqlog.NewMock() mux := chi.NewRouter() - httpapi.MakeHandler(svc, authn, mux, logger, "") + clientsapi.MakeHandler(svc, authn, mux, logger, "") return httptest.NewServer(mux), svc, authn } diff --git a/clients/api/http/requests.go b/clients/api/http/requests.go index 6c88726e6..ae2e586f2 100644 --- a/clients/api/http/requests.go +++ b/clients/api/http/requests.go @@ -4,9 +4,9 @@ package http import ( + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" ) type createClientReq struct { diff --git a/clients/api/http/requests_test.go b/clients/api/http/requests_test.go index 4b8b5d7e2..cc9fcc0d5 100644 --- a/clients/api/http/requests_test.go +++ b/clients/api/http/requests_test.go @@ -7,10 +7,10 @@ import ( "strings" "testing" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/stretchr/testify/assert" ) diff --git a/clients/postgres/clients.go b/clients/postgres/clients.go index 388e6cfdc..62717f9ed 100644 --- a/clients/postgres/clients.go +++ b/clients/postgres/clients.go @@ -11,9 +11,9 @@ import ( "strings" "time" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/connections" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" diff --git a/clients/roles.go b/clients/roles.go index aa37f0506..a43e72a93 100644 --- a/clients/roles.go +++ b/clients/roles.go @@ -7,7 +7,7 @@ import ( "encoding/json" "strings" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" ) // Role represents Client role. diff --git a/clients/roles_test.go b/clients/roles_test.go index 61d876043..d059c9f46 100644 --- a/clients/roles_test.go +++ b/clients/roles_test.go @@ -6,8 +6,8 @@ package clients_test import ( "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/clients" - "github.com/absmach/supermq/pkg/apiutil" "github.com/stretchr/testify/assert" ) diff --git a/clients/service.go b/clients/service.go index c27fdc477..5346898c9 100644 --- a/clients/service.go +++ b/clients/service.go @@ -8,11 +8,11 @@ import ( "time" smq "github.com/absmach/supermq" + apiutil "github.com/absmach/supermq/api/http/util" smqauth "github.com/absmach/supermq/auth" grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcCommonV1 "github.com/absmach/supermq/internal/grpc/common/v1" grpcGroupsV1 "github.com/absmach/supermq/internal/grpc/groups/v1" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/clients/service_test.go b/clients/service_test.go index 6de4e585a..c806c6b5c 100644 --- a/clients/service_test.go +++ b/clients/service_test.go @@ -8,6 +8,7 @@ import ( "fmt" "testing" + apiutil "github.com/absmach/supermq/api/http/util" chmocks "github.com/absmach/supermq/channels/mocks" "github.com/absmach/supermq/clients" climocks "github.com/absmach/supermq/clients/mocks" @@ -15,7 +16,6 @@ import ( grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcCommonV1 "github.com/absmach/supermq/internal/grpc/common/v1" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index dc8af3baf..45aa4eefc 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -15,7 +15,7 @@ import ( chclient "github.com/absmach/callhome/pkg/client" "github.com/absmach/supermq" "github.com/absmach/supermq/bootstrap" - "github.com/absmach/supermq/bootstrap/api" + httpapi "github.com/absmach/supermq/bootstrap/api" "github.com/absmach/supermq/bootstrap/events/consumer" "github.com/absmach/supermq/bootstrap/events/producer" "github.com/absmach/supermq/bootstrap/middleware" @@ -179,7 +179,7 @@ func main() { exitCode = 1 return } - hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, authn, bootstrap.NewConfigReader([]byte(cfg.EncKey)), logger, cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(svc, authn, bootstrap.NewConfigReader([]byte(cfg.EncKey)), logger, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) diff --git a/cmd/certs/main.go b/cmd/certs/main.go index 325561dbd..686792881 100644 --- a/cmd/certs/main.go +++ b/cmd/certs/main.go @@ -15,7 +15,7 @@ import ( chclient "github.com/absmach/callhome/pkg/client" "github.com/absmach/supermq" "github.com/absmach/supermq/certs" - "github.com/absmach/supermq/certs/api" + httpapi "github.com/absmach/supermq/certs/api" pki "github.com/absmach/supermq/certs/pki/amcerts" "github.com/absmach/supermq/certs/tracing" smqlog "github.com/absmach/supermq/logger" @@ -133,7 +133,7 @@ func main() { exitCode = 1 return } - hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, authn, logger, cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(svc, authn, logger, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) @@ -159,9 +159,9 @@ func newService(tracer trace.Tracer, logger *slog.Logger, cfg config, pkiAgent p } sdk := mgsdk.NewSDK(config) svc := certs.New(sdk, pkiAgent) - svc = api.LoggingMiddleware(svc, logger) + svc = httpapi.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = httpapi.MetricsMiddleware(svc, counter, latency) svc = tracing.New(svc, tracer) return svc diff --git a/cmd/coap/main.go b/cmd/coap/main.go index cdb52bad6..0ad2b7372 100644 --- a/cmd/coap/main.go +++ b/cmd/coap/main.go @@ -14,7 +14,7 @@ import ( chclient "github.com/absmach/callhome/pkg/client" "github.com/absmach/supermq" "github.com/absmach/supermq/coap" - "github.com/absmach/supermq/coap/api" + httpapi "github.com/absmach/supermq/coap/api" "github.com/absmach/supermq/coap/tracing" smqlog "github.com/absmach/supermq/logger" "github.com/absmach/supermq/pkg/grpcclient" @@ -147,14 +147,14 @@ func main() { svc = tracing.New(tracer, svc) - svc = api.LoggingMiddleware(svc, logger) + svc = httpapi.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = httpapi.MetricsMiddleware(svc, counter, latency) - hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(cfg.InstanceID), logger) - cs := coapserver.NewServer(ctx, cancel, svcName, coapServerConfig, api.MakeCoAPHandler(svc, logger), logger) + cs := coapserver.NewServer(ctx, cancel, svcName, coapServerConfig, httpapi.MakeCoAPHandler(svc, logger), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) diff --git a/cmd/http/main.go b/cmd/http/main.go index d7e33811f..9b85de6d7 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -20,7 +20,7 @@ import ( "github.com/absmach/mgate/pkg/session" "github.com/absmach/supermq" adapter "github.com/absmach/supermq/http" - "github.com/absmach/supermq/http/api" + httpapi "github.com/absmach/supermq/http/api" grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" smqlog "github.com/absmach/supermq/logger" @@ -166,7 +166,7 @@ func main() { svc := newService(pub, authn, clientsClient, channelsClient, logger, tracer) targetServerCfg := server.Config{Port: targetHTTPPort} - hs := httpserver.NewServer(ctx, cancel, svcName, targetServerCfg, api.MakeHandler(logger, cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, targetServerCfg, httpapi.MakeHandler(logger, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) @@ -226,12 +226,12 @@ func proxyHTTP(ctx context.Context, cfg server.Config, logger *slog.Logger, sess go func() { errCh <- mp.Listen(ctx) }() - logger.Info(fmt.Sprintf("%s service https server listening at %s:%s with TLS cert %s and key %s", svcName, cfg.Host, cfg.Port, cfg.CertFile, cfg.KeyFile)) + logger.Info(fmt.Sprintf("%s service HTTPS server listening at %s:%s with TLS cert %s and key %s", svcName, cfg.Host, cfg.Port, cfg.CertFile, cfg.KeyFile)) default: go func() { errCh <- mp.Listen(ctx) }() - logger.Info(fmt.Sprintf("%s service http server listening at %s:%s without TLS", svcName, cfg.Host, cfg.Port)) + logger.Info(fmt.Sprintf("%s service HTTP server listening at %s:%s without TLS", svcName, cfg.Host, cfg.Port)) } select { diff --git a/cmd/invitations/main.go b/cmd/invitations/main.go index eec7cc5c2..fc05a9caa 100644 --- a/cmd/invitations/main.go +++ b/cmd/invitations/main.go @@ -16,7 +16,7 @@ import ( "github.com/absmach/supermq" grpcTokenV1 "github.com/absmach/supermq/internal/grpc/token/v1" "github.com/absmach/supermq/invitations" - "github.com/absmach/supermq/invitations/api" + httpapi "github.com/absmach/supermq/invitations/api" "github.com/absmach/supermq/invitations/middleware" invitationspg "github.com/absmach/supermq/invitations/postgres" smqlog "github.com/absmach/supermq/logger" @@ -156,7 +156,7 @@ func main() { return } - httpSvr := http.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, authn, cfg.InstanceID), logger) + httpSvr := http.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(svc, logger, authn, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) diff --git a/cmd/journal/main.go b/cmd/journal/main.go index 93728c33f..3b46ddcc1 100644 --- a/cmd/journal/main.go +++ b/cmd/journal/main.go @@ -15,7 +15,7 @@ import ( chclient "github.com/absmach/callhome/pkg/client" "github.com/absmach/supermq" "github.com/absmach/supermq/journal" - "github.com/absmach/supermq/journal/api" + httpapi "github.com/absmach/supermq/journal/api" "github.com/absmach/supermq/journal/events" "github.com/absmach/supermq/journal/middleware" journalpg "github.com/absmach/supermq/journal/postgres" @@ -157,7 +157,7 @@ func main() { return } - hs := http.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, authn, logger, svcName, cfg.InstanceID), logger) + hs := http.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(svc, authn, logger, svcName, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) diff --git a/cmd/postgres-reader/main.go b/cmd/postgres-reader/main.go index baa306d34..5157c9270 100644 --- a/cmd/postgres-reader/main.go +++ b/cmd/postgres-reader/main.go @@ -22,7 +22,7 @@ import ( httpserver "github.com/absmach/supermq/pkg/server/http" "github.com/absmach/supermq/pkg/uuid" "github.com/absmach/supermq/readers" - "github.com/absmach/supermq/readers/api" + httpapi "github.com/absmach/supermq/readers/api" "github.com/absmach/supermq/readers/postgres" "github.com/caarlos0/env/v11" "github.com/jmoiron/sqlx" @@ -141,7 +141,7 @@ func main() { exitCode = 1 return } - hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, authn, clientsClient, channelsClient, svcName, cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(repo, authn, clientsClient, channelsClient, svcName, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) @@ -163,9 +163,9 @@ func main() { func newService(db *sqlx.DB, logger *slog.Logger) readers.MessageRepository { svc := postgres.New(db) - svc = api.LoggingMiddleware(svc, logger) + svc = httpapi.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics("postgres", "message_reader") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = httpapi.MetricsMiddleware(svc, counter, latency) return svc } diff --git a/cmd/postgres-writer/main.go b/cmd/postgres-writer/main.go index 87361adc6..c6923b217 100644 --- a/cmd/postgres-writer/main.go +++ b/cmd/postgres-writer/main.go @@ -16,7 +16,7 @@ import ( "github.com/absmach/supermq" "github.com/absmach/supermq/consumers" consumertracing "github.com/absmach/supermq/consumers/tracing" - "github.com/absmach/supermq/consumers/writers/api" + httpapi "github.com/absmach/supermq/consumers/writers/api" writerpg "github.com/absmach/supermq/consumers/writers/postgres" smqlog "github.com/absmach/supermq/logger" jaegerclient "github.com/absmach/supermq/pkg/jaeger" @@ -125,7 +125,7 @@ func main() { return } - hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(svcName, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) @@ -147,8 +147,8 @@ func main() { func newService(db *sqlx.DB, logger *slog.Logger) consumers.BlockingConsumer { svc := writerpg.New(db) - svc = api.LoggingMiddleware(svc, logger) + svc = httpapi.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics("postgres", "message_writer") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = httpapi.MetricsMiddleware(svc, counter, latency) return svc } diff --git a/cmd/provision/main.go b/cmd/provision/main.go index b4b93175f..6c126a83b 100644 --- a/cmd/provision/main.go +++ b/cmd/provision/main.go @@ -23,7 +23,7 @@ import ( httpserver "github.com/absmach/supermq/pkg/server/http" "github.com/absmach/supermq/pkg/uuid" "github.com/absmach/supermq/provision" - "github.com/absmach/supermq/provision/api" + httpapi "github.com/absmach/supermq/provision/api" "github.com/caarlos0/env/v11" "golang.org/x/sync/errgroup" ) @@ -84,10 +84,10 @@ func main() { SDK := mgsdk.NewSDK(SDKCfg) svc := provision.New(cfg, SDK, logger) - svc = api.NewLoggingMiddleware(svc, logger) + svc = httpapi.NewLoggingMiddleware(svc, logger) httpServerConfig := server.Config{Host: "", Port: cfg.Server.HTTPPort, KeyFile: cfg.Server.ServerKey, CertFile: cfg.Server.ServerCert} - hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(svc, logger, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) diff --git a/cmd/timescale-reader/main.go b/cmd/timescale-reader/main.go index 9400828e7..ed5e22913 100644 --- a/cmd/timescale-reader/main.go +++ b/cmd/timescale-reader/main.go @@ -22,7 +22,7 @@ import ( httpserver "github.com/absmach/supermq/pkg/server/http" "github.com/absmach/supermq/pkg/uuid" "github.com/absmach/supermq/readers" - "github.com/absmach/supermq/readers/api" + httpapi "github.com/absmach/supermq/readers/api" "github.com/absmach/supermq/readers/timescale" "github.com/caarlos0/env/v11" "github.com/jmoiron/sqlx" @@ -140,7 +140,7 @@ func main() { exitCode = 1 return } - hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, authn, clientsClient, channelsClient, svcName, cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(repo, authn, clientsClient, channelsClient, svcName, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) @@ -162,9 +162,9 @@ func main() { func newService(db *sqlx.DB, logger *slog.Logger) readers.MessageRepository { svc := timescale.New(db) - svc = api.LoggingMiddleware(svc, logger) + svc = httpapi.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics("timescale", "message_reader") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = httpapi.MetricsMiddleware(svc, counter, latency) return svc } diff --git a/cmd/timescale-writer/main.go b/cmd/timescale-writer/main.go index 7173a3adc..394abca9f 100644 --- a/cmd/timescale-writer/main.go +++ b/cmd/timescale-writer/main.go @@ -16,7 +16,7 @@ import ( "github.com/absmach/supermq" "github.com/absmach/supermq/consumers" consumertracing "github.com/absmach/supermq/consumers/tracing" - "github.com/absmach/supermq/consumers/writers/api" + httpapi "github.com/absmach/supermq/consumers/writers/api" "github.com/absmach/supermq/consumers/writers/timescale" smqlog "github.com/absmach/supermq/logger" jaegerclient "github.com/absmach/supermq/pkg/jaeger" @@ -127,7 +127,7 @@ func main() { return } - hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(svcName, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) @@ -149,8 +149,8 @@ func main() { func newService(db *sqlx.DB, logger *slog.Logger) consumers.BlockingConsumer { svc := timescale.New(db) - svc = api.LoggingMiddleware(svc, logger) + svc = httpapi.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics("timescale", "message_writer") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = httpapi.MetricsMiddleware(svc, counter, latency) return svc } diff --git a/cmd/users/main.go b/cmd/users/main.go index ac52f62b7..77a8b172e 100644 --- a/cmd/users/main.go +++ b/cmd/users/main.go @@ -36,7 +36,7 @@ import ( httpserver "github.com/absmach/supermq/pkg/server/http" "github.com/absmach/supermq/pkg/uuid" "github.com/absmach/supermq/users" - "github.com/absmach/supermq/users/api" + httpapi "github.com/absmach/supermq/users/api" "github.com/absmach/supermq/users/emailer" "github.com/absmach/supermq/users/events" "github.com/absmach/supermq/users/hasher" @@ -237,7 +237,7 @@ func main() { oauthProvider := googleoauth.NewProvider(oauthConfig, cfg.OAuthUIRedirectURL, cfg.OAuthUIErrorURL) mux := chi.NewRouter() - httpSrv := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(csvc, authn, tokenClient, cfg.SelfRegister, mux, logger, cfg.InstanceID, cfg.PassRegex, oauthProvider), logger) + httpSrv := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, httpapi.MakeHandler(csvc, authn, tokenClient, cfg.SelfRegister, mux, logger, cfg.InstanceID, cfg.PassRegex, oauthProvider), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) diff --git a/cmd/ws/main.go b/cmd/ws/main.go index 5b3b733bc..699aadcb4 100644 --- a/cmd/ws/main.go +++ b/cmd/ws/main.go @@ -30,7 +30,7 @@ import ( httpserver "github.com/absmach/supermq/pkg/server/http" "github.com/absmach/supermq/pkg/uuid" "github.com/absmach/supermq/ws" - "github.com/absmach/supermq/ws/api" + httpapi "github.com/absmach/supermq/ws/api" "github.com/absmach/supermq/ws/tracing" "github.com/caarlos0/env/v11" "go.opentelemetry.io/otel/trace" @@ -167,7 +167,7 @@ func main() { svc := newService(clientsClient, channelsClient, nps, logger, tracer) - hs := httpserver.NewServer(ctx, cancel, svcName, targetServerConfig, api.MakeHandler(ctx, svc, logger, cfg.InstanceID), logger) + hs := httpserver.NewServer(ctx, cancel, svcName, targetServerConfig, httpapi.MakeHandler(ctx, svc, logger, cfg.InstanceID), logger) if cfg.SendTelemetry { chc := chclient.New(svcName, supermq.Version, logger, cancel) @@ -194,9 +194,9 @@ func main() { func newService(clientsClient grpcClientsV1.ClientsServiceClient, channels grpcChannelsV1.ChannelsServiceClient, nps messaging.PubSub, logger *slog.Logger, tracer trace.Tracer) ws.Service { svc := ws.New(clientsClient, channels, nps) svc = tracing.New(tracer, svc) - svc = api.LoggingMiddleware(svc, logger) + svc = httpapi.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics("ws_adapter", "api") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = httpapi.MetricsMiddleware(svc, counter, latency) return svc } @@ -212,10 +212,10 @@ func proxyWS(ctx context.Context, hostConfig, targetConfig server.Config, logger go func() { if hostConfig.CertFile != "" && hostConfig.KeyFile != "" { - logger.Info(fmt.Sprintf("ws-adapter service http server listening at %s:%s with TLS", hostConfig.Host, hostConfig.Port)) + logger.Info(fmt.Sprintf("ws-adapter service HTTP server listening at %s:%s with TLS", hostConfig.Host, hostConfig.Port)) errCh <- wp.ListenTLS(hostConfig.CertFile, hostConfig.KeyFile) } else { - logger.Info(fmt.Sprintf("ws-adapter service http server listening at %s:%s without TLS", hostConfig.Host, hostConfig.Port)) + logger.Info(fmt.Sprintf("ws-adapter service HTTP server listening at %s:%s without TLS", hostConfig.Host, hostConfig.Port)) errCh <- wp.Listen() } }() diff --git a/consumers/messages.go b/consumers/messages.go index afb9a7a51..e85312c2f 100644 --- a/consumers/messages.go +++ b/consumers/messages.go @@ -10,7 +10,7 @@ import ( "os" "strings" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" "github.com/absmach/supermq/pkg/messaging" "github.com/absmach/supermq/pkg/messaging/brokers" diff --git a/consumers/notifiers/api/endpoint.go b/consumers/notifiers/api/endpoint.go index 6487d63a2..42b8055ea 100644 --- a/consumers/notifiers/api/endpoint.go +++ b/consumers/notifiers/api/endpoint.go @@ -6,8 +6,8 @@ package api import ( "context" + apiutil "github.com/absmach/supermq/api/http/util" notifiers "github.com/absmach/supermq/consumers/notifiers" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/go-kit/kit/endpoint" ) diff --git a/consumers/notifiers/api/endpoint_test.go b/consumers/notifiers/api/endpoint_test.go index 3c3a3bbcf..7fb467640 100644 --- a/consumers/notifiers/api/endpoint_test.go +++ b/consumers/notifiers/api/endpoint_test.go @@ -13,12 +13,12 @@ import ( "strings" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/consumers/notifiers" - httpapi "github.com/absmach/supermq/consumers/notifiers/api" + "github.com/absmach/supermq/consumers/notifiers/api" "github.com/absmach/supermq/consumers/notifiers/mocks" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/absmach/supermq/pkg/uuid" "github.com/stretchr/testify/assert" @@ -70,7 +70,7 @@ func (tr testRequest) make() (*http.Response, error) { func newServer() (*httptest.Server, *mocks.Service) { logger := smqlog.NewMock() svc := new(mocks.Service) - mux := httpapi.MakeHandler(svc, logger, instanceID) + mux := api.MakeHandler(svc, logger, instanceID) return httptest.NewServer(mux), svc } diff --git a/consumers/notifiers/api/requests.go b/consumers/notifiers/api/requests.go index 29a4f1d1b..9b133aead 100644 --- a/consumers/notifiers/api/requests.go +++ b/consumers/notifiers/api/requests.go @@ -3,7 +3,7 @@ package api -import "github.com/absmach/supermq/pkg/apiutil" +import apiutil "github.com/absmach/supermq/api/http/util" type createSubReq struct { token string diff --git a/consumers/notifiers/api/transport.go b/consumers/notifiers/api/transport.go index 216d479a5..605833fe0 100644 --- a/consumers/notifiers/api/transport.go +++ b/consumers/notifiers/api/transport.go @@ -11,9 +11,9 @@ import ( "strings" "github.com/absmach/supermq" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/consumers/notifiers" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" kithttp "github.com/go-kit/kit/transport/http" diff --git a/docker/Dockerfile.livereload b/docker/Dockerfile.livereload deleted file mode 100644 index 43c8e0bfb..000000000 --- a/docker/Dockerfile.livereload +++ /dev/null @@ -1,6 +0,0 @@ -## Copyright (c) Abstract Machines -## SPDX-License-Identifier: Apache-2.0 - -FROM golang:1.23-alpine -RUN go install github.com/air-verse/air@latest -RUN apk update && apk add make git diff --git a/docker/docker-compose-live.yaml b/docker/docker-compose-live.yaml deleted file mode 100644 index a268072e1..000000000 --- a/docker/docker-compose-live.yaml +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright (c) Abstract Machines -# SPDX-License-Identifier: Apache-2.0 - -services: - domains: - image: supermq/domains-dev - build: - context: . - dockerfile: Dockerfile.livereload - volumes: - - ../:/go/src/github.com/absmach/supermq - - $GOPATH/pkg/mod/cache:/go/pkg/mod/cache - working_dir: /go/src/github.com/absmach/supermq - entrypoint: [ "air", - "--build.cmd", "BUILD_DIR=/tmp make domains", - "--build.bin", "/tmp/domains", - "--build.stop_on_error", "true", - "--build.send_interrupt", "true", - "--build.include_file","dockers/.env", - "--build.exclude_dir", ".vscode,.git,.docker,.github,api,build,tools,scripts", - "--build.exclude_regex", "[\"_test\\.go\"" , - "--tmp_dir", "/tmp",] - - users: - image: supermq/users-dev - build: - context: . - dockerfile: Dockerfile.livereload - volumes: - - ../:/go/src/github.com/absmach/supermq - - $GOPATH/pkg/mod/cache:/go/pkg/mod/cache - working_dir: /go/src/github.com/absmach/supermq - entrypoint: [ "air", - "--build.cmd", "BUILD_DIR=/tmp make users", - "--build.bin", "/tmp/users", - "--build.stop_on_error", "true", - "--build.send_interrupt", "true", - "--build.exclude_dir", ".vscode,.git,.docker,.github,api,build,tools,scripts", - "--build.exclude_regex", "[\"_test\\.go\"" , - "--tmp_dir", "/tmp",] - clients: - image: supermq/clients-dev - build: - context: . - dockerfile: Dockerfile.livereload - volumes: - - ../:/go/src/github.com/absmach/supermq - - $GOPATH/pkg/mod/cache:/go/pkg/mod/cache - working_dir: /go/src/github.com/absmach/supermq - entrypoint: [ "air", - "--build.cmd", "BUILD_DIR=/tmp make clients", - "--build.bin", "/tmp/clients", - "--build.stop_on_error", "true", - "--build.send_interrupt", "true", - "--build.exclude_dir", ".vscode,.git,.docker,.github,api,build,tools,scripts", - "--build.exclude_regex", "[\"_test\\.go\"" , - "-tmp_dir", "/tmp",] - - channels: - image: supermq/channels-dev - build: - context: . - dockerfile: Dockerfile.livereload - volumes: - - ../:/go/src/github.com/absmach/supermq - - $GOPATH/pkg/mod/cache:/go/pkg/mod/cache - working_dir: /go/src/github.com/absmach/supermq - entrypoint: [ "air", - "--build.cmd", "BUILD_DIR=/tmp make channels", - "--build.bin", "/tmp/channels", - "--build.stop_on_error", "true", - "--build.send_interrupt", "true", - "--build.exclude_dir", ".vscode,.git,.docker,.github,api,build,tools,scripts", - "--build.exclude_regex", "[\"_test\\.go\"" , - "-tmp_dir", "/tmp",] - - channels-db: - command: ["postgres", "-c", "log_statement=all"] - - groups: - image: supermq/groups-dev - build: - context: . - dockerfile: Dockerfile.livereload - volumes: - - ../:/go/src/github.com/absmach/supermq - - $GOPATH/pkg/mod/cache:/go/pkg/mod/cache - working_dir: /go/src/github.com/absmach/supermq - entrypoint: [ "air", - "--build.cmd", "BUILD_DIR=/tmp make groups", - "--build.bin", "/tmp/groups", - "--build.stop_on_error", "true", - "--build.send_interrupt", "true", - "--build.exclude_dir", ".vscode,.git,.docker,.github,api,build,tools,scripts", - "--build.exclude_regex", "[\"_test\\.go\"" , - "-tmp_dir", "/tmp",] diff --git a/domains/api/grpc/endpoint_test.go b/domains/api/grpc/endpoint_test.go index a0d8e83f7..eeec3e8a0 100644 --- a/domains/api/grpc/endpoint_test.go +++ b/domains/api/grpc/endpoint_test.go @@ -10,10 +10,10 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/domains" grpcapi "github.com/absmach/supermq/domains/api/grpc" grpcDomainsV1 "github.com/absmach/supermq/internal/grpc/domains/v1" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/domains/api/grpc/requests.go b/domains/api/grpc/requests.go index 5d9f6c124..5caa1efd6 100644 --- a/domains/api/grpc/requests.go +++ b/domains/api/grpc/requests.go @@ -4,7 +4,7 @@ package grpc import ( - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" ) type deleteUserPoliciesReq struct { diff --git a/domains/api/http/decode.go b/domains/api/http/decode.go index fd9c6569f..13999acf1 100644 --- a/domains/api/http/decode.go +++ b/domains/api/http/decode.go @@ -9,9 +9,9 @@ import ( "net/http" "strings" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/domains" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" ) diff --git a/domains/api/http/endpoint.go b/domains/api/http/endpoint.go index 812615e04..40fb2c118 100644 --- a/domains/api/http/endpoint.go +++ b/domains/api/http/endpoint.go @@ -6,9 +6,9 @@ package http import ( "context" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/domains" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/domains/api/http/endpoint_test.go b/domains/api/http/endpoint_test.go index 46f59055e..e3360cfe9 100644 --- a/domains/api/http/endpoint_test.go +++ b/domains/api/http/endpoint_test.go @@ -13,13 +13,13 @@ import ( "testing" "time" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/domains" - httpapi "github.com/absmach/supermq/domains/api/http" + domainsapi "github.com/absmach/supermq/domains/api/http" "github.com/absmach/supermq/domains/mocks" - "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" authnmock "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" @@ -93,7 +93,7 @@ func newDomainsServer() (*httptest.Server, *mocks.Service, *authnmock.Authentica svc := new(mocks.Service) authn := new(authnmock.Authentication) mux := chi.NewMux() - httpapi.MakeHandler(svc, authn, mux, logger, "") + domainsapi.MakeHandler(svc, authn, mux, logger, "") return httptest.NewServer(mux), svc, authn } diff --git a/domains/api/http/requests.go b/domains/api/http/requests.go index 6ebfa7970..7f12eaa1a 100644 --- a/domains/api/http/requests.go +++ b/domains/api/http/requests.go @@ -4,8 +4,8 @@ package http import ( + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/domains" - "github.com/absmach/supermq/pkg/apiutil" ) type page struct { diff --git a/domains/api/http/transport.go b/domains/api/http/transport.go index e895d6263..fa68fe2f3 100644 --- a/domains/api/http/transport.go +++ b/domains/api/http/transport.go @@ -7,9 +7,9 @@ import ( "log/slog" "github.com/absmach/supermq" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/domains" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" roleManagerHttp "github.com/absmach/supermq/pkg/roles/rolemanager/api" "github.com/go-chi/chi/v5" diff --git a/domains/postgres/domains.go b/domains/postgres/domains.go index 0b6d94d9f..861057677 100644 --- a/domains/postgres/domains.go +++ b/domains/postgres/domains.go @@ -11,8 +11,8 @@ import ( "strings" "time" + api "github.com/absmach/supermq/api/http" "github.com/absmach/supermq/domains" - "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" "github.com/absmach/supermq/pkg/postgres" diff --git a/groups/api/grpc/server.go b/groups/api/grpc/server.go index b0a0dc9dd..291d9b28d 100644 --- a/groups/api/grpc/server.go +++ b/groups/api/grpc/server.go @@ -6,11 +6,11 @@ package grpc import ( "context" + apiutil "github.com/absmach/supermq/api/http/util" smqauth "github.com/absmach/supermq/auth" groups "github.com/absmach/supermq/groups/private" grpcCommonV1 "github.com/absmach/supermq/internal/grpc/common/v1" grpcGroupsV1 "github.com/absmach/supermq/internal/grpc/groups/v1" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" kitgrpc "github.com/go-kit/kit/transport/grpc" diff --git a/groups/api/http/decode.go b/groups/api/http/decode.go index d0bdf6da9..7ca6cc36a 100644 --- a/groups/api/http/decode.go +++ b/groups/api/http/decode.go @@ -9,9 +9,9 @@ import ( "net/http" "strings" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" groups "github.com/absmach/supermq/groups" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" ) diff --git a/groups/api/http/decode_test.go b/groups/api/http/decode_test.go index 04e5d486e..5bbc9d2ae 100644 --- a/groups/api/http/decode_test.go +++ b/groups/api/http/decode_test.go @@ -11,9 +11,9 @@ import ( "strings" "testing" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/groups" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/stretchr/testify/assert" ) diff --git a/groups/api/http/endpoint_test.go b/groups/api/http/endpoint_test.go index a322b91cd..0ca5ef15a 100644 --- a/groups/api/http/endpoint_test.go +++ b/groups/api/http/endpoint_test.go @@ -13,12 +13,12 @@ import ( "testing" "time" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/groups" "github.com/absmach/supermq/groups/mocks" - smqapi "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" @@ -763,7 +763,7 @@ func TestListGroups(t *testing.T) { desc: "list groups with limit greater than max", token: validToken, domainID: validID, - query: fmt.Sprintf("limit=%d", smqapi.MaxLimitSize+1), + query: fmt.Sprintf("limit=%d", api.MaxLimitSize+1), status: http.StatusBadRequest, err: apiutil.ErrValidation, }, diff --git a/groups/api/http/endpoints.go b/groups/api/http/endpoints.go index c41b87df0..4a5f238c2 100644 --- a/groups/api/http/endpoints.go +++ b/groups/api/http/endpoints.go @@ -6,9 +6,9 @@ package api import ( "context" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/groups" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/groups/api/http/requests.go b/groups/api/http/requests.go index bc602e1c3..59a0e59f3 100644 --- a/groups/api/http/requests.go +++ b/groups/api/http/requests.go @@ -4,9 +4,9 @@ package api import ( + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/groups" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" ) type createGroupReq struct { diff --git a/groups/api/http/requests_test.go b/groups/api/http/requests_test.go index 3672b2ff2..8fc3712e1 100644 --- a/groups/api/http/requests_test.go +++ b/groups/api/http/requests_test.go @@ -8,10 +8,10 @@ import ( "strings" "testing" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/groups" - "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/stretchr/testify/assert" ) diff --git a/groups/api/http/transport.go b/groups/api/http/transport.go index 1caee6a4a..36a0f462a 100644 --- a/groups/api/http/transport.go +++ b/groups/api/http/transport.go @@ -7,9 +7,9 @@ import ( "log/slog" "github.com/absmach/supermq" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/groups" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" roleManagerHttp "github.com/absmach/supermq/pkg/roles/rolemanager/api" "github.com/go-chi/chi/v5" diff --git a/groups/service.go b/groups/service.go index 6277304f7..9c8a6ada9 100644 --- a/groups/service.go +++ b/groups/service.go @@ -9,9 +9,9 @@ import ( "time" "github.com/absmach/supermq" + apiutil "github.com/absmach/supermq/api/http/util" grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/groups/service_test.go b/groups/service_test.go index bef8fdf84..2b0320df5 100644 --- a/groups/service_test.go +++ b/groups/service_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/0x6flab/namegenerator" + apiutil "github.com/absmach/supermq/api/http/util" chmocks "github.com/absmach/supermq/channels/mocks" climocks "github.com/absmach/supermq/clients/mocks" "github.com/absmach/supermq/groups" @@ -17,7 +18,6 @@ import ( grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" diff --git a/http/api/endpoint.go b/http/api/endpoint.go index 1fb7604ae..c002dc7e3 100644 --- a/http/api/endpoint.go +++ b/http/api/endpoint.go @@ -6,7 +6,7 @@ package api import ( "context" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" "github.com/go-kit/kit/endpoint" ) diff --git a/http/api/endpoint_test.go b/http/api/endpoint_test.go index 0522f1068..555f53769 100644 --- a/http/api/endpoint_test.go +++ b/http/api/endpoint_test.go @@ -14,6 +14,7 @@ import ( "github.com/absmach/mgate" proxy "github.com/absmach/mgate/pkg/http" "github.com/absmach/mgate/pkg/session" + apiutil "github.com/absmach/supermq/api/http/util" chmocks "github.com/absmach/supermq/channels/mocks" climocks "github.com/absmach/supermq/clients/mocks" server "github.com/absmach/supermq/http" @@ -22,7 +23,6 @@ import ( grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnMocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/connections" diff --git a/http/api/request.go b/http/api/request.go index af4a9030f..5836f511b 100644 --- a/http/api/request.go +++ b/http/api/request.go @@ -4,7 +4,7 @@ package api import ( - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/messaging" ) diff --git a/http/api/transport.go b/http/api/transport.go index 5378b24f2..56fee979f 100644 --- a/http/api/transport.go +++ b/http/api/transport.go @@ -10,8 +10,8 @@ import ( "net/http" "github.com/absmach/supermq" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" "github.com/absmach/supermq/pkg/messaging" "github.com/go-chi/chi/v5" diff --git a/http/handler.go b/http/handler.go index c28c745bc..da7bd5b72 100644 --- a/http/handler.go +++ b/http/handler.go @@ -15,9 +15,9 @@ import ( mgate "github.com/absmach/mgate/pkg/http" "github.com/absmach/mgate/pkg/session" + apiutil "github.com/absmach/supermq/api/http/util" grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/connections" "github.com/absmach/supermq/pkg/errors" diff --git a/http/handler_test.go b/http/handler_test.go index 2ea3dd8ad..094ad0988 100644 --- a/http/handler_test.go +++ b/http/handler_test.go @@ -11,6 +11,7 @@ import ( mghttp "github.com/absmach/mgate/pkg/http" "github.com/absmach/mgate/pkg/session" + apiutil "github.com/absmach/supermq/api/http/util" chmocks "github.com/absmach/supermq/channels/mocks" clmocks "github.com/absmach/supermq/clients/mocks" mhttp "github.com/absmach/supermq/http" @@ -18,7 +19,6 @@ import ( grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/invitations/api/endpoint.go b/invitations/api/endpoint.go index adb4e8e38..efde368a7 100644 --- a/invitations/api/endpoint.go +++ b/invitations/api/endpoint.go @@ -6,9 +6,9 @@ package api import ( "context" - "github.com/absmach/supermq/internal/api" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/invitations" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/invitations/api/endpoint_test.go b/invitations/api/endpoint_test.go index 36403a954..540c16966 100644 --- a/invitations/api/endpoint_test.go +++ b/invitations/api/endpoint_test.go @@ -11,12 +11,12 @@ import ( "strings" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/internal/testsutil" "github.com/absmach/supermq/invitations" "github.com/absmach/supermq/invitations/api" "github.com/absmach/supermq/invitations/mocks" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/invitations/api/requests.go b/invitations/api/requests.go index d71b8c3c3..c81c976ab 100644 --- a/invitations/api/requests.go +++ b/invitations/api/requests.go @@ -4,8 +4,8 @@ package api import ( + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/invitations" - "github.com/absmach/supermq/pkg/apiutil" ) const maxLimitSize = 100 diff --git a/invitations/api/requests_test.go b/invitations/api/requests_test.go index 2af5a6d2f..7b8bb5a1b 100644 --- a/invitations/api/requests_test.go +++ b/invitations/api/requests_test.go @@ -7,8 +7,8 @@ import ( "fmt" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/invitations" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/policies" "github.com/stretchr/testify/assert" ) diff --git a/invitations/api/transport.go b/invitations/api/transport.go index 232a46f26..06eae2177 100644 --- a/invitations/api/transport.go +++ b/invitations/api/transport.go @@ -11,9 +11,9 @@ import ( "strings" "github.com/absmach/supermq" - "github.com/absmach/supermq/internal/api" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/invitations" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" diff --git a/invitations/invitations.go b/invitations/invitations.go index a7bf2973a..e7d681756 100644 --- a/invitations/invitations.go +++ b/invitations/invitations.go @@ -8,7 +8,7 @@ import ( "encoding/json" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/policies" ) diff --git a/invitations/invitations_test.go b/invitations/invitations_test.go index de6ef8436..5eb120dff 100644 --- a/invitations/invitations_test.go +++ b/invitations/invitations_test.go @@ -7,8 +7,8 @@ import ( "fmt" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/invitations" - "github.com/absmach/supermq/pkg/apiutil" "github.com/stretchr/testify/assert" ) diff --git a/invitations/service_test.go b/invitations/service_test.go index 7812418f0..f93206373 100644 --- a/invitations/service_test.go +++ b/invitations/service_test.go @@ -8,12 +8,12 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" authmocks "github.com/absmach/supermq/auth/mocks" grpcTokenV1 "github.com/absmach/supermq/internal/grpc/token/v1" "github.com/absmach/supermq/internal/testsutil" "github.com/absmach/supermq/invitations" "github.com/absmach/supermq/invitations/mocks" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" diff --git a/invitations/state.go b/invitations/state.go index 4e364e7e7..50649e865 100644 --- a/invitations/state.go +++ b/invitations/state.go @@ -7,7 +7,7 @@ import ( "encoding/json" "strings" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" ) // State represents invitation state. diff --git a/invitations/state_test.go b/invitations/state_test.go index 467cf7eda..451f209e6 100644 --- a/invitations/state_test.go +++ b/invitations/state_test.go @@ -6,8 +6,8 @@ package invitations_test import ( "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/invitations" - "github.com/absmach/supermq/pkg/apiutil" "github.com/stretchr/testify/assert" ) diff --git a/journal/api/endpoint.go b/journal/api/endpoint.go index 3e20d6de5..2042aeba3 100644 --- a/journal/api/endpoint.go +++ b/journal/api/endpoint.go @@ -6,9 +6,9 @@ package api import ( "context" - "github.com/absmach/supermq/internal/api" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/journal" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/journal/api/endpoint_test.go b/journal/api/endpoint_test.go index c5291b8fe..b470a4cbf 100644 --- a/journal/api/endpoint_test.go +++ b/journal/api/endpoint_test.go @@ -12,12 +12,12 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/internal/testsutil" "github.com/absmach/supermq/journal" "github.com/absmach/supermq/journal/api" "github.com/absmach/supermq/journal/mocks" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/journal/api/requests.go b/journal/api/requests.go index f9c202a5a..8d52fd8ec 100644 --- a/journal/api/requests.go +++ b/journal/api/requests.go @@ -4,9 +4,9 @@ package api import ( - "github.com/absmach/supermq/internal/api" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/journal" - "github.com/absmach/supermq/pkg/apiutil" ) type retrieveJournalsReq struct { diff --git a/journal/api/requests_test.go b/journal/api/requests_test.go index 6d74081af..e88c52c9f 100644 --- a/journal/api/requests_test.go +++ b/journal/api/requests_test.go @@ -6,9 +6,9 @@ package api import ( "testing" - "github.com/absmach/supermq/internal/api" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/journal" - "github.com/absmach/supermq/pkg/apiutil" "github.com/stretchr/testify/assert" ) diff --git a/journal/api/transport.go b/journal/api/transport.go index 3f645e4ca..7c7f5bc83 100644 --- a/journal/api/transport.go +++ b/journal/api/transport.go @@ -12,9 +12,9 @@ import ( "time" "github.com/absmach/supermq" - "github.com/absmach/supermq/internal/api" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/journal" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" diff --git a/journal/journal.go b/journal/journal.go index 92ff333e6..70ed8928d 100644 --- a/journal/journal.go +++ b/journal/journal.go @@ -8,7 +8,7 @@ import ( "encoding/json" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/policies" ) diff --git a/journal/journal_test.go b/journal/journal_test.go index 109b270d6..478846c30 100644 --- a/journal/journal_test.go +++ b/journal/journal_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/journal" - "github.com/absmach/supermq/pkg/apiutil" "github.com/stretchr/testify/assert" ) diff --git a/pkg/roles/repo/postgres/roles.go b/pkg/roles/repo/postgres/roles.go index 1a005aa65..ad95626e7 100644 --- a/pkg/roles/repo/postgres/roles.go +++ b/pkg/roles/repo/postgres/roles.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" "github.com/absmach/supermq/pkg/postgres" diff --git a/pkg/roles/rolemanager/api/decoders.go b/pkg/roles/rolemanager/api/decoders.go index dbc9837a1..d8c6e23d2 100644 --- a/pkg/roles/rolemanager/api/decoders.go +++ b/pkg/roles/rolemanager/api/decoders.go @@ -9,8 +9,8 @@ import ( "net/http" "strings" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" "github.com/go-chi/chi/v5" ) diff --git a/pkg/roles/rolemanager/api/endpoints.go b/pkg/roles/rolemanager/api/endpoints.go index 6bbe06ae7..5e35d6882 100644 --- a/pkg/roles/rolemanager/api/endpoints.go +++ b/pkg/roles/rolemanager/api/endpoints.go @@ -6,8 +6,8 @@ package http import ( "context" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/pkg/roles/rolemanager/api/requests.go b/pkg/roles/rolemanager/api/requests.go index 71529258d..a607ad5e8 100644 --- a/pkg/roles/rolemanager/api/requests.go +++ b/pkg/roles/rolemanager/api/requests.go @@ -4,8 +4,8 @@ package http import ( - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" ) type createRoleReq struct { diff --git a/pkg/roles/rolemanager/api/router.go b/pkg/roles/rolemanager/api/router.go index eb2ce7692..d47b7b369 100644 --- a/pkg/roles/rolemanager/api/router.go +++ b/pkg/roles/rolemanager/api/router.go @@ -4,7 +4,7 @@ package http import ( - "github.com/absmach/supermq/internal/api" + api "github.com/absmach/supermq/api/http" "github.com/absmach/supermq/pkg/roles" "github.com/go-chi/chi/v5" kithttp "github.com/go-kit/kit/transport/http" diff --git a/pkg/sdk/bootstrap.go b/pkg/sdk/bootstrap.go index e7e11dcc3..8a21e0437 100644 --- a/pkg/sdk/bootstrap.go +++ b/pkg/sdk/bootstrap.go @@ -14,7 +14,7 @@ import ( "net/http" "strings" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" ) diff --git a/pkg/sdk/bootstrap_test.go b/pkg/sdk/bootstrap_test.go index 815bf48f9..361d4f3f7 100644 --- a/pkg/sdk/bootstrap_test.go +++ b/pkg/sdk/bootstrap_test.go @@ -14,12 +14,12 @@ import ( "net/http/httptest" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/bootstrap" "github.com/absmach/supermq/bootstrap/api" bmocks "github.com/absmach/supermq/bootstrap/mocks" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/pkg/sdk/certs.go b/pkg/sdk/certs.go index 5735b2591..c724eda67 100644 --- a/pkg/sdk/certs.go +++ b/pkg/sdk/certs.go @@ -9,7 +9,7 @@ import ( "net/http" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" ) diff --git a/pkg/sdk/certs_test.go b/pkg/sdk/certs_test.go index 71e591584..8b1cde5fd 100644 --- a/pkg/sdk/certs_test.go +++ b/pkg/sdk/certs_test.go @@ -10,12 +10,12 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/certs" httpapi "github.com/absmach/supermq/certs/api" "github.com/absmach/supermq/certs/mocks" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/pkg/sdk/channels.go b/pkg/sdk/channels.go index a3f70eb1b..4ea278c7d 100644 --- a/pkg/sdk/channels.go +++ b/pkg/sdk/channels.go @@ -9,7 +9,7 @@ import ( "net/http" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" ) diff --git a/pkg/sdk/channels_test.go b/pkg/sdk/channels_test.go index c3c21d91d..3f35158a3 100644 --- a/pkg/sdk/channels_test.go +++ b/pkg/sdk/channels_test.go @@ -11,13 +11,13 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/channels" chapi "github.com/absmach/supermq/channels/api/http" chmocks "github.com/absmach/supermq/channels/mocks" "github.com/absmach/supermq/clients" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/connections" diff --git a/pkg/sdk/clients.go b/pkg/sdk/clients.go index fad7dacf5..43cf14944 100644 --- a/pkg/sdk/clients.go +++ b/pkg/sdk/clients.go @@ -9,7 +9,7 @@ import ( "net/http" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" ) diff --git a/pkg/sdk/clients_test.go b/pkg/sdk/clients_test.go index 34edee522..c9dc83ddb 100644 --- a/pkg/sdk/clients_test.go +++ b/pkg/sdk/clients_test.go @@ -11,12 +11,12 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/clients" api "github.com/absmach/supermq/clients/api/http" "github.com/absmach/supermq/clients/mocks" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/pkg/sdk/consumers_test.go b/pkg/sdk/consumers_test.go index ae3822780..1ccac3e07 100644 --- a/pkg/sdk/consumers_test.go +++ b/pkg/sdk/consumers_test.go @@ -9,12 +9,12 @@ import ( "net/http/httptest" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/consumers/notifiers" httpapi "github.com/absmach/supermq/consumers/notifiers/api" notmocks "github.com/absmach/supermq/consumers/notifiers/mocks" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" sdk "github.com/absmach/supermq/pkg/sdk" diff --git a/pkg/sdk/domains.go b/pkg/sdk/domains.go index b5ead9a80..7c695e7fa 100644 --- a/pkg/sdk/domains.go +++ b/pkg/sdk/domains.go @@ -9,7 +9,7 @@ import ( "net/http" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" ) diff --git a/pkg/sdk/domains_test.go b/pkg/sdk/domains_test.go index fbaf0ec4e..56be5cdab 100644 --- a/pkg/sdk/domains_test.go +++ b/pkg/sdk/domains_test.go @@ -10,13 +10,13 @@ import ( "testing" "time" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/domains" - httpapi "github.com/absmach/supermq/domains/api/http" + domainapi "github.com/absmach/supermq/domains/api/http" "github.com/absmach/supermq/domains/mocks" - internalapi "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" @@ -50,7 +50,7 @@ func setupDomains() (*httptest.Server, *mocks.Service, *authnmocks.Authenticatio mux := chi.NewRouter() authn := new(authnmocks.Authentication) - mux = httpapi.MakeHandler(svc, authn, mux, logger, "") + mux = domainapi.MakeHandler(svc, authn, mux, logger, "") return httptest.NewServer(mux), svc, authn } @@ -458,8 +458,8 @@ func TestListDomians(t *testing.T) { svcReq: domains.Page{ Offset: 0, Limit: 10, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: domains.DomainsPage{ Total: 1, @@ -484,8 +484,8 @@ func TestListDomians(t *testing.T) { svcReq: domains.Page{ Offset: 0, Limit: 10, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: domains.DomainsPage{}, authnErr: svcerr.ErrAuthentication, @@ -531,8 +531,8 @@ func TestListDomians(t *testing.T) { svcReq: domains.Page{ Offset: 0, Limit: 10, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: domains.DomainsPage{ Total: 1, diff --git a/pkg/sdk/groups.go b/pkg/sdk/groups.go index 9d70bda67..fc0bda88a 100644 --- a/pkg/sdk/groups.go +++ b/pkg/sdk/groups.go @@ -9,7 +9,7 @@ import ( "net/http" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" ) diff --git a/pkg/sdk/groups_test.go b/pkg/sdk/groups_test.go index 236a2ef98..5bbef6df6 100644 --- a/pkg/sdk/groups_test.go +++ b/pkg/sdk/groups_test.go @@ -11,12 +11,12 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/groups" httpapi "github.com/absmach/supermq/groups/api/http" "github.com/absmach/supermq/groups/mocks" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/pkg/sdk/invitations_test.go b/pkg/sdk/invitations_test.go index 11cac6283..4d3413e69 100644 --- a/pkg/sdk/invitations_test.go +++ b/pkg/sdk/invitations_test.go @@ -10,12 +10,12 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/internal/testsutil" "github.com/absmach/supermq/invitations" "github.com/absmach/supermq/invitations/api" "github.com/absmach/supermq/invitations/mocks" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/pkg/sdk/journal.go b/pkg/sdk/journal.go index 1e6ccd1e5..420db09d0 100644 --- a/pkg/sdk/journal.go +++ b/pkg/sdk/journal.go @@ -9,7 +9,7 @@ import ( "net/http" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" ) diff --git a/pkg/sdk/journal_test.go b/pkg/sdk/journal_test.go index 1342bdf9d..8a91e6479 100644 --- a/pkg/sdk/journal_test.go +++ b/pkg/sdk/journal_test.go @@ -10,11 +10,11 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/journal" "github.com/absmach/supermq/journal/api" "github.com/absmach/supermq/journal/mocks" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/pkg/sdk/message.go b/pkg/sdk/message.go index ce8d83176..14244d825 100644 --- a/pkg/sdk/message.go +++ b/pkg/sdk/message.go @@ -11,7 +11,7 @@ import ( "strconv" "strings" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" ) diff --git a/pkg/sdk/message_test.go b/pkg/sdk/message_test.go index 2faabe615..9975b26ea 100644 --- a/pkg/sdk/message_test.go +++ b/pkg/sdk/message_test.go @@ -11,6 +11,7 @@ import ( "github.com/absmach/mgate" proxy "github.com/absmach/mgate/pkg/http" + apiutil "github.com/absmach/supermq/api/http/util" chmocks "github.com/absmach/supermq/channels/mocks" climocks "github.com/absmach/supermq/clients/mocks" adapter "github.com/absmach/supermq/http" @@ -18,7 +19,6 @@ import ( grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" diff --git a/pkg/sdk/tokens.go b/pkg/sdk/tokens.go index f9493d8c5..ab129bc28 100644 --- a/pkg/sdk/tokens.go +++ b/pkg/sdk/tokens.go @@ -20,8 +20,8 @@ type Token struct { } type Login struct { - Identity string `json:"identity"` - Secret string `json:"secret"` + Username string `json:"username"` + Password string `json:"password"` } func (sdk mgSDK) CreateToken(lt Login) (Token, errors.SDKError) { diff --git a/pkg/sdk/tokens_test.go b/pkg/sdk/tokens_test.go index fdccadced..a79b1deed 100644 --- a/pkg/sdk/tokens_test.go +++ b/pkg/sdk/tokens_test.go @@ -7,9 +7,9 @@ import ( "net/http" "testing" + apiutil "github.com/absmach/supermq/api/http/util" smqauth "github.com/absmach/supermq/auth" grpcTokenV1 "github.com/absmach/supermq/internal/grpc/token/v1" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" @@ -41,8 +41,8 @@ func TestIssueToken(t *testing.T) { { desc: "issue token successfully", login: sdk.Login{ - Identity: client.Credentials.Username, - Secret: client.Credentials.Secret, + Username: client.Credentials.Username, + Password: client.Credentials.Secret, }, svcRes: &grpcTokenV1.Token{ AccessToken: token.AccessToken, @@ -56,8 +56,8 @@ func TestIssueToken(t *testing.T) { { desc: "issue token with invalid identity", login: sdk.Login{ - Identity: invalidIdentity, - Secret: client.Credentials.Secret, + Username: invalidIdentity, + Password: client.Credentials.Secret, }, svcRes: &grpcTokenV1.Token{}, svcErr: svcerr.ErrAuthentication, @@ -67,8 +67,8 @@ func TestIssueToken(t *testing.T) { { desc: "issue token with invalid secret", login: sdk.Login{ - Identity: client.Credentials.Username, - Secret: "invalid", + Username: client.Credentials.Username, + Password: "invalid", }, svcRes: &grpcTokenV1.Token{}, svcErr: svcerr.ErrLogin, @@ -78,8 +78,8 @@ func TestIssueToken(t *testing.T) { { desc: "issue token with empty identity", login: sdk.Login{ - Identity: "", - Secret: client.Credentials.Secret, + Username: "", + Password: client.Credentials.Secret, }, svcRes: &grpcTokenV1.Token{}, svcErr: nil, @@ -89,8 +89,8 @@ func TestIssueToken(t *testing.T) { { desc: "issue token with empty secret", login: sdk.Login{ - Identity: client.Credentials.Username, - Secret: "", + Username: client.Credentials.Username, + Password: "", }, svcRes: &grpcTokenV1.Token{}, svcErr: nil, @@ -100,12 +100,12 @@ func TestIssueToken(t *testing.T) { } for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { - svcCall := svc.On("IssueToken", mock.Anything, tc.login.Identity, tc.login.Secret).Return(tc.svcRes, tc.svcErr) + svcCall := svc.On("IssueToken", mock.Anything, tc.login.Username, tc.login.Password).Return(tc.svcRes, tc.svcErr) resp, err := mgsdk.CreateToken(tc.login) assert.Equal(t, tc.err, err) assert.Equal(t, tc.response, resp) if tc.err == nil { - ok := svcCall.Parent.AssertCalled(t, "IssueToken", mock.Anything, tc.login.Identity, tc.login.Secret) + ok := svcCall.Parent.AssertCalled(t, "IssueToken", mock.Anything, tc.login.Username, tc.login.Password) assert.True(t, ok) } svcCall.Unset() diff --git a/pkg/sdk/users.go b/pkg/sdk/users.go index a14982e67..41c384e91 100644 --- a/pkg/sdk/users.go +++ b/pkg/sdk/users.go @@ -9,7 +9,7 @@ import ( "net/http" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" ) diff --git a/pkg/sdk/users_test.go b/pkg/sdk/users_test.go index 84eb41eb9..611db2be4 100644 --- a/pkg/sdk/users_test.go +++ b/pkg/sdk/users_test.go @@ -10,11 +10,11 @@ import ( "strings" "testing" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" authmocks "github.com/absmach/supermq/auth/mocks" - internalapi "github.com/absmach/supermq/internal/api" grpcTokenV1 "github.com/absmach/supermq/internal/grpc/token/v1" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" @@ -23,7 +23,7 @@ import ( oauth2mocks "github.com/absmach/supermq/pkg/oauth2/mocks" sdk "github.com/absmach/supermq/pkg/sdk" "github.com/absmach/supermq/users" - "github.com/absmach/supermq/users/api" + httpapi "github.com/absmach/supermq/users/api" umocks "github.com/absmach/supermq/users/mocks" "github.com/go-chi/chi/v5" "github.com/stretchr/testify/assert" @@ -43,7 +43,7 @@ func setupUsers() (*httptest.Server, *umocks.Service, *authnmocks.Authentication provider.On("Name").Return("test") authn := new(authnmocks.Authentication) token := new(authmocks.TokenServiceClient) - api.MakeHandler(usvc, authn, token, true, mux, logger, "", passRegex, provider) + httpapi.MakeHandler(usvc, authn, token, true, mux, logger, "", passRegex, provider) return httptest.NewServer(mux), usvc, authn } @@ -320,8 +320,8 @@ func TestListUsers(t *testing.T) { svcReq: users.Page{ Offset: offset, Limit: limit, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: users.UsersPage{ Page: users.Page{ @@ -348,8 +348,8 @@ func TestListUsers(t *testing.T) { svcReq: users.Page{ Offset: offset, Limit: limit, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: users.UsersPage{}, svcErr: svcerr.ErrAuthentication, @@ -381,8 +381,8 @@ func TestListUsers(t *testing.T) { svcReq: users.Page{ Offset: offset, Limit: 10, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: users.UsersPage{ Page: users.Page{ @@ -423,8 +423,8 @@ func TestListUsers(t *testing.T) { Offset: offset, Limit: limit, Metadata: users.Metadata{"name": "user_99"}, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: users.UsersPage{ Page: users.Page{ @@ -453,8 +453,8 @@ func TestListUsers(t *testing.T) { Offset: offset, Limit: limit, Status: users.DisabledStatus, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: users.UsersPage{ Page: users.Page{ @@ -483,8 +483,8 @@ func TestListUsers(t *testing.T) { Offset: offset, Limit: limit, Tag: "tag1", - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: users.UsersPage{ Page: users.Page{ @@ -514,8 +514,8 @@ func TestListUsers(t *testing.T) { svcReq: users.Page{ Offset: offset, Limit: limit, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: users.UsersPage{}, svcErr: nil, @@ -532,8 +532,8 @@ func TestListUsers(t *testing.T) { svcReq: users.Page{ Offset: offset, Limit: limit, - Order: internalapi.DefOrder, - Dir: internalapi.DefDir, + Order: api.DefOrder, + Dir: api.DefDir, }, svcRes: users.UsersPage{ Page: users.Page{ diff --git a/pkg/server/coap/coap.go b/pkg/server/coap/coap.go index e2156ec05..66b185284 100644 --- a/pkg/server/coap/coap.go +++ b/pkg/server/coap/coap.go @@ -32,7 +32,7 @@ func NewServer(ctx context.Context, cancel context.CancelFunc, name string, conf func (s *coapServer) Start() error { errCh := make(chan error) - s.Logger.Info(fmt.Sprintf("%s service started using http, exposed port %s", s.Name, s.Address)) + s.Logger.Info(fmt.Sprintf("%s service started using HTTP, exposed port %s", s.Name, s.Address)) s.Logger.Info(fmt.Sprintf("%s service %s server listening at %s without TLS", s.Name, s.Protocol, s.Address)) go func() { diff --git a/provision/api/endpoint.go b/provision/api/endpoint.go index cf41e5d3e..c4e0fae0d 100644 --- a/provision/api/endpoint.go +++ b/provision/api/endpoint.go @@ -6,7 +6,7 @@ package api import ( "context" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" "github.com/absmach/supermq/provision" "github.com/go-kit/kit/endpoint" diff --git a/provision/api/endpoint_test.go b/provision/api/endpoint_test.go index ca6680bde..ea58c2113 100644 --- a/provision/api/endpoint_test.go +++ b/provision/api/endpoint_test.go @@ -11,9 +11,9 @@ import ( "strings" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/absmach/supermq/provision" "github.com/absmach/supermq/provision/api" diff --git a/provision/api/requests.go b/provision/api/requests.go index 9ae254e3c..60f9106a9 100644 --- a/provision/api/requests.go +++ b/provision/api/requests.go @@ -3,7 +3,7 @@ package api -import "github.com/absmach/supermq/pkg/apiutil" +import apiutil "github.com/absmach/supermq/api/http/util" type provisionReq struct { token string diff --git a/provision/api/requests_test.go b/provision/api/requests_test.go index 3db3380fc..1fcc7626f 100644 --- a/provision/api/requests_test.go +++ b/provision/api/requests_test.go @@ -7,8 +7,8 @@ import ( "fmt" "testing" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/errors" "github.com/stretchr/testify/assert" ) diff --git a/provision/api/transport.go b/provision/api/transport.go index f6f1b852f..911cf68e9 100644 --- a/provision/api/transport.go +++ b/provision/api/transport.go @@ -10,8 +10,8 @@ import ( "net/http" "github.com/absmach/supermq" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/errors" "github.com/absmach/supermq/provision" "github.com/go-chi/chi/v5" diff --git a/provision/service.go b/provision/service.go index 520a7bb4e..b5000dd18 100644 --- a/provision/service.go +++ b/provision/service.go @@ -294,8 +294,8 @@ func (ps *provisionService) createTokenIfEmpty(token string) (string, error) { } u := sdk.Login{ - Identity: ps.conf.Server.MgUsername, - Secret: ps.conf.Server.MgPass, + Username: ps.conf.Server.MgUsername, + Password: ps.conf.Server.MgPass, } tkn, err := ps.sdk.CreateToken(u) if err != nil { diff --git a/provision/service_test.go b/provision/service_test.go index d5ed1efb1..732c9fd90 100644 --- a/provision/service_test.go +++ b/provision/service_test.go @@ -219,8 +219,8 @@ func TestCert(t *testing.T) { mgsdk.On("IssueCert", c.clientID, c.config.Cert.TTL, c.domainID, mock.Anything).Return(sdk.Cert{SerialNumber: c.serial}, c.sdkCertErr) mgsdk.On("ViewCert", c.serial, mock.Anything, mock.Anything).Return(sdk.Cert{Certificate: c.cert, Key: c.key}, c.sdkCertErr) login := sdk.Login{ - Identity: c.config.Server.MgUsername, - Secret: c.config.Server.MgPass, + Username: c.config.Server.MgUsername, + Password: c.config.Server.MgPass, } mgsdk.On("CreateToken", login).Return(sdk.Token{AccessToken: validToken}, c.sdkTokenErr) cert, key, err := svc.Cert(c.domainID, c.token, c.clientID, c.ttl) diff --git a/readers/api/endpoint.go b/readers/api/endpoint.go index 21c15e345..83da0e5f8 100644 --- a/readers/api/endpoint.go +++ b/readers/api/endpoint.go @@ -6,9 +6,9 @@ package api import ( "context" + apiutil "github.com/absmach/supermq/api/http/util" grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/readers/api/endpoint_test.go b/readers/api/endpoint_test.go index 27502c6fd..1eef9ebbc 100644 --- a/readers/api/endpoint_test.go +++ b/readers/api/endpoint_test.go @@ -11,12 +11,12 @@ import ( "testing" "time" + apiutil "github.com/absmach/supermq/api/http/util" chmocks "github.com/absmach/supermq/channels/mocks" climocks "github.com/absmach/supermq/clients/mocks" grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" svcerr "github.com/absmach/supermq/pkg/errors/service" diff --git a/readers/api/requests.go b/readers/api/requests.go index eadfe9736..a39dd5834 100644 --- a/readers/api/requests.go +++ b/readers/api/requests.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/readers" ) diff --git a/readers/api/transport.go b/readers/api/transport.go index bab37b263..39769f1ed 100644 --- a/readers/api/transport.go +++ b/readers/api/transport.go @@ -9,9 +9,9 @@ import ( "net/http" "github.com/absmach/supermq" + apiutil "github.com/absmach/supermq/api/http/util" grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/connections" "github.com/absmach/supermq/pkg/errors" diff --git a/tools/config/golangci.yml b/tools/config/golangci.yml index 9dd682643..8c1b5f017 100644 --- a/tools/config/golangci.yml +++ b/tools/config/golangci.yml @@ -32,7 +32,10 @@ linters-settings: alias: repoerr - pkg: github.com/absmach/supermq/pkg/sdk/mocks alias: sdkmocks - + - pkg: github.com/absmach/supermq/api/http/util + alias: apiutil + - pkg: github.com/absmach/supermq/api/http + alias: api gocritic: enabled-checks: - importShadow diff --git a/tools/e2e/e2e.go b/tools/e2e/e2e.go index 66785b1a8..48f2f074f 100644 --- a/tools/e2e/e2e.go +++ b/tools/e2e/e2e.go @@ -149,8 +149,8 @@ func createUser(s sdk.SDK, conf Config) (string, string, error) { } login := sdk.Login{ - Identity: user.Credentials.Username, - Secret: user.Credentials.Secret, + Username: user.Credentials.Username, + Password: user.Credentials.Secret, } token, err := s.CreateToken(login) if err != nil { @@ -170,8 +170,8 @@ func createUser(s sdk.SDK, conf Config) (string, string, error) { } login = sdk.Login{ - Identity: user.Credentials.Username, - Secret: user.Credentials.Secret, + Username: user.Credentials.Username, + Password: user.Credentials.Secret, } token, err = s.CreateToken(login) if err != nil { diff --git a/tools/provision/provision.go b/tools/provision/provision.go index e21c7ab45..35258fe57 100644 --- a/tools/provision/provision.go +++ b/tools/provision/provision.go @@ -95,7 +95,7 @@ func Provision(conf Config) error { var err error // Login user - token, err := s.CreateToken(sdk.Login{Identity: user.Credentials.Username, Secret: user.Credentials.Secret}) + token, err := s.CreateToken(sdk.Login{Username: user.Credentials.Username, Password: user.Credentials.Secret}) if err != nil { return fmt.Errorf("unable to login user: %s", err.Error()) } @@ -114,8 +114,8 @@ func Provision(conf Config) error { } // Login to domain token, err = s.CreateToken(sdk.Login{ - Identity: user.Credentials.Username, - Secret: user.Credentials.Secret, + Username: user.Credentials.Username, + Password: user.Credentials.Secret, }) if err != nil { return fmt.Errorf("unable to login user: %w", err) diff --git a/users/api/endpoint_test.go b/users/api/endpoint_test.go index 147461500..8dbd5a2c5 100644 --- a/users/api/endpoint_test.go +++ b/users/api/endpoint_test.go @@ -13,19 +13,19 @@ import ( "strings" "testing" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" authmocks "github.com/absmach/supermq/auth/mocks" - "github.com/absmach/supermq/internal/api" grpcTokenV1 "github.com/absmach/supermq/internal/grpc/token/v1" "github.com/absmach/supermq/internal/testsutil" smqlog "github.com/absmach/supermq/logger" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" authnmocks "github.com/absmach/supermq/pkg/authn/mocks" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" oauth2mocks "github.com/absmach/supermq/pkg/oauth2/mocks" "github.com/absmach/supermq/users" - httpapi "github.com/absmach/supermq/users/api" + usersapi "github.com/absmach/supermq/users/api" "github.com/absmach/supermq/users/mocks" "github.com/go-chi/chi/v5" "github.com/stretchr/testify/assert" @@ -93,7 +93,7 @@ func newUsersServer() (*httptest.Server, *mocks.Service, *authnmocks.Authenticat provider.On("Name").Return("test") authn := new(authnmocks.Authentication) token := new(authmocks.TokenServiceClient) - httpapi.MakeHandler(svc, authn, token, true, mux, logger, "", passRegex, provider) + usersapi.MakeHandler(svc, authn, token, true, mux, logger, "", passRegex, provider) return httptest.NewServer(mux), svc, authn } @@ -2119,6 +2119,7 @@ func TestIssueToken(t *testing.T) { defer us.Close() validUsername := "valid" + dataFormat := `{"username": "%s", "password": "%s"}` cases := []struct { desc string @@ -2129,42 +2130,42 @@ func TestIssueToken(t *testing.T) { }{ { desc: "issue token with valid identity and secret", - data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, validUsername, secret), + data: fmt.Sprintf(dataFormat, validUsername, secret), contentType: contentType, status: http.StatusCreated, err: nil, }, { desc: "issue token with empty identity", - data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, "", secret), + data: fmt.Sprintf(dataFormat, "", secret), contentType: contentType, status: http.StatusBadRequest, err: apiutil.ErrValidation, }, { desc: "issue token with empty secret", - data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, validUsername, ""), + data: fmt.Sprintf(dataFormat, validUsername, ""), contentType: contentType, status: http.StatusBadRequest, err: apiutil.ErrValidation, }, { desc: "issue token with invalid email", - data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, "invalid", secret), + data: fmt.Sprintf(dataFormat, "invalid", secret), contentType: contentType, status: http.StatusUnauthorized, err: svcerr.ErrAuthentication, }, { desc: "issues token with malformed data", - data: fmt.Sprintf(`{"identity": %s, "secret": %s}`, validUsername, secret), + data: fmt.Sprintf(dataFormat, validUsername, secret), contentType: contentType, status: http.StatusBadRequest, err: apiutil.ErrValidation, }, { desc: "issue token with invalid contentype", - data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, "invalid", secret), + data: fmt.Sprintf(dataFormat, "invalid", secret), contentType: "application/xml", status: http.StatusUnsupportedMediaType, err: apiutil.ErrValidation, diff --git a/users/api/endpoints.go b/users/api/endpoints.go index 0df4c5ee8..3641dddb8 100644 --- a/users/api/endpoints.go +++ b/users/api/endpoints.go @@ -6,8 +6,8 @@ package api import ( "context" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" svcerr "github.com/absmach/supermq/pkg/errors/service" @@ -475,7 +475,7 @@ func issueTokenEndpoint(svc users.Service) endpoint.Endpoint { return nil, errors.Wrap(apiutil.ErrValidation, err) } - token, err := svc.IssueToken(ctx, req.Identity, req.Secret) + token, err := svc.IssueToken(ctx, req.Username, req.Password) if err != nil { return nil, err } diff --git a/users/api/requests.go b/users/api/requests.go index e2a4a2824..db71551ea 100644 --- a/users/api/requests.go +++ b/users/api/requests.go @@ -7,8 +7,8 @@ import ( "net/mail" "net/url" - "github.com/absmach/supermq/internal/api" - "github.com/absmach/supermq/pkg/apiutil" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" svcerr "github.com/absmach/supermq/pkg/errors/service" "github.com/absmach/supermq/users" ) @@ -259,15 +259,15 @@ func (req changeUserStatusReq) validate() error { } type loginUserReq struct { - Identity string `json:"identity,omitempty"` - Secret string `json:"secret,omitempty"` + Username string `json:"username,omitempty"` + Password string `json:"password,omitempty"` } func (req loginUserReq) validate() error { - if req.Identity == "" { + if req.Username == "" { return apiutil.ErrMissingIdentity } - if req.Secret == "" { + if req.Password == "" { return apiutil.ErrMissingPass } diff --git a/users/api/requests_test.go b/users/api/requests_test.go index 4da4d4881..a437373c8 100644 --- a/users/api/requests_test.go +++ b/users/api/requests_test.go @@ -8,9 +8,9 @@ import ( "strings" "testing" - "github.com/absmach/supermq/internal/api" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" "github.com/absmach/supermq/internal/testsutil" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/users" "github.com/stretchr/testify/assert" ) @@ -511,24 +511,24 @@ func TestLoginUserReqValidate(t *testing.T) { { desc: "valid request with identity", req: loginUserReq{ - Identity: "example", - Secret: secret, + Username: "example", + Password: secret, }, err: nil, }, { desc: "empty identity", req: loginUserReq{ - Identity: "", - Secret: secret, + Username: "", + Password: secret, }, err: apiutil.ErrMissingIdentity, }, { desc: "empty secret", req: loginUserReq{ - Secret: "", - Identity: "example", + Password: "", + Username: "example", }, err: apiutil.ErrMissingPass, }, diff --git a/users/api/users.go b/users/api/users.go index 06d2e6a5a..cdf099ab3 100644 --- a/users/api/users.go +++ b/users/api/users.go @@ -11,10 +11,10 @@ import ( "regexp" "strings" + api "github.com/absmach/supermq/api/http" + apiutil "github.com/absmach/supermq/api/http/util" smqauth "github.com/absmach/supermq/auth" - "github.com/absmach/supermq/internal/api" grpcTokenV1 "github.com/absmach/supermq/internal/grpc/token/v1" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" "github.com/absmach/supermq/pkg/oauth2" diff --git a/users/postgres/users.go b/users/postgres/users.go index 68be6e651..54c88820b 100644 --- a/users/postgres/users.go +++ b/users/postgres/users.go @@ -11,8 +11,8 @@ import ( "strings" "time" + api "github.com/absmach/supermq/api/http" "github.com/absmach/supermq/groups" - "github.com/absmach/supermq/internal/api" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" "github.com/absmach/supermq/pkg/postgres" diff --git a/users/roles.go b/users/roles.go index 8b51144e8..fede41e8a 100644 --- a/users/roles.go +++ b/users/roles.go @@ -7,7 +7,7 @@ import ( "encoding/json" "strings" - "github.com/absmach/supermq/pkg/apiutil" + apiutil "github.com/absmach/supermq/api/http/util" ) // Role represents User role. diff --git a/users/service.go b/users/service.go index 896275301..e11729027 100644 --- a/users/service.go +++ b/users/service.go @@ -9,9 +9,9 @@ import ( "time" "github.com/absmach/supermq" + apiutil "github.com/absmach/supermq/api/http/util" smqauth "github.com/absmach/supermq/auth" grpcTokenV1 "github.com/absmach/supermq/internal/grpc/token/v1" - "github.com/absmach/supermq/pkg/apiutil" "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/errors" repoerr "github.com/absmach/supermq/pkg/errors/repository" diff --git a/ws/handler.go b/ws/handler.go index 156594343..00594682c 100644 --- a/ws/handler.go +++ b/ws/handler.go @@ -13,9 +13,9 @@ import ( "time" "github.com/absmach/mgate/pkg/session" + apiutil "github.com/absmach/supermq/api/http/util" grpcChannelsV1 "github.com/absmach/supermq/internal/grpc/channels/v1" grpcClientsV1 "github.com/absmach/supermq/internal/grpc/clients/v1" - "github.com/absmach/supermq/pkg/apiutil" smqauthn "github.com/absmach/supermq/pkg/authn" "github.com/absmach/supermq/pkg/connections" "github.com/absmach/supermq/pkg/errors"