2022-08-20 19:11:54 +02:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2023-02-03 21:47:20 +01:00
|
|
|
"net/http"
|
|
|
|
"unicode/utf8"
|
|
|
|
|
2022-08-20 19:11:54 +02:00
|
|
|
"github.com/gorilla/mux"
|
2023-02-28 15:01:24 +01:00
|
|
|
|
2022-08-20 19:11:54 +02:00
|
|
|
"github.com/netbirdio/netbird/management/server"
|
|
|
|
"github.com/netbirdio/netbird/management/server/http/api"
|
2022-11-11 20:36:45 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server/http/util"
|
2022-08-20 19:11:54 +02:00
|
|
|
"github.com/netbirdio/netbird/management/server/jwtclaims"
|
2022-11-11 20:36:45 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server/status"
|
2022-08-20 19:11:54 +02:00
|
|
|
"github.com/netbirdio/netbird/route"
|
|
|
|
)
|
|
|
|
|
2023-02-28 15:01:24 +01:00
|
|
|
// RoutesHanlder is the routes handler of the account
|
|
|
|
type RoutesHanlder struct {
|
2023-02-03 21:47:20 +01:00
|
|
|
accountManager server.AccountManager
|
|
|
|
claimsExtractor *jwtclaims.ClaimsExtractor
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
|
2023-02-28 15:01:24 +01:00
|
|
|
// NewRoutesHandler returns a new instance of RoutesHanlder handler
|
|
|
|
func NewRoutesHandler(accountManager server.AccountManager, authCfg AuthCfg) *RoutesHanlder {
|
|
|
|
return &RoutesHanlder{
|
2022-08-20 19:11:54 +02:00
|
|
|
accountManager: accountManager,
|
2023-02-03 21:47:20 +01:00
|
|
|
claimsExtractor: jwtclaims.NewClaimsExtractor(
|
|
|
|
jwtclaims.WithAudience(authCfg.Audience),
|
|
|
|
jwtclaims.WithUserIDClaim(authCfg.UserIDClaim),
|
|
|
|
),
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 15:01:24 +01:00
|
|
|
// GetAllRoutes returns the list of routes for the account
|
|
|
|
func (h *RoutesHanlder) GetAllRoutes(w http.ResponseWriter, r *http.Request) {
|
2023-02-03 21:47:20 +01:00
|
|
|
claims := h.claimsExtractor.FromRequestContext(r)
|
2022-11-11 20:36:45 +01:00
|
|
|
account, user, err := h.accountManager.GetAccountFromToken(claims)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-05 10:24:50 +01:00
|
|
|
routes, err := h.accountManager.ListRoutes(account.Id, user.Id)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
apiRoutes := make([]*api.Route, 0)
|
|
|
|
for _, r := range routes {
|
2023-02-03 10:33:28 +01:00
|
|
|
apiRoutes = append(apiRoutes, toRouteResponse(r))
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteJSONObject(w, apiRoutes)
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
|
2023-02-28 15:01:24 +01:00
|
|
|
// CreateRoute handles route creation request
|
|
|
|
func (h *RoutesHanlder) CreateRoute(w http.ResponseWriter, r *http.Request) {
|
2023-02-03 21:47:20 +01:00
|
|
|
claims := h.claimsExtractor.FromRequestContext(r)
|
2023-01-25 16:29:59 +01:00
|
|
|
account, user, err := h.accountManager.GetAccountFromToken(claims)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var req api.PostApiRoutesJSONRequestBody
|
2022-11-11 20:36:45 +01:00
|
|
|
err = json.NewDecoder(r.Body).Decode(&req)
|
|
|
|
if err != nil {
|
|
|
|
util.WriteErrorResponse("couldn't parse JSON request", http.StatusBadRequest, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-22 14:10:24 +02:00
|
|
|
_, newPrefix, err := route.ParseNetwork(req.Network)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-22 14:10:24 +02:00
|
|
|
if utf8.RuneCountInString(req.NetworkId) > route.MaxNetIDChar || req.NetworkId == "" {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument, "identifier should be between 1 and %d",
|
|
|
|
route.MaxNetIDChar), w)
|
2022-08-22 14:10:24 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-25 16:29:59 +01:00
|
|
|
newRoute, err := h.accountManager.CreateRoute(account.Id, newPrefix.String(), req.Peer, req.Description, req.NetworkId, req.Masquerade, req.Metric, req.Groups, req.Enabled, user.Id)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:33:28 +01:00
|
|
|
resp := toRouteResponse(newRoute)
|
2022-08-20 19:11:54 +02:00
|
|
|
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteJSONObject(w, &resp)
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
|
2023-02-28 15:01:24 +01:00
|
|
|
// UpdateRoute handles update to a route identified by a given ID
|
|
|
|
func (h *RoutesHanlder) UpdateRoute(w http.ResponseWriter, r *http.Request) {
|
2023-02-03 21:47:20 +01:00
|
|
|
claims := h.claimsExtractor.FromRequestContext(r)
|
2022-11-11 20:36:45 +01:00
|
|
|
account, user, err := h.accountManager.GetAccountFromToken(claims)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
routeID := vars["id"]
|
|
|
|
if len(routeID) == 0 {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument, "invalid route ID"), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-07 12:10:56 +01:00
|
|
|
_, err = h.accountManager.GetRoute(account.Id, routeID, user.Id)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-10 11:06:54 +02:00
|
|
|
var req api.PutApiRoutesIdJSONRequestBody
|
2022-11-11 20:36:45 +01:00
|
|
|
err = json.NewDecoder(r.Body).Decode(&req)
|
|
|
|
if err != nil {
|
|
|
|
util.WriteErrorResponse("couldn't parse JSON request", http.StatusBadRequest, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-22 14:10:24 +02:00
|
|
|
prefixType, newPrefix, err := route.ParseNetwork(req.Network)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument, "couldn't parse update prefix %s for route ID %s",
|
|
|
|
req.Network, routeID), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-22 14:10:24 +02:00
|
|
|
if utf8.RuneCountInString(req.NetworkId) > route.MaxNetIDChar || req.NetworkId == "" {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"identifier should be between 1 and %d", route.MaxNetIDChar), w)
|
2022-08-22 14:10:24 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-20 19:11:54 +02:00
|
|
|
newRoute := &route.Route{
|
|
|
|
ID: routeID,
|
2022-08-22 14:10:24 +02:00
|
|
|
Network: newPrefix,
|
|
|
|
NetID: req.NetworkId,
|
|
|
|
NetworkType: prefixType,
|
2022-08-20 19:11:54 +02:00
|
|
|
Masquerade: req.Masquerade,
|
2023-02-03 10:33:28 +01:00
|
|
|
Peer: req.Peer,
|
2022-08-20 19:11:54 +02:00
|
|
|
Metric: req.Metric,
|
|
|
|
Description: req.Description,
|
|
|
|
Enabled: req.Enabled,
|
2022-12-06 10:11:57 +01:00
|
|
|
Groups: req.Groups,
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
|
2023-01-25 16:29:59 +01:00
|
|
|
err = h.accountManager.SaveRoute(account.Id, user.Id, newRoute)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:33:28 +01:00
|
|
|
resp := toRouteResponse(newRoute)
|
2022-08-20 19:11:54 +02:00
|
|
|
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteJSONObject(w, &resp)
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
|
2023-02-28 15:01:24 +01:00
|
|
|
// PatchRoute handles patch updates to a route identified by a given ID
|
|
|
|
func (h *RoutesHanlder) PatchRoute(w http.ResponseWriter, r *http.Request) {
|
2023-02-03 21:47:20 +01:00
|
|
|
claims := h.claimsExtractor.FromRequestContext(r)
|
2022-11-11 20:36:45 +01:00
|
|
|
account, user, err := h.accountManager.GetAccountFromToken(claims)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
routeID := vars["id"]
|
|
|
|
if len(routeID) == 0 {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument, "invalid route ID"), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-07 12:10:56 +01:00
|
|
|
_, err = h.accountManager.GetRoute(account.Id, routeID, user.Id)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var req api.PatchApiRoutesIdJSONRequestBody
|
2022-11-11 20:36:45 +01:00
|
|
|
err = json.NewDecoder(r.Body).Decode(&req)
|
|
|
|
if err != nil {
|
|
|
|
util.WriteErrorResponse("couldn't parse JSON request", http.StatusBadRequest, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(req) == 0 {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument, "no patch instruction received"), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var operations []server.RouteUpdateOperation
|
|
|
|
|
|
|
|
for _, patch := range req {
|
|
|
|
switch patch.Path {
|
2022-08-22 14:10:24 +02:00
|
|
|
case api.RoutePatchOperationPathNetwork:
|
2022-08-20 19:11:54 +02:00
|
|
|
if patch.Op != api.RoutePatchOperationOpReplace {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"network field only accepts replace operation, got %s", patch.Op), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
operations = append(operations, server.RouteUpdateOperation{
|
2022-08-22 14:10:24 +02:00
|
|
|
Type: server.UpdateRouteNetwork,
|
2022-08-20 19:11:54 +02:00
|
|
|
Values: patch.Value,
|
|
|
|
})
|
|
|
|
case api.RoutePatchOperationPathDescription:
|
|
|
|
if patch.Op != api.RoutePatchOperationOpReplace {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"description field only accepts replace operation, got %s", patch.Op), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
operations = append(operations, server.RouteUpdateOperation{
|
|
|
|
Type: server.UpdateRouteDescription,
|
|
|
|
Values: patch.Value,
|
|
|
|
})
|
2022-08-22 14:10:24 +02:00
|
|
|
case api.RoutePatchOperationPathNetworkId:
|
|
|
|
if patch.Op != api.RoutePatchOperationOpReplace {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"network Identifier field only accepts replace operation, got %s", patch.Op), w)
|
2022-08-22 14:10:24 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
operations = append(operations, server.RouteUpdateOperation{
|
|
|
|
Type: server.UpdateRouteNetworkIdentifier,
|
|
|
|
Values: patch.Value,
|
|
|
|
})
|
2022-08-20 19:11:54 +02:00
|
|
|
case api.RoutePatchOperationPathPeer:
|
|
|
|
if patch.Op != api.RoutePatchOperationOpReplace {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"peer field only accepts replace operation, got %s", patch.Op), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(patch.Value) > 1 {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"value field only accepts 1 value, got %d", len(patch.Value)), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
operations = append(operations, server.RouteUpdateOperation{
|
|
|
|
Type: server.UpdateRoutePeer,
|
2023-02-03 10:33:28 +01:00
|
|
|
Values: patch.Value,
|
2022-08-20 19:11:54 +02:00
|
|
|
})
|
|
|
|
case api.RoutePatchOperationPathMetric:
|
|
|
|
if patch.Op != api.RoutePatchOperationOpReplace {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"metric field only accepts replace operation, got %s", patch.Op), w)
|
|
|
|
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
operations = append(operations, server.RouteUpdateOperation{
|
|
|
|
Type: server.UpdateRouteMetric,
|
|
|
|
Values: patch.Value,
|
|
|
|
})
|
|
|
|
case api.RoutePatchOperationPathMasquerade:
|
|
|
|
if patch.Op != api.RoutePatchOperationOpReplace {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"masquerade field only accepts replace operation, got %s", patch.Op), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
operations = append(operations, server.RouteUpdateOperation{
|
|
|
|
Type: server.UpdateRouteMasquerade,
|
|
|
|
Values: patch.Value,
|
|
|
|
})
|
|
|
|
case api.RoutePatchOperationPathEnabled:
|
|
|
|
if patch.Op != api.RoutePatchOperationOpReplace {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"enabled field only accepts replace operation, got %s", patch.Op), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
operations = append(operations, server.RouteUpdateOperation{
|
|
|
|
Type: server.UpdateRouteEnabled,
|
|
|
|
Values: patch.Value,
|
|
|
|
})
|
2022-12-06 10:11:57 +01:00
|
|
|
case api.RoutePatchOperationPathGroups:
|
|
|
|
if patch.Op != api.RoutePatchOperationOpReplace {
|
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument,
|
|
|
|
"groups field only accepts replace operation, got %s", patch.Op), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
operations = append(operations, server.RouteUpdateOperation{
|
|
|
|
Type: server.UpdateRouteGroups,
|
|
|
|
Values: patch.Value,
|
|
|
|
})
|
2022-08-20 19:11:54 +02:00
|
|
|
default:
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument, "invalid patch path"), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:33:28 +01:00
|
|
|
root, err := h.accountManager.UpdateRoute(account.Id, routeID, operations)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:33:28 +01:00
|
|
|
resp := toRouteResponse(root)
|
2022-08-20 19:11:54 +02:00
|
|
|
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteJSONObject(w, &resp)
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
|
2023-02-28 15:01:24 +01:00
|
|
|
// DeleteRoute handles route deletion request
|
|
|
|
func (h *RoutesHanlder) DeleteRoute(w http.ResponseWriter, r *http.Request) {
|
2023-02-03 21:47:20 +01:00
|
|
|
claims := h.claimsExtractor.FromRequestContext(r)
|
2023-01-25 16:29:59 +01:00
|
|
|
account, user, err := h.accountManager.GetAccountFromToken(claims)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
routeID := mux.Vars(r)["id"]
|
|
|
|
if len(routeID) == 0 {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument, "invalid route ID"), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-25 16:29:59 +01:00
|
|
|
err = h.accountManager.DeleteRoute(account.Id, routeID, user.Id)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteJSONObject(w, "")
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
|
2023-02-28 15:01:24 +01:00
|
|
|
// GetRoute handles a route Get request identified by ID
|
|
|
|
func (h *RoutesHanlder) GetRoute(w http.ResponseWriter, r *http.Request) {
|
2023-02-03 21:47:20 +01:00
|
|
|
claims := h.claimsExtractor.FromRequestContext(r)
|
2022-11-11 20:36:45 +01:00
|
|
|
account, user, err := h.accountManager.GetAccountFromToken(claims)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(err, w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
routeID := mux.Vars(r)["id"]
|
|
|
|
if len(routeID) == 0 {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.InvalidArgument, "invalid route ID"), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-05 10:24:50 +01:00
|
|
|
foundRoute, err := h.accountManager.GetRoute(account.Id, routeID, user.Id)
|
2022-08-20 19:11:54 +02:00
|
|
|
if err != nil {
|
2022-11-11 20:36:45 +01:00
|
|
|
util.WriteError(status.Errorf(status.NotFound, "route not found"), w)
|
2022-08-20 19:11:54 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:33:28 +01:00
|
|
|
util.WriteJSONObject(w, toRouteResponse(foundRoute))
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 10:33:28 +01:00
|
|
|
func toRouteResponse(serverRoute *route.Route) *api.Route {
|
2022-08-20 19:11:54 +02:00
|
|
|
return &api.Route{
|
|
|
|
Id: serverRoute.ID,
|
|
|
|
Description: serverRoute.Description,
|
2022-08-22 14:10:24 +02:00
|
|
|
NetworkId: serverRoute.NetID,
|
2022-08-20 19:11:54 +02:00
|
|
|
Enabled: serverRoute.Enabled,
|
2023-02-03 10:33:28 +01:00
|
|
|
Peer: serverRoute.Peer,
|
2022-08-22 14:10:24 +02:00
|
|
|
Network: serverRoute.Network.String(),
|
|
|
|
NetworkType: serverRoute.NetworkType.String(),
|
2022-08-20 19:11:54 +02:00
|
|
|
Masquerade: serverRoute.Masquerade,
|
|
|
|
Metric: serverRoute.Metric,
|
2022-12-06 10:11:57 +01:00
|
|
|
Groups: serverRoute.Groups,
|
2022-08-20 19:11:54 +02:00
|
|
|
}
|
|
|
|
}
|