@@ -48,8 +48,8 @@ type authorizationMiddleware struct {
4848 svc channels.Service
4949 repo channels.Repository
5050 authz smqauthz.Authorization
51- opp svcutil .OperationPerm
52- extOpp svcutil .ExternalOperationPerm
51+ opp channels .OperationPerm
52+ extOpp channels .ExternalOperationPerm
5353 callout callout.Callout
5454 rmMW.RoleManagerAuthorizationMiddleware
5555}
@@ -59,8 +59,8 @@ func AuthorizationMiddleware(
5959 svc channels.Service ,
6060 repo channels.Repository ,
6161 authz smqauthz.Authorization ,
62- channelsOpPerm , rolesOpPerm map [svcutil .Operation ]svcutil .Permission ,
63- extOpPerm map [svcutil .ExternalOperation ]svcutil .Permission ,
62+ channelsOpPerm , rolesOpPerm map [channels .Operation ]channels .Permission ,
63+ extOpPerm map [channels .ExternalOperation ]channels .Permission ,
6464 callout callout.Callout ,
6565) (channels.Service , error ) {
6666 opp := channels .NewOperationPerm ()
@@ -78,7 +78,13 @@ func AuthorizationMiddleware(
7878 if err := extOpp .Validate (); err != nil {
7979 return nil , err
8080 }
81- ram , err := rmMW .NewRoleManagerAuthorizationMiddleware (policies .ChannelType , svc , authz , rolesOpPerm )
81+
82+ res := make (map [svcutil.Operation ]svcutil.Permission , len (rolesOpPerm ))
83+ for op , perm := range rolesOpPerm {
84+ res [svcutil .Operation (op )] = svcutil .Permission (perm )
85+ }
86+
87+ ram , err := rmMW .NewRoleManagerAuthorizationMiddleware (policies .ChannelType , svc , authz , res )
8288 if err != nil {
8389 return nil , err
8490 }
@@ -134,7 +140,7 @@ func (am *authorizationMiddleware) CreateChannels(ctx context.Context, session a
134140 "entities" : chs ,
135141 "count" : len (chs ),
136142 }
137- if err := am .callOut (ctx , session , channels .OpCreateChannel .String (channels . OperationNames ), params ); err != nil {
143+ if err := am .callOut (ctx , session , channels .OpCreateChannel .String (), params ); err != nil {
138144 return []channels.Channel {}, []roles.RoleProvision {}, err
139145 }
140146
@@ -167,7 +173,7 @@ func (am *authorizationMiddleware) ViewChannel(ctx context.Context, session auth
167173 params := map [string ]any {
168174 "entity_id" : id ,
169175 }
170- if err := am .callOut (ctx , session , channels .OpViewChannel .String (channels . OperationNames ), params ); err != nil {
176+ if err := am .callOut (ctx , session , channels .OpViewChannel .String (), params ); err != nil {
171177 return channels.Channel {}, err
172178 }
173179 return am .svc .ViewChannel (ctx , session , id , withRoles )
@@ -193,7 +199,7 @@ func (am *authorizationMiddleware) ListChannels(ctx context.Context, session aut
193199 params := map [string ]any {
194200 "pagemeta" : pm ,
195201 }
196- if err := am .callOut (ctx , session , channels .OpListChannels .String (channels . OperationNames ), params ); err != nil {
202+ if err := am .callOut (ctx , session , channels .OpListChannels .String (), params ); err != nil {
197203 return channels.ChannelsPage {}, err
198204 }
199205 return am .svc .ListChannels (ctx , session , pm )
@@ -219,7 +225,7 @@ func (am *authorizationMiddleware) ListUserChannels(ctx context.Context, session
219225 "user_id" : userID ,
220226 "pagemeta" : pm ,
221227 }
222- if err := am .callOut (ctx , session , channels .OpListUserChannels .String (channels . OperationNames ), params ); err != nil {
228+ if err := am .callOut (ctx , session , channels .OpListUserChannels .String (), params ); err != nil {
223229 return channels.ChannelsPage {}, err
224230 }
225231 return am .svc .ListUserChannels (ctx , session , userID , pm )
@@ -251,7 +257,7 @@ func (am *authorizationMiddleware) UpdateChannel(ctx context.Context, session au
251257 params := map [string ]any {
252258 "entity_id" : channel .ID ,
253259 }
254- if err := am .callOut (ctx , session , channels .OpUpdateChannel .String (channels . OperationNames ), params ); err != nil {
260+ if err := am .callOut (ctx , session , channels .OpUpdateChannel .String (), params ); err != nil {
255261 return channels.Channel {}, err
256262 }
257263 return am .svc .UpdateChannel (ctx , session , channel )
@@ -283,7 +289,7 @@ func (am *authorizationMiddleware) UpdateChannelTags(ctx context.Context, sessio
283289 params := map [string ]any {
284290 "entity_id" : channel .ID ,
285291 }
286- if err := am .callOut (ctx , session , channels .OpUpdateChannelTags .String (channels . OperationNames ), params ); err != nil {
292+ if err := am .callOut (ctx , session , channels .OpUpdateChannelTags .String (), params ); err != nil {
287293 return channels.Channel {}, err
288294 }
289295 return am .svc .UpdateChannelTags (ctx , session , channel )
@@ -315,7 +321,7 @@ func (am *authorizationMiddleware) EnableChannel(ctx context.Context, session au
315321 params := map [string ]any {
316322 "entity_id" : id ,
317323 }
318- if err := am .callOut (ctx , session , channels .OpEnableChannel .String (channels . OperationNames ), params ); err != nil {
324+ if err := am .callOut (ctx , session , channels .OpEnableChannel .String (), params ); err != nil {
319325 return channels.Channel {}, err
320326 }
321327 return am .svc .EnableChannel (ctx , session , id )
@@ -347,7 +353,7 @@ func (am *authorizationMiddleware) DisableChannel(ctx context.Context, session a
347353 params := map [string ]any {
348354 "entity_id" : id ,
349355 }
350- if err := am .callOut (ctx , session , channels .OpDisableChannel .String (channels . OperationNames ), params ); err != nil {
356+ if err := am .callOut (ctx , session , channels .OpDisableChannel .String (), params ); err != nil {
351357 return channels.Channel {}, err
352358 }
353359 return am .svc .DisableChannel (ctx , session , id )
@@ -378,7 +384,7 @@ func (am *authorizationMiddleware) RemoveChannel(ctx context.Context, session au
378384 params := map [string ]any {
379385 "entity_id" : id ,
380386 }
381- if err := am .callOut (ctx , session , channels .OpDeleteChannel .String (channels . OperationNames ), params ); err != nil {
387+ if err := am .callOut (ctx , session , channels .OpDeleteChannel .String (), params ); err != nil {
382388 return err
383389 }
384390
@@ -440,7 +446,7 @@ func (am *authorizationMiddleware) Connect(ctx context.Context, session authn.Se
440446 "client_ids" : thIDs ,
441447 "connection_types" : connTypes ,
442448 }
443- if err := am .callOut (ctx , session , channels .OpConnectClient .String (channels . OperationNames ), params ); err != nil {
449+ if err := am .callOut (ctx , session , channels .OpConnectClient .String (), params ); err != nil {
444450 return err
445451 }
446452 return am .svc .Connect (ctx , session , chIDs , thIDs , connTypes )
@@ -502,7 +508,7 @@ func (am *authorizationMiddleware) Disconnect(ctx context.Context, session authn
502508 "client_ids" : thIDs ,
503509 "connection_types" : connTypes ,
504510 }
505- if err := am .callOut (ctx , session , channels .OpDisconnectClient .String (channels . OperationNames ), params ); err != nil {
511+ if err := am .callOut (ctx , session , channels .OpDisconnectClient .String (), params ); err != nil {
506512 return err
507513 }
508514 return am .svc .Disconnect (ctx , session , chIDs , thIDs , connTypes )
@@ -545,7 +551,7 @@ func (am *authorizationMiddleware) SetParentGroup(ctx context.Context, session a
545551 "entity_id" : id ,
546552 "parent_group_id" : parentGroupID ,
547553 }
548- if err := am .callOut (ctx , session , channels .OpSetParentGroup .String (channels . OperationNames ), params ); err != nil {
554+ if err := am .callOut (ctx , session , channels .OpSetParentGroup .String (), params ); err != nil {
549555 return err
550556 }
551557 return am .svc .SetParentGroup (ctx , session , parentGroupID , id )
@@ -593,15 +599,15 @@ func (am *authorizationMiddleware) RemoveParentGroup(ctx context.Context, sessio
593599 "entity_id" : id ,
594600 "parent_group_id" : ch .ParentGroup ,
595601 }
596- if err := am .callOut (ctx , session , channels .OpRemoveParentGroup .String (channels . OperationNames ), params ); err != nil {
602+ if err := am .callOut (ctx , session , channels .OpRemoveParentGroup .String (), params ); err != nil {
597603 return err
598604 }
599605 return am .svc .RemoveParentGroup (ctx , session , id )
600606 }
601607 return nil
602608}
603609
604- func (am * authorizationMiddleware ) authorize (ctx context.Context , op svcutil .Operation , req smqauthz.PolicyReq ) error {
610+ func (am * authorizationMiddleware ) authorize (ctx context.Context , op channels .Operation , req smqauthz.PolicyReq ) error {
605611 perm , err := am .opp .GetPermission (op )
606612 if err != nil {
607613 return err
@@ -616,7 +622,7 @@ func (am *authorizationMiddleware) authorize(ctx context.Context, op svcutil.Ope
616622 return nil
617623}
618624
619- func (am * authorizationMiddleware ) extAuthorize (ctx context.Context , extOp svcutil .ExternalOperation , req smqauthz.PolicyReq ) error {
625+ func (am * authorizationMiddleware ) extAuthorize (ctx context.Context , extOp channels .ExternalOperation , req smqauthz.PolicyReq ) error {
620626 perm , err := am .extOpp .GetPermission (extOp )
621627 if err != nil {
622628 return err
0 commit comments