2016-11-11 14:14:38 +01:00
|
|
|
package endpoints
|
|
|
|
|
|
|
|
import (
|
2016-12-06 13:02:12 +01:00
|
|
|
"fmt"
|
2016-12-15 14:42:37 +01:00
|
|
|
"net/http"
|
2016-12-06 13:02:12 +01:00
|
|
|
|
2016-11-11 15:33:08 +01:00
|
|
|
"github.com/ecix/birdwatcher/bird"
|
2016-11-11 14:14:38 +01:00
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
)
|
|
|
|
|
2016-12-15 14:42:37 +01:00
|
|
|
func ProtoRoutes(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
2016-12-06 13:02:12 +01:00
|
|
|
protocol, err := ValidateProtocolParam(ps.ByName("protocol"))
|
|
|
|
if err != nil {
|
|
|
|
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
|
|
|
}
|
|
|
|
return bird.RoutesProto(protocol)
|
2016-11-11 14:14:38 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 14:42:37 +01:00
|
|
|
func RoutesFiltered(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
2016-12-06 17:20:27 +01:00
|
|
|
protocol, err := ValidateProtocolParam(ps.ByName("protocol"))
|
|
|
|
if err != nil {
|
|
|
|
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
|
|
|
}
|
|
|
|
return bird.RoutesFiltered(protocol)
|
|
|
|
}
|
|
|
|
|
2016-12-15 14:42:37 +01:00
|
|
|
func RoutesPrefixed(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
|
|
|
qs := r.URL.Query()
|
|
|
|
prefixl := qs["prefix"]
|
|
|
|
if len(prefixl) != 1 {
|
|
|
|
return bird.Parsed{"error": "need a prefix as single query parameter"}, false
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix, err := ValidatePrefixParam(prefixl[0])
|
2016-12-08 11:09:25 +01:00
|
|
|
if err != nil {
|
|
|
|
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
|
|
|
}
|
|
|
|
return bird.RoutesPrefixed(prefix)
|
|
|
|
}
|
|
|
|
|
2016-12-15 14:42:37 +01:00
|
|
|
func TableRoutes(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
2016-11-11 14:14:38 +01:00
|
|
|
return bird.RoutesTable(ps.ByName("table"))
|
|
|
|
}
|
|
|
|
|
2016-12-15 14:42:37 +01:00
|
|
|
func ProtoCount(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
2016-12-06 14:44:18 +01:00
|
|
|
protocol, err := ValidateProtocolParam(ps.ByName("protocol"))
|
|
|
|
if err != nil {
|
|
|
|
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
|
|
|
}
|
|
|
|
return bird.RoutesProtoCount(protocol)
|
2016-11-11 14:14:38 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 14:42:37 +01:00
|
|
|
func TableCount(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
2016-11-11 14:14:38 +01:00
|
|
|
return bird.RoutesTable(ps.ByName("table"))
|
|
|
|
}
|
|
|
|
|
2016-12-15 14:42:37 +01:00
|
|
|
func RouteNet(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
2016-11-11 14:14:38 +01:00
|
|
|
return bird.RoutesLookupTable(ps.ByName("net"), "master")
|
|
|
|
}
|
|
|
|
|
2016-12-15 14:42:37 +01:00
|
|
|
func RouteNetTable(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
2016-11-11 14:14:38 +01:00
|
|
|
return bird.RoutesLookupTable(ps.ByName("net"), ps.ByName("table"))
|
|
|
|
}
|
2017-02-15 12:20:55 +01:00
|
|
|
|
|
|
|
func RoutesPeer(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
|
|
|
|
qs := r.URL.Query()
|
|
|
|
peerl := qs["peer"]
|
|
|
|
if len(peerl) != 1 {
|
|
|
|
return bird.Parsed{"error": "need a peer as single query parameter"}, false
|
|
|
|
}
|
|
|
|
|
|
|
|
peer, err := ValidateProtocolParam(peerl[0])
|
|
|
|
if err != nil {
|
|
|
|
return bird.Parsed{"error": fmt.Sprintf("%s", err)}, false
|
|
|
|
}
|
|
|
|
return bird.RoutesPeer(peer)
|
|
|
|
}
|