@@ -6,13 +6,11 @@ package middleware
66import (
77 "context"
88 "fmt"
9- "time"
109
1110 "github.com/absmach/supermq/auth"
1211 "github.com/absmach/supermq/channels"
1312 "github.com/absmach/supermq/pkg/authn"
1413 smqauthz "github.com/absmach/supermq/pkg/authz"
15- "github.com/absmach/supermq/pkg/callout"
1614 "github.com/absmach/supermq/pkg/connections"
1715 "github.com/absmach/supermq/pkg/errors"
1816 svcerr "github.com/absmach/supermq/pkg/errors/service"
@@ -44,12 +42,11 @@ var (
4442var _ channels.Service = (* authorizationMiddleware )(nil )
4543
4644type authorizationMiddleware struct {
47- svc channels.Service
48- repo channels.Repository
49- authz smqauthz.Authorization
50- opp svcutil.OperationPerm
51- extOpp svcutil.ExternalOperationPerm
52- callout callout.Callout
45+ svc channels.Service
46+ repo channels.Repository
47+ authz smqauthz.Authorization
48+ opp svcutil.OperationPerm
49+ extOpp svcutil.ExternalOperationPerm
5350 rolemw.RoleManagerAuthorizationMiddleware
5451}
5552
@@ -60,7 +57,6 @@ func NewAuthorization(
6057 authz smqauthz.Authorization ,
6158 channelsOpPerm , rolesOpPerm map [svcutil.Operation ]svcutil.Permission ,
6259 extOpPerm map [svcutil.ExternalOperation ]svcutil.Permission ,
63- callout callout.Callout ,
6460) (channels.Service , error ) {
6561 opp := channels .NewOperationPerm ()
6662 if err := opp .AddOperationPermissionMap (channelsOpPerm ); err != nil {
@@ -77,7 +73,8 @@ func NewAuthorization(
7773 if err := extOpp .Validate (); err != nil {
7874 return nil , err
7975 }
80- ram , err := rolemw .NewAuthorization (policies .ChannelType , svc , authz , rolesOpPerm , callout )
76+
77+ ram , err := rolemw .NewAuthorization (policies .ChannelType , svc , authz , rolesOpPerm )
8178 if err != nil {
8279 return nil , err
8380 }
@@ -89,7 +86,6 @@ func NewAuthorization(
8986 RoleManagerAuthorizationMiddleware : ram ,
9087 opp : opp ,
9188 extOpp : extOpp ,
92- callout : callout ,
9389 }, nil
9490}
9591
@@ -130,15 +126,6 @@ func (am *authorizationMiddleware) CreateChannels(ctx context.Context, session a
130126 }
131127 }
132128
133- params := map [string ]any {
134- "entities" : chs ,
135- "count" : len (chs ),
136- }
137-
138- if err := am .callOut (ctx , session , channels .OpCreateChannel .String (channels .OperationNames ), "" , params ); err != nil {
139- return []channels.Channel {}, []roles.RoleProvision {}, err
140- }
141-
142129 return am .svc .CreateChannels (ctx , session , chs ... )
143130}
144131
@@ -166,10 +153,6 @@ func (am *authorizationMiddleware) ViewChannel(ctx context.Context, session auth
166153 return channels.Channel {}, errors .Wrap (err , errView )
167154 }
168155
169- if err := am .callOut (ctx , session , channels .OpViewChannel .String (channels .OperationNames ), id , nil ); err != nil {
170- return channels.Channel {}, err
171- }
172-
173156 return am .svc .ViewChannel (ctx , session , id , withRoles )
174157}
175158
@@ -191,14 +174,6 @@ func (am *authorizationMiddleware) ListChannels(ctx context.Context, session aut
191174 session .SuperAdmin = true
192175 }
193176
194- params := map [string ]any {
195- "pagemeta" : pm ,
196- }
197-
198- if err := am .callOut (ctx , session , channels .OpListChannels .String (channels .OperationNames ), "" , params ); err != nil {
199- return channels.ChannelsPage {}, err
200- }
201-
202177 return am .svc .ListChannels (ctx , session , pm )
203178}
204179
@@ -219,15 +194,6 @@ func (am *authorizationMiddleware) ListUserChannels(ctx context.Context, session
219194 return channels.ChannelsPage {}, errors .Wrap (err , errList )
220195 }
221196
222- params := map [string ]any {
223- "user_id" : userID ,
224- "pagemeta" : pm ,
225- }
226-
227- if err := am .callOut (ctx , session , channels .OpListUserChannels .String (channels .OperationNames ), "" , params ); err != nil {
228- return channels.ChannelsPage {}, err
229- }
230-
231197 return am .svc .ListUserChannels (ctx , session , userID , pm )
232198}
233199
@@ -255,10 +221,6 @@ func (am *authorizationMiddleware) UpdateChannel(ctx context.Context, session au
255221 return channels.Channel {}, errors .Wrap (err , errUpdate )
256222 }
257223
258- if err := am .callOut (ctx , session , channels .OpUpdateChannel .String (channels .OperationNames ), channel .ID , nil ); err != nil {
259- return channels.Channel {}, err
260- }
261-
262224 return am .svc .UpdateChannel (ctx , session , channel )
263225}
264226
@@ -286,10 +248,6 @@ func (am *authorizationMiddleware) UpdateChannelTags(ctx context.Context, sessio
286248 return channels.Channel {}, errors .Wrap (err , errUpdateTags )
287249 }
288250
289- if err := am .callOut (ctx , session , channels .OpUpdateChannelTags .String (channels .OperationNames ), channel .ID , nil ); err != nil {
290- return channels.Channel {}, err
291- }
292-
293251 return am .svc .UpdateChannelTags (ctx , session , channel )
294252}
295253
@@ -317,10 +275,6 @@ func (am *authorizationMiddleware) EnableChannel(ctx context.Context, session au
317275 return channels.Channel {}, errors .Wrap (err , errEnable )
318276 }
319277
320- if err := am .callOut (ctx , session , channels .OpEnableChannel .String (channels .OperationNames ), id , nil ); err != nil {
321- return channels.Channel {}, err
322- }
323-
324278 return am .svc .EnableChannel (ctx , session , id )
325279}
326280
@@ -348,10 +302,6 @@ func (am *authorizationMiddleware) DisableChannel(ctx context.Context, session a
348302 return channels.Channel {}, errors .Wrap (err , errDisable )
349303 }
350304
351- if err := am .callOut (ctx , session , channels .OpDisableChannel .String (channels .OperationNames ), id , nil ); err != nil {
352- return channels.Channel {}, err
353- }
354-
355305 return am .svc .DisableChannel (ctx , session , id )
356306}
357307
@@ -378,10 +328,6 @@ func (am *authorizationMiddleware) RemoveChannel(ctx context.Context, session au
378328 return errors .Wrap (err , errDelete )
379329 }
380330
381- if err := am .callOut (ctx , session , channels .OpDeleteChannel .String (channels .OperationNames ), id , nil ); err != nil {
382- return err
383- }
384-
385331 return am .svc .RemoveChannel (ctx , session , id )
386332}
387333
@@ -436,16 +382,6 @@ func (am *authorizationMiddleware) Connect(ctx context.Context, session authn.Se
436382 }
437383 }
438384
439- params := map [string ]any {
440- "channel_ids" : chIDs ,
441- "client_ids" : thIDs ,
442- "connection_types" : connTypes ,
443- }
444-
445- if err := am .callOut (ctx , session , channels .OpConnectClient .String (channels .OperationNames ), "" , params ); err != nil {
446- return err
447- }
448-
449385 return am .svc .Connect (ctx , session , chIDs , thIDs , connTypes )
450386}
451387
@@ -501,16 +437,6 @@ func (am *authorizationMiddleware) Disconnect(ctx context.Context, session authn
501437 }
502438 }
503439
504- params := map [string ]any {
505- "channel_ids" : chIDs ,
506- "client_ids" : thIDs ,
507- "connection_types" : connTypes ,
508- }
509-
510- if err := am .callOut (ctx , session , channels .OpDisconnectClient .String (channels .OperationNames ), "" , params ); err != nil {
511- return err
512- }
513-
514440 return am .svc .Disconnect (ctx , session , chIDs , thIDs , connTypes )
515441}
516442
@@ -548,14 +474,6 @@ func (am *authorizationMiddleware) SetParentGroup(ctx context.Context, session a
548474 return errors .Wrap (err , errGroupSetChildChannels )
549475 }
550476
551- params := map [string ]any {
552- "parent_group_id" : parentGroupID ,
553- }
554-
555- if err := am .callOut (ctx , session , channels .OpSetParentGroup .String (channels .OperationNames ), id , params ); err != nil {
556- return err
557- }
558-
559477 return am .svc .SetParentGroup (ctx , session , parentGroupID , id )
560478}
561479
@@ -598,14 +516,6 @@ func (am *authorizationMiddleware) RemoveParentGroup(ctx context.Context, sessio
598516 return errors .Wrap (err , errGroupRemoveChildChannels )
599517 }
600518
601- params := map [string ]any {
602- "parent_group_id" : ch .ParentGroup ,
603- }
604-
605- if err := am .callOut (ctx , session , channels .OpRemoveParentGroup .String (channels .OperationNames ), id , params ); err != nil {
606- return err
607- }
608-
609519 return am .svc .RemoveParentGroup (ctx , session , id )
610520 }
611521 return nil
@@ -656,24 +566,3 @@ func (am *authorizationMiddleware) checkSuperAdmin(ctx context.Context, session
656566 }
657567 return nil
658568}
659-
660- func (am * authorizationMiddleware ) callOut (ctx context.Context , session authn.Session , op , entityID string , pld map [string ]any ) error {
661- req := callout.Request {
662- BaseRequest : callout.BaseRequest {
663- Operation : op ,
664- EntityType : policies .ChannelType ,
665- EntityID : entityID ,
666- CallerID : session .UserID ,
667- CallerType : policies .UserType ,
668- DomainID : session .DomainID ,
669- Time : time .Now ().UTC (),
670- },
671- Payload : pld ,
672- }
673-
674- if err := am .callout .Callout (ctx , req ); err != nil {
675- return err
676- }
677-
678- return nil
679- }
0 commit comments