mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
Merge pull request #6895 from yousong/automated-cherry-pick-of-#6893-upstream-release-3.2
Automated cherry pick of #6893: cloudcommon: app: cosmetic change
This commit is contained in:
@@ -87,8 +87,9 @@ func InitAuth(options *common_options.CommonOptions, authComplete auth.AuthCompl
|
||||
|
||||
func InitBaseAuth(options *common_options.BaseOptions) {
|
||||
if options.EnableRbac {
|
||||
policy.EnableGlobalRbac(time.Duration(options.RbacPolicySyncPeriodSeconds)*time.Second,
|
||||
time.Duration(options.RbacPolicySyncFailedRetrySeconds)*time.Second,
|
||||
policy.EnableGlobalRbac(
|
||||
time.Second*time.Duration(options.RbacPolicySyncPeriodSeconds),
|
||||
time.Second*time.Duration(options.RbacPolicySyncFailedRetrySeconds),
|
||||
options.RbacDebug,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -191,11 +192,33 @@ func (manager *SPolicyManager) start(refreshInterval time.Duration, retryInterva
|
||||
|
||||
manager.cache = hashcache.NewCache(2048, manager.refreshInterval/2)
|
||||
|
||||
manager.SyncOnce()
|
||||
manager.syncByInterval()
|
||||
}
|
||||
|
||||
func (manager *SPolicyManager) syncByInterval() {
|
||||
syncWorkerManager.Run(manager.syncByInterval_, nil, nil)
|
||||
}
|
||||
|
||||
func (manager *SPolicyManager) syncByInterval_() {
|
||||
err := manager.doSync()
|
||||
var interval time.Duration
|
||||
if err != nil {
|
||||
interval = manager.failedRetryInterval
|
||||
} else {
|
||||
interval = manager.refreshInterval
|
||||
}
|
||||
time.AfterFunc(interval, manager.syncByInterval)
|
||||
}
|
||||
|
||||
var syncOnce int32
|
||||
|
||||
func (manager *SPolicyManager) SyncOnce() {
|
||||
syncWorkerManager.Run(manager.sync, nil, nil)
|
||||
if atomic.CompareAndSwapInt32(&syncOnce, 0, 1) {
|
||||
syncWorkerManager.Run(func() {
|
||||
atomic.StoreInt32(&syncOnce, 0)
|
||||
manager.doSync()
|
||||
}, nil, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *SPolicyManager) doSync() error {
|
||||
@@ -223,17 +246,6 @@ func (manager *SPolicyManager) doSync() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SPolicyManager) sync() {
|
||||
err := manager.doSync()
|
||||
var interval time.Duration
|
||||
if err != nil {
|
||||
interval = manager.failedRetryInterval
|
||||
} else {
|
||||
interval = manager.refreshInterval
|
||||
}
|
||||
time.AfterFunc(interval, manager.SyncOnce)
|
||||
}
|
||||
|
||||
func queryKey(scope rbacutils.TRbacScope, userCred mcclient.TokenCredential, service string, resource string, action string, extra ...string) string {
|
||||
queryKeys := []string{string(scope)}
|
||||
queryKeys = append(queryKeys, userCred.GetProjectId(), userCred.GetDomainId(), userCred.GetUserId())
|
||||
|
||||
Reference in New Issue
Block a user