Skip to content

Commit

Permalink
Use import alias consistently
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Borovcanin <[email protected]>
  • Loading branch information
dborovcanin committed Dec 19, 2024
1 parent 5443000 commit c66c4df
Show file tree
Hide file tree
Showing 48 changed files with 551 additions and 551 deletions.
10 changes: 5 additions & 5 deletions auth/api/http/keys/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
"strings"

api "github.com/absmach/supermq/api/http"
httpapi "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/auth"
"github.com/absmach/supermq/pkg/errors"
Expand All @@ -23,27 +23,27 @@ const contentType = "application/json"
// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(svc auth.Service, mux *chi.Mux, logger *slog.Logger) *chi.Mux {
opts := []kithttp.ServerOption{
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, api.EncodeError)),
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, httpapi.EncodeError)),
}
mux.Route("/keys", func(r chi.Router) {
r.Post("/", kithttp.NewServer(
issueEndpoint(svc),
decodeIssue,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Get("/{id}", kithttp.NewServer(
(retrieveEndpoint(svc)),
decodeKeyReq,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Delete("/{id}", kithttp.NewServer(
(revokeEndpoint(svc)),
decodeKeyReq,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)
})
Expand Down
30 changes: 15 additions & 15 deletions auth/api/http/pats/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
"strings"

api "github.com/absmach/supermq/api/http"
httpapi "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/auth"
"github.com/absmach/supermq/pkg/errors"
Expand All @@ -27,64 +27,64 @@ const (
// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(svc auth.Service, mux *chi.Mux, logger *slog.Logger) *chi.Mux {
opts := []kithttp.ServerOption{
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, api.EncodeError)),
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, httpapi.EncodeError)),
}
mux.Route("/pats", func(r chi.Router) {
r.Post("/", kithttp.NewServer(
createPATEndpoint(svc),
decodeCreatePATRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Get("/", kithttp.NewServer(
listPATSEndpoint(svc),
decodeListPATSRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Route("/{id}", func(r chi.Router) {
r.Get("/", kithttp.NewServer(
retrievePATEndpoint(svc),
decodeRetrievePATRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Patch("/name", kithttp.NewServer(
updatePATNameEndpoint(svc),
decodeUpdatePATNameRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Patch("/description", kithttp.NewServer(
updatePATDescriptionEndpoint(svc),
decodeUpdatePATDescriptionRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Delete("/", kithttp.NewServer(
deletePATEndpoint(svc),
decodeDeletePATRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Route("/secret", func(r chi.Router) {
r.Patch("/reset", kithttp.NewServer(
resetPATSecretEndpoint(svc),
decodeResetPATSecretRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Patch("/revoke", kithttp.NewServer(
revokePATSecretEndpoint(svc),
decodeRevokePATSecretRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)
})
Expand All @@ -93,21 +93,21 @@ func MakeHandler(svc auth.Service, mux *chi.Mux, logger *slog.Logger) *chi.Mux {
r.Patch("/add", kithttp.NewServer(
addPATScopeEntryEndpoint(svc),
decodeAddPATScopeEntryRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Patch("/remove", kithttp.NewServer(
removePATScopeEntryEndpoint(svc),
decodeRemovePATScopeEntryRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)

r.Delete("/", kithttp.NewServer(
clearPATAllScopeEntryEndpoint(svc),
decodeClearPATAllScopeEntryRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
).ServeHTTP)
})
Expand Down Expand Up @@ -182,11 +182,11 @@ func decodeUpdatePATDescriptionRequest(_ context.Context, r *http.Request) (inte
}

func decodeListPATSRequest(_ context.Context, r *http.Request) (interface{}, error) {
l, err := apiutil.ReadNumQuery[uint64](r, api.LimitKey, api.DefLimit)
l, err := apiutil.ReadNumQuery[uint64](r, httpapi.LimitKey, httpapi.DefLimit)
if err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}
o, err := apiutil.ReadNumQuery[uint64](r, api.OffsetKey, api.DefOffset)
o, err := apiutil.ReadNumQuery[uint64](r, httpapi.OffsetKey, httpapi.DefOffset)
if err != nil {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}
Expand Down
18 changes: 9 additions & 9 deletions bootstrap/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package api
import (
"context"

api "github.com/absmach/supermq/api/http"
httpapi "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/bootstrap"
"github.com/absmach/supermq/pkg/authn"
Expand All @@ -22,7 +22,7 @@ func addEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}

session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(httpapi.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthorization
}
Expand Down Expand Up @@ -65,7 +65,7 @@ func updateCertEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}

session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(httpapi.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthorization
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func viewEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}

session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(httpapi.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthorization
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func updateEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}

session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(httpapi.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthorization
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func updateConnEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}

session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(httpapi.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthorization
}
Expand All @@ -190,7 +190,7 @@ func listEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}

session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(httpapi.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthorization
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func removeEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return removeRes{}, errors.Wrap(apiutil.ErrValidation, err)
}

session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(httpapi.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthorization
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func stateEndpoint(svc bootstrap.Service) endpoint.Endpoint {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}

session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(httpapi.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthorization
}
Expand Down
28 changes: 14 additions & 14 deletions bootstrap/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"

"github.com/absmach/supermq"
api "github.com/absmach/supermq/api/http"
httpapi "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/bootstrap"
smqauthn "github.com/absmach/supermq/pkg/authn"
Expand Down Expand Up @@ -42,77 +42,77 @@ var (
// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(svc bootstrap.Service, authn smqauthn.Authentication, reader bootstrap.ConfigReader, logger *slog.Logger, instanceID string) http.Handler {
opts := []kithttp.ServerOption{
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, api.EncodeError)),
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, httpapi.EncodeError)),
}

r := chi.NewRouter()

r.Route("/{domainID}/clients", func(r chi.Router) {
r.Group(func(r chi.Router) {
r.Use(api.AuthenticateMiddleware(authn, true))
r.Use(httpapi.AuthenticateMiddleware(authn, true))

r.Route("/configs", func(r chi.Router) {
r.Post("/", otelhttp.NewHandler(kithttp.NewServer(
addEndpoint(svc),
decodeAddRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "add").ServeHTTP)

r.Get("/", otelhttp.NewHandler(kithttp.NewServer(
listEndpoint(svc),
decodeListRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "list").ServeHTTP)

r.Get("/{configID}", otelhttp.NewHandler(kithttp.NewServer(
viewEndpoint(svc),
decodeEntityRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "view").ServeHTTP)

r.Put("/{configID}", otelhttp.NewHandler(kithttp.NewServer(
updateEndpoint(svc),
decodeUpdateRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "update").ServeHTTP)

r.Delete("/{configID}", otelhttp.NewHandler(kithttp.NewServer(
removeEndpoint(svc),
decodeEntityRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "remove").ServeHTTP)

r.Patch("/certs/{certID}", otelhttp.NewHandler(kithttp.NewServer(
updateCertEndpoint(svc),
decodeUpdateCertRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "update_cert").ServeHTTP)

r.Put("/connections/{connID}", otelhttp.NewHandler(kithttp.NewServer(
updateConnEndpoint(svc),
decodeUpdateConnRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "update_connections").ServeHTTP)
})
})

r.With(api.AuthenticateMiddleware(authn, true)).Put("/state/{clientID}", otelhttp.NewHandler(kithttp.NewServer(
r.With(httpapi.AuthenticateMiddleware(authn, true)).Put("/state/{clientID}", otelhttp.NewHandler(kithttp.NewServer(
stateEndpoint(svc),
decodeStateRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "update_state").ServeHTTP)
})

r.Route("/clients/bootstrap", func(r chi.Router) {
r.Get("/", otelhttp.NewHandler(kithttp.NewServer(
bootstrapEndpoint(svc, reader, false),
decodeBootstrapRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "bootstrap").ServeHTTP)
r.Get("/{externalID}", otelhttp.NewHandler(kithttp.NewServer(
bootstrapEndpoint(svc, reader, false),
decodeBootstrapRequest,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...), "bootstrap").ServeHTTP)
r.Get("/secure/{externalID}", otelhttp.NewHandler(kithttp.NewServer(
bootstrapEndpoint(svc, reader, true),
Expand Down
14 changes: 7 additions & 7 deletions certs/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"

"github.com/absmach/supermq"
api "github.com/absmach/supermq/api/http"
httpapi "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/certs"
smqauthn "github.com/absmach/supermq/pkg/authn"
Expand All @@ -34,38 +34,38 @@ const (
// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(svc certs.Service, authn smqauthn.Authentication, logger *slog.Logger, instanceID string) http.Handler {
opts := []kithttp.ServerOption{
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, api.EncodeError)),
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, httpapi.EncodeError)),
}

r := chi.NewRouter()

r.Group(func(r chi.Router) {
r.Use(api.AuthenticateMiddleware(authn, true))
r.Use(httpapi.AuthenticateMiddleware(authn, true))
r.Route("/{domainID}", func(r chi.Router) {
r.Route("/certs", func(r chi.Router) {
r.Post("/", otelhttp.NewHandler(kithttp.NewServer(
issueCert(svc),
decodeCerts,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
), "issue").ServeHTTP)
r.Get("/{certID}", otelhttp.NewHandler(kithttp.NewServer(
viewCert(svc),
decodeViewCert,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
), "view").ServeHTTP)
r.Delete("/{certID}", otelhttp.NewHandler(kithttp.NewServer(
revokeCert(svc),
decodeRevokeCerts,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
), "revoke").ServeHTTP)
})
r.Get("/serials/{clientID}", otelhttp.NewHandler(kithttp.NewServer(
listSerials(svc),
decodeListCerts,
api.EncodeResponse,
httpapi.EncodeResponse,
opts...,
), "list_serials").ServeHTTP)
})
Expand Down
Loading

0 comments on commit c66c4df

Please sign in to comment.