traffic: audit endpoint + canonical app_key

This commit is contained in:
beckline
2026-02-16 01:31:56 +03:00
parent 69f3b2ef6a
commit 5eb292f17a
5 changed files with 454 additions and 17 deletions

View File

@@ -113,6 +113,7 @@ func upsertTrafficAppProfile(req TrafficAppProfileUpsertRequest) (TrafficAppProf
appKey = strings.TrimSpace(fields[0])
}
}
appKey = canonicalizeAppKey(appKey, cmd)
if appKey == "" {
return TrafficAppProfile{}, fmt.Errorf("cannot infer app_key")
}
@@ -284,6 +285,20 @@ func loadTrafficAppProfilesState() trafficAppProfilesState {
if st.Profiles == nil {
st.Profiles = nil
}
// EN: Best-effort migration: normalize app keys to canonical form.
// RU: Best-effort миграция: нормализуем app_key в канонический вид.
changed := false
for i := range st.Profiles {
canon := canonicalizeAppKey(st.Profiles[i].AppKey, st.Profiles[i].Command)
if canon != "" && strings.TrimSpace(st.Profiles[i].AppKey) != canon {
st.Profiles[i].AppKey = canon
changed = true
}
}
if changed {
_ = saveTrafficAppProfilesState(st)
}
return st
}