Skip to content

Commit

Permalink
Merge pull request #3485 from jamsman94/cp/3483
Browse files Browse the repository at this point in the history
cherrypick #3483
  • Loading branch information
jamsman94 authored Apr 19, 2024
2 parents 2cb6c22 + f8c2266 commit b75cbc3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions pkg/microservice/user/core/service/permission/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ package permission

import (
"fmt"
"time"

"github.com/koderover/zadig/v2/pkg/config"
"github.com/koderover/zadig/v2/pkg/tool/cache"
"github.com/koderover/zadig/v2/pkg/types"
"go.uber.org/zap"

Expand Down Expand Up @@ -117,7 +120,27 @@ func InitializeProjectAuthorization(namespace string, isPublic bool, admins []st
return fmt.Errorf("failed to bind project-admin role to given user list, error: %s", err)
}

roleCache := cache.NewRedisCache(config.RedisCommonCacheTokenDB())
// flush cache for every identity that is affected
for _, uid := range admins {
uidRoleKey := fmt.Sprintf(UIDRoleKeyFormat, uid)
err = roleCache.Delete(uidRoleKey)
if err != nil {
log.Warnf("failed to flush user-role cache for key: %s, error: %s", uidRoleKey, err)
}
}

tx.Commit()

go func(uids []string, redisCache *cache.RedisCache) {
time.Sleep(2 * time.Second)

for _, uid := range uids {
uidRoleKey := fmt.Sprintf(UIDRoleKeyFormat, uid)
err = roleCache.Delete(uidRoleKey)
}
}(admins, roleCache)

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/microservice/user/core/service/permission/role_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func CreateRoleBindings(role, ns string, identityList []*types.Identity, log *za
}

for _, gid := range groupIDList {
gidRoleKey := fmt.Sprintf(UIDRoleKeyFormat, gid)
gidRoleKey := fmt.Sprintf(GIDRoleKeyFormat, gid)
err = roleCache.Delete(gidRoleKey)
if err != nil {
log.Warnf("failed to flush user-role cache for key: %s, error: %s", gidRoleKey, err)
Expand All @@ -259,7 +259,7 @@ func CreateRoleBindings(role, ns string, identityList []*types.Identity, log *za
}

for _, gid := range gids {
gidRoleKey := fmt.Sprintf(UIDRoleKeyFormat, gid)
gidRoleKey := fmt.Sprintf(GIDRoleKeyFormat, gid)
err = roleCache.Delete(gidRoleKey)
}
}(userIDList, groupIDList, roleCache)
Expand Down

0 comments on commit b75cbc3

Please sign in to comment.