feat: search multiple NetBox instances with isolated host identities
Release / release (push) Successful in 5m16s
Release / release (push) Successful in 5m16s
This commit is contained in:
1 parent
a2a6dd7591
commit
7f53b90266
26 files changed
+1299
-115
No files matched your search
+23
-2
@@ -52,7 +52,11 @@ func (s *Service) Read(ctx context.Context, host netbox.HostEntry, remote bool)
|
||||
note.Text, note.ETag, err = s.Client.GetComments(ctx, note.Host)
|
||||
return note, err
|
||||
}
|
||||
data, err := os.ReadFile(s.path(host))
|
||||
path, err := s.localPath(host)
|
||||
if err != nil {
|
||||
return note, err
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if os.IsNotExist(err) {
|
||||
return note, nil
|
||||
}
|
||||
@@ -67,5 +71,22 @@ func (s *Service) Write(ctx context.Context, note Note, remote bool) error {
|
||||
}
|
||||
return s.Client.SetComments(ctx, note.Host, note.Text, note.ETag)
|
||||
}
|
||||
return storage.WriteFile(s.path(note.Host), []byte(note.Text), 0o600)
|
||||
path, err := s.localPath(note.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return storage.WriteFile(path, []byte(note.Text), 0o600)
|
||||
}
|
||||
|
||||
func (s *Service) localPath(host netbox.HostEntry) (string, error) {
|
||||
if s.Client == nil {
|
||||
return s.path(host), nil
|
||||
}
|
||||
host, namespace, err := s.Client.HostScope(host)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
scoped := *s
|
||||
scoped.Namespace = namespace
|
||||
return scoped.path(host), nil
|
||||
}
|
||||
Reference in new issue
Block a user