24 lines
569 B
Go
24 lines
569 B
Go
package resolver
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/netbox"
|
|
)
|
|
|
|
// PrimaryIPStrategy returns the primary IP configured in NetBox.
|
|
// Prefers IPv4, falls back to IPv6.
|
|
type PrimaryIPStrategy struct{}
|
|
|
|
func (s *PrimaryIPStrategy) Name() string { return "primary_ip" }
|
|
|
|
func (s *PrimaryIPStrategy) Resolve(_ context.Context, entry *netbox.HostEntry, _ *netbox.Client) (string, error) {
|
|
if entry.PrimaryIP4 != "" {
|
|
return entry.PrimaryIP4, nil
|
|
}
|
|
if entry.PrimaryIP6 != "" {
|
|
return entry.PrimaryIP6, nil
|
|
}
|
|
return "", ErrNoIP
|
|
}
|