2020-12-22 02:06:46 +00:00
|
|
|
package tunnel
|
|
|
|
|
|
|
|
import (
|
2020-12-29 17:51:42 +00:00
|
|
|
"github.com/pkg/errors"
|
2021-03-23 14:30:43 +00:00
|
|
|
|
2021-12-27 14:56:50 +00:00
|
|
|
"github.com/cloudflare/cloudflared/cfapi"
|
2020-12-22 02:06:46 +00:00
|
|
|
)
|
|
|
|
|
2020-12-29 17:51:42 +00:00
|
|
|
const noClientMsg = "error while creating backend client"
|
|
|
|
|
2021-12-27 14:56:50 +00:00
|
|
|
func (sc *subcommandContext) listRoutes(filter *cfapi.IpRouteFilter) ([]*cfapi.DetailedRoute, error) {
|
2020-12-22 02:06:46 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
2020-12-29 17:51:42 +00:00
|
|
|
return nil, errors.Wrap(err, noClientMsg)
|
2020-12-22 02:06:46 +00:00
|
|
|
}
|
|
|
|
return client.ListRoutes(filter)
|
|
|
|
}
|
|
|
|
|
2021-12-27 14:56:50 +00:00
|
|
|
func (sc *subcommandContext) addRoute(newRoute cfapi.NewRoute) (cfapi.Route, error) {
|
2020-12-22 02:06:46 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
2021-12-27 14:56:50 +00:00
|
|
|
return cfapi.Route{}, errors.Wrap(err, noClientMsg)
|
2020-12-22 02:06:46 +00:00
|
|
|
}
|
|
|
|
return client.AddRoute(newRoute)
|
|
|
|
}
|
2020-12-29 17:51:42 +00:00
|
|
|
|
2021-12-27 14:56:50 +00:00
|
|
|
func (sc *subcommandContext) deleteRoute(params cfapi.DeleteRouteParams) error {
|
2020-12-29 17:51:42 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, noClientMsg)
|
|
|
|
}
|
2021-11-29 12:00:31 +00:00
|
|
|
return client.DeleteRoute(params)
|
2020-12-29 17:51:42 +00:00
|
|
|
}
|
2021-01-05 23:55:18 +00:00
|
|
|
|
2021-12-27 14:56:50 +00:00
|
|
|
func (sc *subcommandContext) getRouteByIP(params cfapi.GetRouteByIpParams) (cfapi.DetailedRoute, error) {
|
2021-01-05 23:55:18 +00:00
|
|
|
client, err := sc.client()
|
|
|
|
if err != nil {
|
2021-12-27 14:56:50 +00:00
|
|
|
return cfapi.DetailedRoute{}, errors.Wrap(err, noClientMsg)
|
2021-01-05 23:55:18 +00:00
|
|
|
}
|
2021-11-29 12:00:31 +00:00
|
|
|
return client.GetByIP(params)
|
2021-01-05 23:55:18 +00:00
|
|
|
}
|