fix: align admin behavior and Kratos integrations

This commit is contained in:
2026-08-14 14:14:51 +08:00
parent 8c4c6ba661
commit e0b0e1d8c8
123 changed files with 4334 additions and 1877 deletions
+31 -5
View File
@@ -19,12 +19,37 @@ import (
func (r *systemRepo) PersistConfig(context.Context) error { return r.data.persistConfig() }
func (r *systemRepo) PersistAdminConfig(_ context.Context, raw []byte) error {
next := proto.Clone(r.data.admin).(*conf.AdminBackend)
currentData, currentAdmin := r.data.runtime.Values()
next := proto.Clone(currentAdmin).(*conf.AdminBackend)
if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(raw, next); err != nil {
return err
}
next.ConfigPath = r.data.admin.ConfigPath
return r.data.persistConfigValues(r.data.config, next)
next.ConfigPath = currentAdmin.ConfigPath
if err := r.data.persistConfigValues(currentData, next); err != nil {
return err
}
// Writing through the management API updates the same in-memory values
// immediately; the file watcher remains the fallback for external edits.
r.data.runtime.Replace(currentData, next)
return nil
}
func (r *systemRepo) PersistRuntimeConfig(_ context.Context, dataRaw, adminRaw []byte) error {
currentData, currentAdmin := r.data.runtime.Values()
nextData := proto.Clone(currentData).(*conf.Data)
nextAdmin := proto.Clone(currentAdmin).(*conf.AdminBackend)
options := protojson.UnmarshalOptions{DiscardUnknown: true}
if err := options.Unmarshal(dataRaw, nextData); err != nil {
return err
}
if err := options.Unmarshal(adminRaw, nextAdmin); err != nil {
return err
}
nextAdmin.ConfigPath = currentAdmin.ConfigPath
if err := r.data.persistConfigValues(nextData, nextAdmin); err != nil {
return err
}
r.data.runtime.Replace(nextData, nextAdmin)
return nil
}
func (r *systemRepo) ReloadConfig(ctx context.Context) error {
return r.data.reloadConfig(ctx)
@@ -161,9 +186,10 @@ func (r *systemRepo) Initialize(ctx context.Context, input *biz.DatabaseConfig)
}); err != nil {
return err
}
nextData := proto.Clone(r.data.config).(*conf.Data)
currentData, currentAdmin := r.data.runtime.Values()
nextData := proto.Clone(currentData).(*conf.Data)
nextData.Database = config
if err := r.data.persistConfigValues(nextData, r.data.admin); err != nil {
if err := r.data.persistConfigValues(nextData, currentAdmin); err != nil {
return fmt.Errorf("persist database configuration: %w", err)
}
r.data.activateDatabase(candidate, config)