From 7e35db1040faee848c8f2ce3d8ce9f544761a4bb Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Wed, 28 Apr 2021 19:32:23 +0800 Subject: [PATCH] fix(keystone): avoid panic when call logclient --- pkg/mcclient/auth/auth.go | 2 +- pkg/util/logclient/logclient.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/mcclient/auth/auth.go b/pkg/mcclient/auth/auth.go index 3af1f96590..360d7ce85d 100644 --- a/pkg/mcclient/auth/auth.go +++ b/pkg/mcclient/auth/auth.go @@ -278,7 +278,7 @@ func GetTokenString() string { } func IsAuthed() bool { - return manager.isAuthed() + return manager != nil && manager.isAuthed() } func Client() *mcclient.Client { diff --git a/pkg/util/logclient/logclient.go b/pkg/util/logclient/logclient.go index 9baa5181cf..0541f086ce 100644 --- a/pkg/util/logclient/logclient.go +++ b/pkg/util/logclient/logclient.go @@ -161,7 +161,11 @@ func addLog(model IObject, action string, iNotes interface{}, userCred mcclient. logentry.Add(jsonutils.NewString(notes), "notes") logclientWorkerMan.Run(func() { - s := DefaultSessionGenerator(context.Background(), auth.AdminCredential(), "", "") + cred := userCred + if auth.IsAuthed() { + cred = auth.AdminCredential() + } + s := DefaultSessionGenerator(context.Background(), cred, "", "") _, err := api.Create(s, logentry) if err != nil { log.Errorf("create action log %s failed %s", logentry, err)