Add local and NetBox server notes and improve reliability
Release / release (push) Successful in 6m52s

This commit is contained in:
Sebastian Unterschütz committed 2026-10-27 17:51:59 +01:00
1 parent 2852dff2c4
commit 12cc64fdd9
17 files changed
+848 -83

No files matched your search

+5 -1
View File
@@ -2,6 +2,7 @@ package cache
import (
"encoding/json"
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/storage"
"os"
"path/filepath"
"sort"
@@ -116,12 +117,15 @@ func (c *Cache) Save() error {
if err != nil {
return err
}
return os.WriteFile(c.path, data, 0o644)
return storage.WriteFile(c.path, data, 0o600)
}
func (c *Cache) Upsert(e Entry) {
e.CachedAt = time.Now()
c.mu.Lock()
if old, ok := c.entries[e.Name]; ok && e.LastUsed.IsZero() {
e.LastUsed = old.LastUsed
}
c.entries[e.Name] = e
c.mu.Unlock()
}
+12
View File
@@ -471,3 +471,15 @@ func tempFile(t *testing.T, content []byte) string {
f.Close()
return f.Name()
}
func TestUpsertPreservesUsageHistory(t *testing.T) {
c := New("", 3600)
c.Upsert(Entry{Name: "web01", IP: "10.0.0.1"})
c.MarkUsed("web01")
before, _ := c.Get("web01")
c.Upsert(Entry{Name: "web01", IP: "10.0.0.2"})
after, _ := c.Get("web01")
if after.LastUsed != before.LastUsed || after.IP != "10.0.0.2" {
t.Fatalf("history lost: %+v", after)
}
}