[management] add nil handling for route domains (#4366)

This commit is contained in:
Pascal Fischer
2025-08-19 11:35:03 +02:00
committed by GitHub
parent a889c4108b
commit 5d361b5421
2 changed files with 9 additions and 2 deletions

View File

@@ -290,6 +290,9 @@ func (am *DefaultAccountManager) DeleteRoute(ctx context.Context, accountID stri
return transaction.DeleteRoute(ctx, accountID, string(routeID)) return transaction.DeleteRoute(ctx, accountID, string(routeID))
}) })
if err != nil {
return fmt.Errorf("failed to delete route %s: %w", routeID, err)
}
am.StoreEvent(ctx, userID, string(route.ID), accountID, activity.RouteRemoved, route.EventMeta()) am.StoreEvent(ctx, userID, string(route.ID), accountID, activity.RouteRemoved, route.EventMeta())

View File

@@ -111,7 +111,11 @@ type Route struct {
// EventMeta returns activity event meta related to the route // EventMeta returns activity event meta related to the route
func (r *Route) EventMeta() map[string]any { func (r *Route) EventMeta() map[string]any {
return map[string]any{"name": r.NetID, "network_range": r.Network.String(), "domains": r.Domains.SafeString(), "peer_id": r.Peer, "peer_groups": r.PeerGroups} domains := ""
if r.Domains != nil {
domains = r.Domains.SafeString()
}
return map[string]any{"name": r.NetID, "network_range": r.Network.String(), "domains": domains, "peer_id": r.Peer, "peer_groups": r.PeerGroups}
} }
// Copy copies a route object // Copy copies a route object
@@ -181,7 +185,7 @@ func (r *Route) GetResourceID() ResID {
// If the route is dynamic, it returns the domains as comma-separated punycode-encoded string. // If the route is dynamic, it returns the domains as comma-separated punycode-encoded string.
// If the route is not dynamic, it returns the network (prefix) string. // If the route is not dynamic, it returns the network (prefix) string.
func (r *Route) NetString() string { func (r *Route) NetString() string {
if r.IsDynamic() { if r.IsDynamic() && r.Domains != nil {
return r.Domains.SafeString() return r.Domains.SafeString()
} }
return r.Network.String() return r.Network.String()