fix(common): distinguish system and user log by is_system_account (#18316)

This commit is contained in:
屈轩
2023-10-15 20:57:56 -05:00
committed by GitHub
parent 61f01b5290
commit de0b2ae67c
3 changed files with 13 additions and 8 deletions
+1
View File
@@ -67,6 +67,7 @@ func getDefaultAdminCred() *mcclient.SSimpleToken {
token.ProjectDomain = prj.GetDomain().Name
rol, _ := RoleManager.FetchRole("", api.SystemAdminRole, api.DEFAULT_DOMAIN_ID, "")
token.Roles = rol.Name
token.SystemAccount = true
token.RoleIds = rol.Id
return &token
}
+8 -7
View File
@@ -286,13 +286,14 @@ func (t *SAuthToken) GetSimpleUserCred(token string) (mcclient.TokenCredential,
return nil, errors.Wrap(err, "UserManager.FetchUserExtended")
}
ret := mcclient.SSimpleToken{
Token: token,
UserId: t.UserId,
User: userExt.Name,
Domain: userExt.DomainName,
DomainId: userExt.DomainId,
Expires: t.ExpiresAt,
Context: t.Context,
Token: token,
UserId: t.UserId,
User: userExt.Name,
Domain: userExt.DomainName,
DomainId: userExt.DomainId,
Expires: t.ExpiresAt,
Context: t.Context,
SystemAccount: userExt.IsSystemAccount,
}
var roles []models.SRole
if len(t.ProjectId) > 0 {
+4 -1
View File
@@ -44,6 +44,8 @@ type SSimpleToken struct {
RoleIds string
Expires time.Time
SystemAccount bool
Context SAuthContext
}
@@ -184,7 +186,7 @@ func (this *SSimpleToken) GetServiceCatalog() IServiceCatalog {
}
func (this *SSimpleToken) IsSystemAccount() bool {
return true
return this.SystemAccount
}
func (this *SSimpleToken) GetLoginSource() string {
@@ -218,6 +220,7 @@ func SimplifyToken(token TokenCredential) TokenCredential {
Source: token.GetLoginSource(),
Ip: token.GetLoginIp(),
},
SystemAccount: token.IsSystemAccount(),
}
}