feat: Add audit logging (#38189)

Co-authored-by: bircni <bircni@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
bircni
2026-09-12 10:15:23 +02:00
committed by GitHub
parent 4d43445532
commit da37b7916b
136 changed files with 3864 additions and 209 deletions
+11
View File
@@ -80,6 +80,17 @@ func AddUserOpenID(ctx context.Context, openid *UserOpenID) error {
return db.Insert(ctx, openid)
}
// GetUserOpenIDByID returns the OpenID with the given ID owned by uid.
func GetUserOpenIDByID(ctx context.Context, id, uid int64) (*UserOpenID, error) {
oid, has, err := db.Get[UserOpenID](ctx, builder.Eq{"id": id, "uid": uid})
if err != nil {
return nil, err
} else if !has {
return nil, util.NewNotExistErrorf("OpenID is unknown")
}
return oid, nil
}
// DeleteUserOpenID deletes an openid address of given user.
func DeleteUserOpenID(ctx context.Context, openid *UserOpenID) (err error) {
var deleted int64
+26
View File
@@ -90,6 +90,32 @@ func NewDeployKeyUserWithKeyID(id int64) *User {
return u
}
const (
CLIUserID int64 = -4
CLIUserName = "CLI"
)
func NewCLIUser() *User {
return &User{
ID: CLIUserID,
Name: CLIUserName,
LowerName: strings.ToLower(CLIUserName),
}
}
const (
AuthenticationSourceUserID int64 = -5
AuthenticationSourceUserName = "AuthenticationSource"
)
func NewAuthenticationSourceUser() *User {
return &User{
ID: AuthenticationSourceUserID,
Name: AuthenticationSourceUserName,
LowerName: strings.ToLower(AuthenticationSourceUserName),
}
}
func GetSystemUserByName(name string) *User {
lowerName := strings.ToLower(name)
uid := globalVars().systemUserNameIdMap[lowerName]