traffic: audit endpoint + canonical app_key
This commit is contained in:
@@ -331,7 +331,7 @@ func appMarksAdd(target string, id uint64, cgAbs string, rel string, level int,
|
||||
|
||||
unit = strings.TrimSpace(unit)
|
||||
command = strings.TrimSpace(command)
|
||||
appKey = normalizeAppKey(appKey, command)
|
||||
appKey = canonicalizeAppKey(appKey, command)
|
||||
|
||||
// EN: Avoid unbounded growth of marks for the same app.
|
||||
// RU: Не даём бесконечно плодить метки на одно и то же приложение.
|
||||
@@ -674,6 +674,20 @@ func loadAppMarksState() appMarksState {
|
||||
if st.Version == 0 {
|
||||
st.Version = 1
|
||||
}
|
||||
|
||||
// EN: Best-effort migration: normalize app keys to canonical form.
|
||||
// RU: Best-effort миграция: нормализуем app_key в канонический вид.
|
||||
changed := false
|
||||
for i := range st.Items {
|
||||
canon := canonicalizeAppKey(st.Items[i].AppKey, st.Items[i].Command)
|
||||
if canon != "" && strings.TrimSpace(st.Items[i].AppKey) != canon {
|
||||
st.Items[i].AppKey = canon
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
_ = saveAppMarksState(st)
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
@@ -695,22 +709,6 @@ func saveAppMarksState(st appMarksState) error {
|
||||
return os.Rename(tmp, trafficAppMarksPath)
|
||||
}
|
||||
|
||||
func normalizeAppKey(appKey string, command string) string {
|
||||
key := strings.TrimSpace(appKey)
|
||||
if key != "" {
|
||||
return key
|
||||
}
|
||||
cmd := strings.TrimSpace(command)
|
||||
if cmd == "" {
|
||||
return ""
|
||||
}
|
||||
fields := strings.Fields(cmd)
|
||||
if len(fields) > 0 {
|
||||
return strings.TrimSpace(fields[0])
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func isAllDigits(s string) bool {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
|
||||
Reference in New Issue
Block a user