@@ -17,11 +17,15 @@ import (
1717 mgsdk "github.com/absmach/magistrala/pkg/sdk"
1818 "github.com/absmach/magistrala/provision"
1919 httpapi "github.com/absmach/magistrala/provision/api"
20+ "github.com/absmach/magistrala/provision/middleware"
2021 "github.com/absmach/supermq"
2122 "github.com/absmach/supermq/channels"
2223 "github.com/absmach/supermq/clients"
2324 smqlog "github.com/absmach/supermq/logger"
25+ smqauthn "github.com/absmach/supermq/pkg/authn"
26+ authnsvc "github.com/absmach/supermq/pkg/authn/authsvc"
2427 "github.com/absmach/supermq/pkg/errors"
28+ "github.com/absmach/supermq/pkg/grpcclient"
2529 "github.com/absmach/supermq/pkg/server"
2630 httpserver "github.com/absmach/supermq/pkg/server/http"
2731 "github.com/absmach/supermq/pkg/uuid"
@@ -30,8 +34,9 @@ import (
3034)
3135
3236const (
33- svcName = "provision"
34- contentType = "application/json"
37+ svcName = "provision"
38+ contentType = "application/json"
39+ envPrefixAuth = "SMQ_AUTH_GRPC_"
3540)
3641
3742var (
@@ -65,6 +70,24 @@ func main() {
6570 }
6671 }
6772
73+ grpcCfg := grpcclient.Config {}
74+ if err := env .ParseWithOptions (& grpcCfg , env.Options {Prefix : envPrefixAuth }); err != nil {
75+ logger .Error (fmt .Sprintf ("failed to load auth gRPC client configuration : %s" , err ))
76+ exitCode = 1
77+
78+ return
79+ }
80+ authn , authnClient , err := authnsvc .NewAuthentication (ctx , grpcCfg )
81+ if err != nil {
82+ logger .Error (err .Error ())
83+ exitCode = 1
84+
85+ return
86+ }
87+ defer authnClient .Close ()
88+ logger .Info ("AuthN successfully connected to auth gRPC server " + authnClient .Secure ())
89+ am := smqauthn .NewAuthNMiddleware (authn )
90+
6891 if cfgFromFile , err := loadConfigFromFile (cfg .File ); err != nil {
6992 logger .Warn (fmt .Sprintf ("Continue with settings from env, failed to load from: %s: %s" , cfg .File , err ))
7093 } else {
@@ -73,12 +96,14 @@ func main() {
7396 cfg = cfgFromFile
7497 logger .Info ("Continue with settings from file: " + cfg .File )
7598 }
99+ fmt .Printf ("This is the final config: %+v\n " , cfg )
76100
77101 SDKCfg := mgsdk.Config {
78102 UsersURL : cfg .Server .UsersURL ,
103+ ChannelsURL : cfg .Server .ChannelsURL ,
79104 ClientsURL : cfg .Server .ClientsURL ,
80105 BootstrapURL : cfg .Server .MgBSURL ,
81- CertsURL : cfg .Server .MgCertsURL ,
106+ CertsURL : cfg .Server .CertsURL ,
82107 MsgContentType : contentType ,
83108 TLSVerification : cfg .Server .TLS ,
84109 }
@@ -91,10 +116,10 @@ func main() {
91116 cSdk := csdk .NewSDK (csdkConf )
92117
93118 svc := provision .New (cfg , mgSdk , cSdk , logger )
94- svc = httpapi . NewLoggingMiddleware (svc , logger )
119+ svc = middleware . NewLogging (svc , logger )
95120
96121 httpServerConfig := server.Config {Host : "" , Port : cfg .Server .HTTPPort , KeyFile : cfg .Server .ServerKey , CertFile : cfg .Server .ServerCert }
97- hs := httpserver .NewServer (ctx , cancel , svcName , httpServerConfig , httpapi .MakeHandler (svc , logger , cfg .InstanceID ), logger )
122+ hs := httpserver .NewServer (ctx , cancel , svcName , httpServerConfig , httpapi .MakeHandler (svc , am , logger , cfg .InstanceID ), logger )
98123
99124 if cfg .SendTelemetry {
100125 chc := chclient .New (svcName , supermq .Version , logger , cancel )
0 commit comments