Merge pull request #10968 from ioito/automated-cherry-pick-of-#10967-upstream-release-3.7

Automated cherry pick of #10967: fix(keystone): avoid panic when call logclient
This commit is contained in:
Zexi Li
2021-04-29 09:46:23 +08:00
committed by GitHub
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)