mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-09 23:27:58 +02:00
Simplified Store Interface (#545)
This PR simplifies Store and FileStore by keeping just the Get and Save account methods. The AccountManager operates mostly around a single account, so it makes sense to fetch the whole account object from the store.
This commit is contained in:
@ -93,7 +93,12 @@ func (am *DefaultAccountManager) checkPrefixPeerExists(accountID, peer string, p
|
||||
return nil
|
||||
}
|
||||
|
||||
routesWithPrefix, err := am.Store.GetRoutesByPrefix(accountID, prefix)
|
||||
account, err := am.Store.GetAccount(accountID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
routesWithPrefix := account.GetRoutesByPrefix(prefix)
|
||||
|
||||
if err != nil {
|
||||
if s, ok := status.FromError(err); ok && s.Code() == codes.NotFound {
|
||||
@ -372,30 +377,6 @@ func toProtocolRoute(route *route.Route) *proto.Route {
|
||||
}
|
||||
}
|
||||
|
||||
func (am *DefaultAccountManager) getPeersRoutes(peers []*Peer) []*route.Route {
|
||||
routes := make([]*route.Route, 0)
|
||||
for _, peer := range peers {
|
||||
peerRoutes, err := am.Store.GetPeerRoutes(peer.Key)
|
||||
if err != nil {
|
||||
errorStatus, ok := status.FromError(err)
|
||||
if !ok && errorStatus.Code() != codes.NotFound {
|
||||
log.Error(err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
activeRoutes := make([]*route.Route, 0)
|
||||
for _, pr := range peerRoutes {
|
||||
if pr.Enabled {
|
||||
activeRoutes = append(activeRoutes, pr)
|
||||
}
|
||||
}
|
||||
if len(activeRoutes) > 0 {
|
||||
routes = append(routes, activeRoutes...)
|
||||
}
|
||||
}
|
||||
return routes
|
||||
}
|
||||
|
||||
func toProtocolRoutes(routes []*route.Route) []*proto.Route {
|
||||
protoRoutes := make([]*proto.Route, 0)
|
||||
for _, r := range routes {
|
||||
|
Reference in New Issue
Block a user