fix(keystone): avoid panic when call logclient

This commit is contained in:
Qu Xuan
2021-04-28 19:36:35 +08:00
parent 6c5a8f6c41
commit 7e35db1040
2 changed files with 6 additions and 2 deletions
+1 -1
View File
@@ -278,7 +278,7 @@ func GetTokenString() string {
}
func IsAuthed() bool {
return manager.isAuthed()
return manager != nil && manager.isAuthed()
}
func Client() *mcclient.Client {
+5 -1
View File
@@ -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)