统一配置JSON缩进排版并保持摘要与历史兼容
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-08 21:08:36 +08:00
1 parent b705f00b22
commit 560605a8e1
10 files changed
+360 -13

No files matched your search

+2 -2
View File
@@ -314,7 +314,7 @@ func writeProtectedConfigFile(name string, cfg *Config) error {
}
stored.SSLPrivateKeyPath = persistControlledSSLPath(stored.SSLPrivateKeyPath)
stored.SSLPublicKeyPath = persistControlledSSLPath(stored.SSLPublicKeyPath)
data, err := json.Marshal(stored)
data, err := json.MarshalIndent(stored, "", " ")
if err != nil {
return errors.Wrap(err)
}
@@ -341,7 +341,7 @@ func readConfig() (*Config, error) {
}
cfgData, err := readConfigFile("config.json")
if os.IsNotExist(err) {
data, marshalErr := json.Marshal(configData)
data, marshalErr := json.MarshalIndent(configData, "", " ")
if marshalErr != nil {
return nil, errors.Wrap(marshalErr)
}
+2 -2
View File
@@ -157,7 +157,7 @@ func BackupConfig(root string, snapshot RuntimeSnapshot, now time.Time) (string,
if err := pruneBackups(directory, now); err != nil {
return "", err
}
data, err := json.Marshal(snapshot)
data, err := json.MarshalIndent(snapshot, "", " ")
if err != nil {
return "", err
}
@@ -301,7 +301,7 @@ func writeRootConfig(root string, value RootConfig) error {
return err
}
value = normalizeRootConfig(value)
data, err := json.Marshal(value)
data, err := json.MarshalIndent(value, "", " ")
if err != nil {
return err
}
+6 -2
View File
@@ -103,8 +103,12 @@ func TestLoadManagerRewritesLegacyVersion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(rewritten), `"version"`) || !strings.Contains(string(rewritten), `"schemaVersion":2`) || !strings.Contains(string(rewritten), `"generation":7`) {
t.Fatalf("legacy configuration was not rewritten: %s", rewritten)
var saved RootConfig
if err := json.Unmarshal(rewritten, &saved); err != nil {
t.Fatal(err)
}
if strings.Contains(string(rewritten), `"version"`) || saved.SchemaVersion != CurrentSchemaVersion || saved.Generation != 7 {
t.Fatal("旧配置未正确更新版本和代次")
}
}
+8 -2
View File
@@ -503,8 +503,14 @@ func TestConfigManagerMailSectionAppliesBothPartitionsWithoutMailFile(t *testing
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(data), `"generation":2`) {
t.Fatalf("%s was not updated to generation 2: %s", name, data)
var saved struct {
Meta SectionMeta `json:"meta"`
}
if err := json.Unmarshal(data, &saved); err != nil {
t.Fatal(err)
}
if saved.Meta.Generation != 2 {
t.Fatalf("%s 未更新至第二代配置", name)
}
}
reloaded, err := NewConfigLoader(root, options).Load()
+1 -1
View File
@@ -264,7 +264,7 @@ func refreshLegacyMigrationRoot(runtime RuntimeConfig, files map[string][]byte)
runtime.Root.Generation = runtime.Generation
runtime.Root.SetupState = runtime.SetupState
runtime.Root.Sections = references
data, err := json.Marshal(runtime.Root)
data, err := json.MarshalIndent(runtime.Root, "", " ")
if err != nil {
return err
}
+4 -4
View File
@@ -340,7 +340,7 @@ func marshalRuntimeFilesWithPluginSecrets(runtime RuntimeConfig, keepPluginSecre
default:
return nil, ErrInvalidSection
}
data, err := json.Marshal(value)
data, err := json.MarshalIndent(value, "", " ")
if err != nil {
return nil, err
}
@@ -353,7 +353,7 @@ func marshalRuntimeFilesWithPluginSecrets(runtime RuntimeConfig, keepPluginSecre
references[section] = SectionRef{File: file, Schema: schema, Generation: runtime.Generation, SHA256: SectionDigest(sectionBytes[section])}
}
runtime.Root.Sections = references
rootData, err := json.Marshal(runtime.Root)
rootData, err := json.MarshalIndent(runtime.Root, "", " ")
if err != nil {
return nil, err
}
@@ -470,7 +470,7 @@ func writeTransactionManifest(directory string, manifest TransactionManifest) er
if err := validateTransactionManifest(manifest); err != nil {
return err
}
data, err := json.Marshal(manifest)
data, err := json.MarshalIndent(manifest, "", " ")
if err != nil {
return err
}
@@ -667,7 +667,7 @@ func (s *TransactionStore) createBackupAt(runtime RuntimeConfig, createdAt time.
return "", err
}
}
manifestData, err := json.Marshal(manifest)
manifestData, err := json.MarshalIndent(manifest, "", " ")
if err != nil {
return "", err
}