Skip to content

Commit 5d361b5

Browse files
[management] add nil handling for route domains (#4366)
1 parent a889c41 commit 5d361b5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

management/server/route.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ func (am *DefaultAccountManager) DeleteRoute(ctx context.Context, accountID stri
290290

291291
return transaction.DeleteRoute(ctx, accountID, string(routeID))
292292
})
293+
if err != nil {
294+
return fmt.Errorf("failed to delete route %s: %w", routeID, err)
295+
}
293296

294297
am.StoreEvent(ctx, userID, string(route.ID), accountID, activity.RouteRemoved, route.EventMeta())
295298

route/route.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ type Route struct {
111111

112112
// EventMeta returns activity event meta related to the route
113113
func (r *Route) EventMeta() map[string]any {
114-
return map[string]any{"name": r.NetID, "network_range": r.Network.String(), "domains": r.Domains.SafeString(), "peer_id": r.Peer, "peer_groups": r.PeerGroups}
114+
domains := ""
115+
if r.Domains != nil {
116+
domains = r.Domains.SafeString()
117+
}
118+
return map[string]any{"name": r.NetID, "network_range": r.Network.String(), "domains": domains, "peer_id": r.Peer, "peer_groups": r.PeerGroups}
115119
}
116120

117121
// Copy copies a route object
@@ -181,7 +185,7 @@ func (r *Route) GetResourceID() ResID {
181185
// If the route is dynamic, it returns the domains as comma-separated punycode-encoded string.
182186
// If the route is not dynamic, it returns the network (prefix) string.
183187
func (r *Route) NetString() string {
184-
if r.IsDynamic() {
188+
if r.IsDynamic() && r.Domains != nil {
185189
return r.Domains.SafeString()
186190
}
187191
return r.Network.String()

0 commit comments

Comments
 (0)