-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
get_route_policies.go
37 lines (29 loc) · 1021 Bytes
/
get_route_policies.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
37
// 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 NewGetRoutePoliciesHandler(c *agent.Controller) restapi.GetBgpRoutePoliciesHandler {
return &getRoutePoliciesHandler{
controller: c,
}
}
type getRoutePoliciesHandler struct {
controller *agent.Controller
}
func (h *getRoutePoliciesHandler) Handle(params restapi.GetBgpRoutePoliciesParams) middleware.Responder {
if h.controller == nil {
return api.Error(http.StatusNotImplemented, agent.ErrBGPControlPlaneDisabled)
}
policies, err := h.controller.BGPMgr.GetRoutePolicies(params.HTTPRequest.Context(), params)
if err != nil {
return api.Error(http.StatusInternalServerError, fmt.Errorf("failed to get route policies: %w", err))
}
return restapi.NewGetBgpRoutePoliciesOK().WithPayload(policies)
}