mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
NOISSUE - Move API to the common package (#2608)
Signed-off-by: Dusan Borovcanin <borovcanindusan1@gmail.com>
This commit is contained in:
@@ -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
|
||||
@@ -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)
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package apiutil
|
||||
package util
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package apiutil
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
+1
-1
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
+1
-1
@@ -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"
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
+5
-5
@@ -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)
|
||||
|
||||
+4
-4
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
+6
-6
@@ -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()
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
@@ -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",]
|
||||
@@ -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"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"github.com/absmach/supermq/pkg/apiutil"
|
||||
apiutil "github.com/absmach/supermq/api/http/util"
|
||||
)
|
||||
|
||||
type deleteUserPoliciesReq struct {
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user