-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
get_routes.go
36 lines (29 loc) · 952 Bytes
/
get_routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package api
import (
"fmt"
"net/http"
"github.com/go-openapi/runtime/middleware"
restapi "github.com/cilium/cilium/api/v1/server/restapi/bgp"
"github.com/cilium/cilium/pkg/api"
"github.com/cilium/cilium/pkg/bgpv1/agent"
)
func NewGetRoutesHandler(c *agent.Controller) restapi.GetBgpRoutesHandler {
return &getRoutesHandler{
controller: c,
}
}
type getRoutesHandler struct {
controller *agent.Controller
}
func (h *getRoutesHandler) Handle(params restapi.GetBgpRoutesParams) middleware.Responder {
if h.controller == nil {
return api.Error(http.StatusNotImplemented, agent.ErrBGPControlPlaneDisabled)
}
routes, err := h.controller.BGPMgr.GetRoutes(params.HTTPRequest.Context(), params)
if err != nil {
return api.Error(http.StatusInternalServerError, fmt.Errorf("failed to get routes: %w", err))
}
return restapi.NewGetBgpRoutesOK().WithPayload(routes)
}