From dbab380d734d0de1684f5cb4472869d5d981d773 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Fri, 9 Nov 2018 15:52:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0climc=20policy-admin-capable?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/climc/shell/policies.go | 12 ++++++++++++ pkg/cloudcommon/policy/global.go | 6 ++++-- pkg/scheduler/manager/task_queue.go | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/climc/shell/policies.go b/cmd/climc/shell/policies.go index 5bf125cfd2..ec9cd07bec 100644 --- a/cmd/climc/shell/policies.go +++ b/cmd/climc/shell/policies.go @@ -184,6 +184,18 @@ func init() { return nil }) + type PolicyAdminCapableOptions struct { + } + R(&PolicyAdminCapableOptions{}, "policy-admin-capable", "Check admin capable", func(s *mcclient.ClientSession, args *PolicyAdminCapableOptions) error { + auth.InitFromClientSession(s) + policy.EnableGlobalRbac(15*time.Second, 15*time.Second) + + capable := policy.PolicyManager.IsAdminCapable(s.GetToken()) + fmt.Printf("%v\n", capable) + + return nil + }) + type PolicyExplainOptions struct { Request []string `help:"explain request, in format of key:is_admin:service:resource:action:extra"` } diff --git a/pkg/cloudcommon/policy/global.go b/pkg/cloudcommon/policy/global.go index 2604c16b4f..266d8e2c2b 100644 --- a/pkg/cloudcommon/policy/global.go +++ b/pkg/cloudcommon/policy/global.go @@ -6,6 +6,8 @@ import ( ) func EnableGlobalRbac(refreshInterval time.Duration, retryInterval time.Duration) { - consts.EnableRbac() - PolicyManager.start(refreshInterval, retryInterval) + if !consts.IsRbacEnabled() { + consts.EnableRbac() + PolicyManager.start(refreshInterval, retryInterval) + } } diff --git a/pkg/scheduler/manager/task_queue.go b/pkg/scheduler/manager/task_queue.go index 0fffd0268d..0a413c8703 100644 --- a/pkg/scheduler/manager/task_queue.go +++ b/pkg/scheduler/manager/task_queue.go @@ -200,8 +200,8 @@ type TaskManager struct { func NewTaskManager(stopCh <-chan struct{}) *TaskManager { return &TaskManager{ taskExecutorQueueManager: NewTaskExecutorQueueManager(stopCh), - stopCh: stopCh, - lock: sync.Mutex{}, + stopCh: stopCh, + lock: sync.Mutex{}, } }