Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ jobs:
run: |
git fetch --prune --unshallow --tags

- name: Get Go version from go.mod
id: go-version
run: echo "version=$(grep '^go ' go.mod | awk '{print $2}')" >> $GITHUB_OUTPUT

- name: Install Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: 1.24.x
go-version: ${{ steps.go-version.outputs.version }}
cache-dependency-path: "go.sum"

- name: Run tests
Expand Down
24 changes: 16 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
- name: Get Go version from go.mod
id: go-version
run: echo "version=$(grep '^go ' go.mod | awk '{print $2}')" >> $GITHUB_OUTPUT

- name: Install Go
uses: actions/setup-go@v6
with:
go-version: 1.24.x
go-version: ${{ steps.go-version.outputs.version }}
cache-dependency-path: "go.sum"

- name: golangci-lint
uses: golangci/golangci-lint-action@v7
uses: golangci/golangci-lint-action@v9
with:
version: v2.2.2
version: v2.4.0
args: --config ./tools/config/.golangci.yaml

- name: Build all Binaries
Expand All @@ -44,10 +48,14 @@ jobs:
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
- name: Get Go version from go.mod
id: go-version
run: echo "version=$(grep '^go ' go.mod | awk '{print $2}')" >> $GITHUB_OUTPUT

- name: Install Go
uses: actions/setup-go@v6
with:
go-version: 1.24.x
go-version: ${{ steps.go-version.outputs.version }}
cache-dependency-path: "go.sum"

- name: Check for changes in specific paths
Expand Down
37 changes: 15 additions & 22 deletions cmd/smpp-notifier/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

// Package main contains smtp-notifier main function to start the smtp-notifier service.
// Package main contains smpp-notifier main function to start the smpp-notifier service.
package main

import (
Expand All @@ -21,6 +21,7 @@ import (
"github.com/absmach/supermq-contrib/consumers/notifiers/tracing"
"github.com/absmach/supermq/consumers"
smqlog "github.com/absmach/supermq/logger"
smqauthn "github.com/absmach/supermq/pkg/authn"
"github.com/absmach/supermq/pkg/authn/authsvc"
"github.com/absmach/supermq/pkg/grpcclient"
jaegerclient "github.com/absmach/supermq/pkg/jaeger"
Expand All @@ -39,24 +40,22 @@ import (
)

const (
svcName = "smtp-notifier"
envPrefixDB = "SMQ_SMTP_NOTIFIER_DB_"
envPrefixHTTP = "SMQ_SMTP_NOTIFIER_HTTP_"
envPrefixAuth = "SMQ_AUTH_GRPC_"
envPrefixClients = "SMQ_CLIENTS_AUTH_GRPC_"
envPrefixChannels = "SMQ_CHANNELS_GRPC_"
defDB = "subscriptions"
defSvcHTTPPort = "9015"
svcName = "smpp-notifier"
envPrefixDB = "SMQ_SMPP_NOTIFIER_DB_"
envPrefixHTTP = "SMQ_SMPP_NOTIFIER_HTTP_"
envPrefixAuth = "SMQ_AUTH_GRPC_"
defDB = "subscriptions"
defSvcHTTPPort = "9015"
)

type config struct {
LogLevel string `env:"SMQ_SMTP_NOTIFIER_LOG_LEVEL" envDefault:"info"`
ConfigPath string `env:"SMQ_SMTP_NOTIFIER_CONFIG_PATH" envDefault:"/config.toml"`
From string `env:"SMQ_SMTP_NOTIFIER_FROM_ADDR" envDefault:""`
LogLevel string `env:"SMQ_SMPP_NOTIFIER_LOG_LEVEL" envDefault:"info"`
ConfigPath string `env:"SMQ_SMPP_NOTIFIER_CONFIG_PATH" envDefault:"/config.toml"`
From string `env:"SMQ_SMPP_NOTIFIER_FROM_ADDR" envDefault:""`
BrokerURL string `env:"SMQ_MESSAGE_BROKER_URL" envDefault:"nats://localhost:4222"`
JaegerURL url.URL `env:"SMQ_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"`
SendTelemetry bool `env:"SMQ_SEND_TELEMETRY" envDefault:"true"`
InstanceID string `env:"SMQ_SMTP_NOTIFIER_INSTANCE_ID" envDefault:""`
InstanceID string `env:"SMQ_SMPP_NOTIFIER_INSTANCE_ID" envDefault:""`
TraceRatio float64 `env:"SMQ_JAEGER_TRACE_RATIO" envDefault:"1.0"`
}

Expand Down Expand Up @@ -135,13 +134,6 @@ func main() {
defer pubSub.Close()
pubSub = brokerstracing.NewPubSub(httpServerConfig, tracer, pubSub)

clientsClientCfg := grpcclient.Config{}
if err := env.ParseWithOptions(&clientsClientCfg, env.Options{Prefix: envPrefixClients}); err != nil {
logger.Error(fmt.Sprintf("failed to load clients gRPC client configuration : %s", err))
exitCode = 1
return
}

authnCfg := grpcclient.Config{}
if err := env.ParseWithOptions(&authnCfg, env.Options{Prefix: envPrefixAuth}); err != nil {
logger.Error(fmt.Sprintf("failed to load auth gRPC client configuration : %s", err))
Expand All @@ -157,6 +149,7 @@ func main() {
}
defer authnHandler.Close()
logger.Info("authn successfully connected to auth gRPC server " + authnHandler.Secure())
authnMiddleware := smqauthn.NewAuthNMiddleware(authn)

svc := newService(db, tracer, cfg, smppConfig, logger)

Expand All @@ -166,7 +159,7 @@ func main() {
return
}

hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, authn, logger, cfg.InstanceID), logger)
hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, authnMiddleware, logger, cfg.InstanceID), logger)

if cfg.SendTelemetry {
chc := chclient.New(svcName, supermq.Version, logger, cancel)
Expand All @@ -182,7 +175,7 @@ func main() {
})

if err := g.Wait(); err != nil {
logger.Error(fmt.Sprintf("SMTP notifier service terminated: %s", err))
logger.Error(fmt.Sprintf("SMPP notifier service terminated: %s", err))
}
}

Expand Down
18 changes: 9 additions & 9 deletions cmd/smtp-notifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
email "github.com/absmach/supermq-contrib/pkg/email"
"github.com/absmach/supermq/consumers"
smqlog "github.com/absmach/supermq/logger"
smqauthn "github.com/absmach/supermq/pkg/authn"
"github.com/absmach/supermq/pkg/authn/authsvc"
"github.com/absmach/supermq/pkg/grpcclient"
jaegerclient "github.com/absmach/supermq/pkg/jaeger"
Expand All @@ -40,14 +41,12 @@ import (
)

const (
svcName = "smtp-notifier"
envPrefixDB = "SMQ_SMTP_NOTIFIER_DB_"
envPrefixHTTP = "SMQ_SMTP_NOTIFIER_HTTP_"
envPrefixAuth = "SMQ_AUTH_GRPC_"
envPrefixClients = "SMQ_CLIENTS_AUTH_GRPC_"
envPrefixChannels = "SMQ_CHANNELS_GRPC_"
defDB = "subscriptions"
defSvcHTTPPort = "9015"
svcName = "smtp-notifier"
envPrefixDB = "SMQ_SMTP_NOTIFIER_DB_"
envPrefixHTTP = "SMQ_SMTP_NOTIFIER_HTTP_"
envPrefixAuth = "SMQ_AUTH_GRPC_"
defDB = "subscriptions"
defSvcHTTPPort = "9015"
)

type config struct {
Expand Down Expand Up @@ -151,6 +150,7 @@ func main() {
}
defer authnHandler.Close()
logger.Info("authn successfully connected to auth gRPC server " + authnHandler.Secure())
authnMiddleware := smqauthn.NewAuthNMiddleware(authn)

svc, err := newService(db, tracer, cfg, ec, logger)
if err != nil {
Expand All @@ -165,7 +165,7 @@ func main() {
return
}

hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, authn, logger, cfg.InstanceID), logger)
hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, authnMiddleware, logger, cfg.InstanceID), logger)

if cfg.SendTelemetry {
chc := chclient.New(svcName, supermq.Version, logger, cancel)
Expand Down
9 changes: 4 additions & 5 deletions consumers/notifiers/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"

notifiers "github.com/absmach/supermq-contrib/consumers/notifiers"
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"
Expand All @@ -21,7 +20,7 @@ func createSubscriptionEndpoint(svc notifiers.Service) endpoint.Endpoint {
if err := req.validate(); err != nil {
return createSubRes{}, errors.Wrap(apiutil.ErrValidation, err)
}
session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(authn.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthentication
}
Expand All @@ -47,7 +46,7 @@ func viewSubscriptionEndpint(svc notifiers.Service) endpoint.Endpoint {
if err := req.validate(); err != nil {
return viewSubRes{}, errors.Wrap(apiutil.ErrValidation, err)
}
session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(authn.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthentication
}
Expand All @@ -71,7 +70,7 @@ func listSubscriptionsEndpoint(svc notifiers.Service) endpoint.Endpoint {
if err := req.validate(); err != nil {
return listSubsRes{}, errors.Wrap(apiutil.ErrValidation, err)
}
session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(authn.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthentication
}
Expand Down Expand Up @@ -111,7 +110,7 @@ func deleteSubscriptionEndpint(svc notifiers.Service) endpoint.Endpoint {
return nil, errors.Wrap(apiutil.ErrValidation, err)
}

session, ok := ctx.Value(api.SessionKey).(authn.Session)
session, ok := ctx.Value(authn.SessionKey).(authn.Session)
if !ok {
return nil, svcerr.ErrAuthentication
}
Expand Down
Loading
Loading